# -*- coding: UTF-8 -*-
'''
@Project ：SEEG_Process 
@File    ：log_config.py
@Author  ：Barry
@Date    ：2021/8/10 20:20 
'''
import logging

BASIC_FMT = "%(asctime)s - %(filename)s[line:%(lineno)d] - " \
            "%(levelname)s: %(message)s"
DATA_FMT = '%Y/%m/%d %H:%M:%S'


def create_log(logger_name='logger', filename='log.log') -> object:
    '''
    :param filename: str
                    filename of log file
    '''
    logger = logging.getLogger(logger_name)
    logger.handlers = []        # 防止logger在控制台重复打印日志
    logging.basicConfig(filename=filename,
                        format=BASIC_FMT,
                        datefmt=DATA_FMT, filemode='w',
                        level=logging.INFO)

    # 将日志信息输出到Console(控制台)
    formatter = logging.Formatter(BASIC_FMT, DATA_FMT)
    shr = logging.StreamHandler()
    shr.setFormatter(formatter)
    shr.setLevel(logging.INFO)
    logger.addHandler(shr)

    return logger
