Musicreater/nmcsup/log.py

57 lines
1.7 KiB
Python
Raw Normal View History

2021-11-21 00:59:15 +08:00
"""提供对于音创系列的日志"""
2022-01-19 17:48:47 +08:00
# 诸葛亮与八卦阵帮忙修改语法 日期:---2022年1月19日
# 统计致命三级错误0个警告二级错误0个语法一级错误9个
2021-11-21 00:59:15 +08:00
2022-01-19 17:48:47 +08:00
import logging
import os
import datetime
import sys
2021-11-21 00:59:15 +08:00
StrStartTime = str(datetime.datetime.now()).replace(':', '_')[:-7]
2022-01-19 17:48:47 +08:00
time = StrStartTime
2021-11-21 00:59:15 +08:00
2022-01-19 17:48:47 +08:00
main_path = './log/'
2021-11-21 00:59:15 +08:00
2022-01-19 17:48:47 +08:00
position = main_path + time
2022-01-23 22:33:41 +08:00
if not os.path.exists('./log/'):
os.makedirs('./log/')
2022-01-19 17:48:47 +08:00
logger = logging.getLogger(__name__)
logger.setLevel(level=logging.INFO)
handler = logging.FileHandler(position + ".logger")
print(position + ".logger")
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
logger.addHandler(handler)
logger.addHandler(console)
print("using Timbre_resources_package_generator_lib \n --made by 诸葛亮与八卦阵")
print(sys.path[0].replace("nmcsup\\logger", "log\\"))
# import logger
# 载入日志功能
StrStartTime = str(datetime.datetime.now()).replace(':', '_')[:-7]
# logger.setting(StrStartTime)
"""字符串型的程序开始时间"""
2022-01-23 22:33:41 +08:00
def log(info: str = '', isPrinted: bool = True, isLoggerLibRecord: bool = True):
2022-01-19 17:48:47 +08:00
# isLoggerLibRecord: 是否同时在logger库中记录
"""将信息连同当前时间载入日志"""
2021-11-21 00:59:15 +08:00
if not os.path.exists('./log/'):
os.makedirs('./log/')
2022-01-19 17:48:47 +08:00
with open('./log/' + StrStartTime + '.msct.log', 'a', encoding='UTF-8') as f:
f.write(str(datetime.datetime.now())[11:19] + ' ' + info + '\n')
if isPrinted:
2022-01-19 17:48:47 +08:00
print(str(datetime.datetime.now())[11:19] + ' ' + info)
if isLoggerLibRecord:
logger.info(info)