def get_logs(self, path, last_clock): import portalocker import tailer import time pn = self.get_path(path) with open(pn, "r+") as log: while True: try: portalocker.lock(log, portalocker.LOCK_EX) break except: dbg.dbg("lock failed") time.sleep(0.1) curtime = int(util.current_sec()) lines = tailer.tail(log, 20) ret = [] if last_clock is None: last_clock = 0 for line in lines: sp = line.strip().split("\t") if(int(sp[0]) < last_clock): continue #log = { # 'time': eval(sp[0]), # 'message': sp[1] #} #ret.append(log) ret.append(sp[1]) return ret, curtime
def get_logs(self, path, last_clock): import portalocker import tailer import time pn = self.get_path(path) with open(pn, "r+") as log: while True: try: portalocker.lock(log, portalocker.LOCK_EX) break except: dbg.dbg("lock failed") time.sleep(0.1) curtime = int(util.current_sec()) lines = tailer.tail(log, 20) ret = [] if last_clock is None: last_clock = 0 for line in lines: sp = line.strip().split("\t") if (int(sp[0]) < last_clock): continue #log = { # 'time': eval(sp[0]), # 'message': sp[1] #} #ret.append(log) ret.append(sp[1]) return ret, curtime
def append(self, path, msg): import portalocker import time pn = self.get_path(path) with open(pn, "a+") as log: while True: try: portalocker.lock(log, portalocker.LOCK_EX) break except: dbg.dbg("lock failed") time.sleep(0.1) log.write("%d\t%s\n" % (util.current_sec(), msg))
def append(self, path, msg): import portalocker import time pn = self.get_path(path) util.mkdirs(os.path.dirname(pn)) with open(pn, "a+") as log: while True: try: portalocker.lock(log, portalocker.LOCK_EX) break except: dbg.dbg("lock failed") time.sleep(0.1) log.write("%d\t%s\n" % (util.current_sec(), msg))