commit update
This commit is contained in:
parent
92bef1f9d9
commit
a899674242
|
@ -36,9 +36,9 @@ class Logging:
|
|||
|
||||
def set_console_logger(self):
|
||||
'''设置控制台日志输出'''
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(self._formatter)
|
||||
self._logger.addHandler(console_handler)
|
||||
console_handler = logging.StreamHandler() #创建一个StreamHandler对象
|
||||
console_handler.setFormatter(self._formatter) #使用之前定义的日志格式
|
||||
self._logger.addHandler(console_handler) #将控制台日志处理器添加到日志对象中
|
||||
|
||||
def set_file_logger(self):
|
||||
'''设置日志文件输出'''
|
||||
|
@ -46,12 +46,12 @@ class Logging:
|
|||
'%(pathname)s - %(levelname)s: %(message)s')
|
||||
# 将输出日志信息保存到文件中
|
||||
file_handler = logging.handlers.RotatingFileHandler(
|
||||
self._log_filename, maxBytes=10485760, backupCount=5, encoding="utf-8")
|
||||
self._log_filename, maxBytes=10485760, backupCount=5, encoding="utf-8") #文件最大大小为10MB,若超过就自动创建新的日志文件;保留文件数为5个,超过后删除最旧的
|
||||
file_handler.setFormatter(self._formatter)
|
||||
self._logger.addHandler(file_handler)
|
||||
|
||||
def get_logger(self):
|
||||
return self._logger
|
||||
return self._logger #获取日志记录对象,获取已设置好的日志记录器对象,用来记录日志信息
|
||||
|
||||
|
||||
logger = Logging().get_logger()
|
8
main.py
8
main.py
|
@ -9,7 +9,7 @@ from threading import Thread
|
|||
import config.baseConfig as baseConfig
|
||||
|
||||
|
||||
def monitoring_loop():
|
||||
def monitoring_loop(): #实现一个简单的定时监控任务,用于定期执行操作并记录日志信息
|
||||
while True:
|
||||
check_and_update_pull()
|
||||
now = datetime.datetime.now()
|
||||
|
@ -18,10 +18,10 @@ def monitoring_loop():
|
|||
|
||||
|
||||
def run():
|
||||
monitoring_thread = Thread(target=monitoring_loop)
|
||||
monitoring_thread.start()
|
||||
monitoring_thread = Thread(target=monitoring_loop) #创建新线程
|
||||
monitoring_thread.start() #启动线程,开始执行监控任务
|
||||
|
||||
app.run(host=baseConfig.host, port=baseConfig.port)
|
||||
app.run(host=baseConfig.host, port=baseConfig.port) #启动应用程序,开始监听指定主机号和端口号,等待接受请求并响应
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue