添加了日志器

This commit is contained in:
MarkusJoe
2022-02-16 13:10:46 +08:00
parent d80d4358ad
commit 464f2526f9
4 files changed
+133

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
[11:53:29] |app.py[<module>line:124] |INFO |I: 服务器已在 http://127.0.0.1:5000 运行
[11:54:17] |app.py[<module>line:131] |INFO |I: 程序已退出
[11:54:20] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[11:56:15] |app.py[<module>line:131] |INFO |程序已退出
[11:57:38] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[11:58:26] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[11:58:54] |app.py[<module>line:131] |INFO |程序已退出
[11:58:57] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[11:59:26] |app.py[<module>line:131] |INFO |程序已退出
[11:59:30] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[11:59:33] |app.py[<module>line:131] |INFO |程序已退出
[11:59:45] |__init__.py[<module>line:138] |ERROR |没有检测到本地主题数据库即将开始下载
[11:59:47] |__init__.py[downloadline:80] |INFO |数据库大小: 0.0Mb. 下载线程: 3
[11:59:47] |__init__.py[check_md5line:66] |INFO |本地数据库md5: d41d8cd98f00b204e9800998ecf8427e
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[11:59:47] |__init__.py[check_md5line:68] |ERROR |下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载
I: 本次下载将使用单线程下载
[11:59:49] |__init__.py[single_downloadline:118] |INFO |正在使用单线程下载中
[11:59:49] |__init__.py[single_downloadline:121] |INFO |下载完成 正在检验文件md5
[11:59:49] |__init__.py[single_downloadline:126] |INFO |本地数据库md5: 1731a1ec76b6e8279512d2476d497c9d
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[11:59:49] |__init__.py[single_downloadline:131] |INFO |md5检验已通过
[11:59:49] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[12:00:19] |app.py[<module>line:131] |INFO |程序已退出
+30
View File
@@ -0,0 +1,30 @@
[12:00:21] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[12:00:22] |app.py[<module>line:131] |INFO |程序已退出
[12:00:31] |__init__.py[<module>line:139] |ERROR |没有检测到本地主题数据库即将开始下载
[12:00:32] |__init__.py[downloadline:80] |INFO |数据库大小: 0.0Mb. 下载线程: 3
[12:00:32] |__init__.py[check_md5line:66] |INFO |本地数据库md5: d41d8cd98f00b204e9800998ecf8427e
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[12:00:32] |__init__.py[check_md5line:68] |ERROR |下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载
I: 本次下载将使用单线程下载
[12:00:35] |__init__.py[single_downloadline:118] |INFO |正在使用单线程下载中
[12:00:35] |__init__.py[single_downloadline:121] |INFO |下载完成 正在检验文件md5
[12:00:35] |__init__.py[single_downloadline:126] |INFO |本地数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[12:00:35] |__init__.py[single_downloadline:127] |INFO |远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[12:00:35] |__init__.py[single_downloadline:132] |INFO |md5检验已通过
[12:00:36] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[12:00:54] |app.py[<module>line:131] |INFO |程序已退出
[12:01:02] |__init__.py[<module>line:139] |ERROR |没有检测到本地主题数据库即将开始下载
[12:01:03] |__init__.py[downloadline:80] |INFO |数据库大小: 0.0Mb. 下载线程: 3
[12:01:03] |__init__.py[check_md5line:66] |INFO |本地数据库md5: d41d8cd98f00b204e9800998ecf8427e
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[12:01:03] |__init__.py[check_md5line:68] |ERROR |下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载
I: 本次下载将使用单线程下载
[12:01:03] |__init__.py[single_downloadline:117] |INFO |正在使用单线程下载中
[12:01:05] |__init__.py[single_downloadline:121] |INFO |下载完成 正在检验文件md5
[12:01:06] |__init__.py[single_downloadline:126] |INFO |本地数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[12:01:06] |__init__.py[single_downloadline:127] |INFO |远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
[12:01:06] |__init__.py[single_downloadline:132] |INFO |md5检验已通过
[12:01:06] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[12:06:07] |app.py[<module>line:131] |INFO |程序已退出
[12:06:10] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
[12:06:10] |app.py[<module>line:131] |INFO |程序已退出
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/16
# @File Name: findrootdir.py
import os
class Checkout:
def __init__(self, path: str):
self.path = path.split('/')[:-1]
def checkout_path(self, path: str):
if os.path.exists(f'{path}/utils'):
return True
else:
return False
def run(self):
for i in range(len(self.path)):
current_path = '/'.join('/'.join(self.path).split('/')[:-i])
if self.checkout_path(current_path):
return current_path
+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2021/12/15
# @File Name: logger.py
import os
import sys
import time
import logging.handlers
from colorlog import ColoredFormatter
class Logger:
def __init__(self):
self.date_format = '%H:%M:%S'
self.info_format_console = '%(log_color)s[%(asctime)s] |%(filename)s[%(lineno)-3s] |%(levelname)-8s |%(message)s'
self.info_format_file = '[%(asctime)s] |%(filename)s[%(funcName)sline:%(lineno)d] |%(levelname)-8s |%(message)s'
def set_logger(self):
formatter = ColoredFormatter(fmt=self.info_format_console,
datefmt=self.date_format,
reset=True,
log_colors={
'DEBUG': 'light_purple',
'INFO': 'light_cyan',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bold_red'})
formatter_file = logging.Formatter(fmt=self.info_format_file,
datefmt=self.date_format)
_logger = logging.getLogger('MainLogger')
_logger.setLevel(logging.DEBUG)
ConsoleLogger = logging.StreamHandler() # 输出到终端
ConsoleLogger.setFormatter(formatter)
log_name = time.strftime('%Y-%m-%d %H') # 一小时内使用的日志文件都是同一个
FileLogger = logging.handlers.RotatingFileHandler(filename=f'./bin/log/{log_name}.log',
maxBytes=102400,
backupCount=5) # 每个日志文件最大102400字节(100Kb)
FileLogger.setFormatter(formatter_file)
_logger.addHandler(ConsoleLogger)
_logger.addHandler(FileLogger)
return _logger
if __name__ != '__main__':
logger = Logger().set_logger()