# -*- coding: utf-8 -*-
# @Author: privacy
# @Date:   2022-07-14 13:26:15
# @Last Modified by:   privacy
# @Last Modified time: 2022-08-09 16:44:04
import logging

class LoggerHandler(logging.Logger):
    def __init__(self, name: str, console_handler_level: str = logging.INFO, fmt: str = '%(levelname)s: %(asctime)s: %(name)s: %(filename)s: %(lineno)d: %(funcName)s: %(message)s'):
        super().__init__(name)
        self.setLevel(logging.INFO)
        self.fmt = logging.Formatter(fmt)
        self.set_console_handler(console_handler_level)

    def set_console_handler(self, console_handler_level: str = logging.INFO) -> None:
        ch = logging.StreamHandler()
        ch.setLevel(console_handler_level)
        ch.setFormatter(self.fmt)
        self.addHandler(ch)

    def set_file_handler(self, filename: str, mode: str = "a", file_handler_level: str = logging.WARNING) -> None:
        fh = logging.FileHandler(filename, mode=mode, encoding='utf-8')
        fh.setLevel(file_handler_level)
        fh.setFormatter(self.fmt)
        self.addHandler(fh)
