def getLog(self, source, page, rows, orderby, sort): offset = int(rows) * (int(page) - 1) sql = { "error": "select logid, date, message from log where level = 'ERROR' and source = '" + source + "'" }[self.logType] countSql = { "error": "select count(logid) from log where level = 'ERROR' and source = '" + source + "'" }[self.logType] if("" != orderby): sql = sql + " order by " + orderby + " " + sort sql = sql + " limit " + rows + " offset " + str(offset) dbpath = os.path.join(logPath.getLogPath(), self.date, "pcd.log.v4.db3") if(False == os.path.isfile(dbpath)): return records() else: r = records() conn = SQLiteUtil.Connect(dbpath) countrs = SQLiteUtil.executeSql(conn, countSql) r.total = countrs[0][0] rs = SQLiteUtil.executeSql(conn, sql) r.rows = list(map(maps.maprecord2errorlog, rs)) return r
def getLogSources(date): dbpath = os.path.join(logPath.getLogPath(), date, "pcd.log.v4.db3") print(os.path.isfile(dbpath)) if os.path.isfile(dbpath): conn = SQLiteUtil.Connect(dbpath) sql = "select distinct source from log" rs = SQLiteUtil.executeSql(conn, sql) return json.dumps(list(map(maps.maprecord2source, rs)), default=generic_JsonEncode, ensure_ascii=False) else: return []
def getRelativeLog(self, filename): sql = "select logid, date, message from log where message like '%" + filename + ".xml%'" countSql = "select count(logid) from log where message like '%" + filename + ".xml%'" cdate = filename[0:8] cdate = cdate[:4] + "-" + cdate[4:] cdate = cdate[:7] + "-" + cdate[7:] dbpath = os.path.join(logPath.getLogPath(), cdate, "pcd.log.v4.db3") if(False == os.path.isfile(dbpath)): return records() else: print(sql) r = records() conn = SQLiteUtil.Connect(dbpath) countrs = SQLiteUtil.executeSql(conn, countSql) r.total = countrs[0][0] rs = SQLiteUtil.executeSql(conn, sql) r.rows = list(map(maps.maprecord2errorlog, rs)) return r
def loadExecuteInfo(self): exesql = "select count(LogId) from log where level='DEBUG' and source='" + self.taskName + "' and message like '%开始执行%'" errSql = "select count(LogId) from log where level='ERROR' and source='" + self.taskName + "' and message not like '%执行完毕%'" firstSql = "select date from log where level='DEBUG' and source='" + self.taskName + "' and message like '%开始执行' order by date limit 1" lastSql = "select date from log where (level='DEBUG' or level='ERROR') and source='" + self.taskName + "' and message like '%执行完毕%' order by date desc limit 1" dbpath = os.path.join(logPath.getLogPath(), self.date, "pcd.log.v4.db3") if(os.path.isfile(dbpath)): conn = SQLiteUtil.Connect(dbpath) exeRS = SQLiteUtil.executeSql(conn, exesql) errRS = SQLiteUtil.executeSql(conn, errSql) firstRS = SQLiteUtil.executeSql(conn, firstSql) lastRS = SQLiteUtil.executeSql(conn, lastSql) self.taskEI.executeCount = exeRS[0][0] self.taskEI.errorCount = errRS[0][0] self.taskEI.firstStartTime = firstRS[0][0] self.taskEI.lastStartTime = lastRS[0][0] return self.taskEI