Skip to content

Commit

Permalink
增加日志系统
Browse files Browse the repository at this point in the history
  • Loading branch information
fandesfyf committed Jun 9, 2021
1 parent ac5aea8 commit 8181707
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
59 changes: 59 additions & 0 deletions Logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!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


class Logger(object):
def __init__(self, log_path="jamtools.log"):
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
self.terminal = sys.stdout
if os.path.exists(log_path):
ls = os.path.getsize(log_path)
print("日志文件大小为:", ls," 保存于:", log_path)
if ls > 2485760:
print("日志文件过大")
with open(log_path, "r+", encoding="utf-8")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(log_path))
self.log = open(log_path, "a", encoding='utf8')
self.logtime = time.time()
self.log.write("\n\nOPEN@" + time.strftime("%Y-%m-%d %H:%M:%S:\n", time.localtime(time.time())))

def write(self, message):
self.terminal.write(message)
now = time.time()
timestr = ""
if now - self.logtime > 1:
timestr = "\n@" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) + "-" * 40 + "\n"

log = timestr + message
self.log.write(log)
if now - self.logtime > 1:
self.logtime = now
self.log.flush()
self.terminal.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)
3 changes: 2 additions & 1 deletion jamtoolsbuild.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time

jamfilelist = ["PyQt5CoreModels", "jamcontroller", "WEBFilesTransmitter", "clientFilesTransmitter",
"jamscreenshot", "jampublic", "jamroll_screenshot"]
"jamscreenshot", "jampublic", "jamroll_screenshot","Logger"]
print("说明:test.py文件为主文件,main.py为存放引入库的文件(无需管),scr文件夹是fbs打包的项目目录.\n"
"运行本文件打包时,会自动将test.py文件覆盖到PyQt5CoreModels.py(这是前期为了防反编译搞的hh)中,然后会自动解析所有jamfilelist中源码的引入库,"
"并将所有需要的库格式化后写入main.py文件中,从而让pyinstall可以找到(否则可能有找不到库的错误)"
Expand Down Expand Up @@ -78,6 +78,7 @@
if line not in importfilelist:
importfilelist.append(line)
line = soursef.readline()

mainf.writelines(importfilelist)
mainf.writelines(["from PyQt5CoreModels import main\n", "main()\n\n"])
shutil.copy2('main.py', 'src/main/python/main.py')
Expand Down
11 changes: 7 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
import json
import socket
import gc

import sys
import os, re
from Logger import Logger
from jampublic import Commen_Thread, OcrimgThread, Transparent_windows, FramelessEnterSendQTextEdit, APP_ID, API_KEY, \
SECRECT_KEY, PLATFORM_SYS, TrThread, mutilocr

import http.client
import os, re

import random
import shutil
import subprocess
import sys

import time
from urllib.parse import quote

Expand Down Expand Up @@ -45,6 +47,7 @@
from clientFilesTransmitter import ClientFilesTransmitterGroupbox
import jamresourse

sys.stdout = Logger(os.path.join(os.path.expanduser('~'),"jamtools.log"))
if PLATFORM_SYS == "win32":
import win32con
import ctypes, ctypes.wintypes
Expand All @@ -60,7 +63,7 @@
# API_KEY = QSettings('Fandes', 'jamtools').value('BaiduAI_APPKEY', 'wuYjn1T9GxGIXvlNkPa9QWsw', str)
# SECRECT_KEY = QSettings('Fandes', 'jamtools').value('BaiduAI_SECRECT_KEY', '89wrg1oEiDzh5r0L63NmWeYNZEWUNqvG', str)

VERSON = "0.12.200226Beta"
VERSON = "0.13.A"


class JHotkey(QThread):
Expand Down

0 comments on commit 8181707

Please sign in to comment.