websoft9/appmanage/api/utils/common_log.py

42 lines
1.2 KiB
Python
Raw Normal View History

2023-03-15 17:55:05 +08:00
import logging
import os
from logging import handlers
class MyLogging():
# init logging
def __init__(self):
# the file of log
2023-03-16 10:03:54 +08:00
logPath = 'logs/'
2023-03-15 17:55:05 +08:00
if not os.path.exists(logPath):
os.makedirs(logPath)
2023-03-21 10:01:45 +08:00
logName = 'app_manage.log'
2023-03-15 17:55:05 +08:00
logFile = logPath + logName
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
# handler
2023-05-29 10:35:34 +08:00
time_rotating_file_handler = handlers.TimedRotatingFileHandler(filename=logFile, when="MIDNIGHT", interval=1, encoding='utf-8')
2023-03-15 17:55:05 +08:00
time_rotating_file_handler.setLevel(logging.DEBUG)
time_rotating_file_handler.setFormatter(formatter)
# config
logging.basicConfig(
level= logging.DEBUG,
handlers= [time_rotating_file_handler],
datefmt='%Y-%m-%d %H:%M:%S',
format='%(asctime)s %(levelname)s: %(message)s'
)
def info_logger(self, content):
logging.info(content)
def error_logger(self, content):
logging.error(content)
def debug_logger(self, content):
logging.debug(content)
def warning_logger(self, content):
logging.warning(content)
myLogger = MyLogging()