代码拉取完成,页面将自动刷新
同步操作将从 borelist/JamTools 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2021/6/9 21:47
# @Author : Fandes
# @FileName: Logger.py
# @Software: PyCharm
import io
import os
import sys, time
from PyQt5.QtCore import QThread
class Logger(QThread):
def __init__(self, log_path="jamtools.log"):
super(Logger, self).__init__()
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
self.terminal = sys.stdout
self.log_path = log_path
self.logtime = time.time() - 2
self.loglist = []
self.running = True
self.start()
def run(self) -> None:
if os.path.exists(self.log_path):
try:
ls = os.path.getsize(self.log_path)
print("日志文件大小为:", ls, " 保存于:", self.log_path)
if ls > 2485760:
print("日志文件过大")
with open(self.log_path, "r+", encoding="utf8")as f:
f.seek(ls - 1885760)
log = "已截断日志" + time.strftime("%Y-%m-%d %H:%M:%S:\n", time.localtime(time.time())) + f.read()
f.seek(0)
f.truncate()
f.write(log)
print("新日志大小", os.path.getsize(self.log_path))
except Exception as e:
with open(self.log_path, "w", encoding="utf8")as f:
f.write("已清空日志, {}".format(e))
self.log = open(self.log_path, "a", encoding='utf8')
self.log.write("\n\nOPEN@" + time.strftime("%Y-%m-%d %H:%M:%S:\n", time.localtime(time.time())))
try:
while self.running:
if len(self.loglist):
self.process(self.loglist.pop(0))
else:
time.sleep(0.05)
except:
sys.stdout = self.terminal
print(sys.exc_info(), "log47")
def stop(self):
self.running = False
self.quit()
self.wait(2)
def write(self, message):
self.loglist.append(message)
def process(self, message):
self.terminal.write(message)
self.terminal.flush()
now = time.time()
timestr = ""
if now - self.logtime > 1:
timestr = "\n"+"-" * 20 + "@" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) + "-" * 20 + "\n"
log = timestr + message
self.log.write(log)
if now - self.logtime > 1:
self.logtime = now
self.log.flush()
def flush(self):
pass
if __name__ == '__main__':
st = time.time()
sys.stdout = Logger('hfks.log')
print("fsdafwefs")
print(time.time() - st)
time.sleep(1.5)
print(time.localtime())
time.sleep(1.1)
print("rtyuio" * 50)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。