-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
27 lines (21 loc) · 852 Bytes
/
logger.py
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
from __future__ import annotations
import logging
import os
import platform
def get_logger(name: __name__, level="INFO") -> logger:
_path = ''
if platform.system() == 'Darwin':
_path = '{}{}'.format(os.getcwd(), '/Logs/scrabble.log')
elif platform.system() == 'Windows':
_path = '{}{}'.format(os.getcwd(), '\\Logs\\scrabble.log')
possible_logs = {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
level = level.upper()
if level not in possible_logs:
level = "INFO"
logger = logging.getLogger(name)
eval("logger.setLevel(logging.{})".format(level))
file_handler = logging.FileHandler(_path)
formatter = logging.Formatter("%(asctime)s LINE=%(lineno)d func_name=%(funcName)s | %(message)s")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
return logger