You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
# coding=utf-8
|
|
"""
|
|
@Author: fu-zhe
|
|
@FileName: ext_logging.py
|
|
@DateTime: 2024/5/16 14:27
|
|
@Description:
|
|
"""
|
|
import logging
|
|
import os
|
|
from mlogging import TimedRotatingFileHandler_MP
|
|
from appsUtils import env
|
|
|
|
APPFOLDERNAME = 'uebaMetricsAnalysis'
|
|
|
|
|
|
def get_logger(logfile):
|
|
"""
|
|
获取日志句柄
|
|
"""
|
|
logger = logging.getLogger(logfile)
|
|
logger.setLevel(logging.DEBUG)
|
|
logroot = env.get_isop_root() + "/apps/" + APPFOLDERNAME + "/logs"
|
|
if not os.path.exists(logroot):
|
|
os.mkdir(logroot)
|
|
filehandle = TimedRotatingFileHandler_MP(os.path.normpath(logroot + "/" + \
|
|
logfile + ".log"), 'midnight')
|
|
filehandle.suffix = "%Y-%m-%d"
|
|
filehandle.setLevel(logging.DEBUG)
|
|
consolehandle = logging.StreamHandler()
|
|
consolehandle.setLevel(logging.DEBUG)
|
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
filehandle.setFormatter(formatter)
|
|
consolehandle.setFormatter(formatter)
|
|
logger.addHandler(filehandle)
|
|
return logger
|
|
|
|
|
|
logger = get_logger(APPFOLDERNAME)
|
|
|