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.
58 lines
1.8 KiB
58 lines
1.8 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'
|
|
#定时任务
|
|
APP_CRON_FOLDERNAME = 'uebaMetricsAnalysis_cron'
|
|
#数据追踪 用于数据排查
|
|
APP_TRACE_FOLDERNAME = 'uebaMetricsAnalysis_trace'
|
|
#审计日志
|
|
APP_AUDIT_FOLDERNAME = 'uebaMetricsAnalysis_audit'
|
|
def get_clean_file_path():
|
|
fileroot = env.get_isop_root() + "/apps/" + APPFOLDERNAME + "/files"
|
|
if not os.path.exists(fileroot):
|
|
os.mkdir(fileroot)
|
|
return fileroot
|
|
|
|
def merge_large_file_path():
|
|
file_path = get_clean_file_path()+"/merge_files"
|
|
if not os.path.exists(file_path):
|
|
os.mkdir(file_path)
|
|
return file_path
|
|
|
|
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)
|
|
logger_cron = get_logger(APP_CRON_FOLDERNAME)
|
|
logger_trace = get_logger(APP_TRACE_FOLDERNAME)
|
|
logger_audit = get_logger(APP_AUDIT_FOLDERNAME) |