summaryrefslogtreecommitdiff
path: root/detection/tool/LoggingTool.py
blob: 6650f3abdec8eda94210b25b0be8d0e8c2c6eda6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/3/18 15:36
# @author    : yinjinagyi
# @File    : LoggingTool.py
# @Function:

import yaml
import logging.config
import sys
sys.path.append('..')
from tool.Functions import get_project_path


class Logger:
    LOGGER_NAME = 'runLogger'

    def getLogger(self, loggerName=LOGGER_NAME):
        logging.config.dictConfig(load_config())
        logger = logging.getLogger(loggerName)
        return logger


def load_config():
    project_path = get_project_path()
    path = project_path + '/logging.yaml'
    with open(path, 'r') as f:
        config = yaml.load(f, Loader=yaml.FullLoader)
    config['handlers']['console_file']['filename'] = config['handlers']['console_file']['filename']
    return config