-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
36 lines (26 loc) · 833 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
28
29
30
31
32
33
34
35
36
from io import TextIOWrapper
from datetime import datetime
_format = "%(message)s"
_datefmt = "%H:%M:%S"
_handler = None
def config(format=None, datefmt=None, handler=None):
global _format, _datefmt, _handler
if format is not None:
_format = format
if datefmt is not None:
_datefmt = datefmt
if handler is not None and isinstance(handler, str):
_handler = open(handler, "a", encoding="utf-8")
def _print(msg, level):
print(_format %
{
"asctime": str(datetime.today().strftime(_datefmt)),
"levelname": level.upper(),
"message": msg,
}, file=_handler)
if isinstance(_handler, TextIOWrapper):
_handler.flush()
def info(msg):
_print(msg, info.__name__)
def warning(msg):
_print(msg, warning.__name__)