-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
36 lines (29 loc) · 868 Bytes
/
log.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
import sys
from logging import (
INFO,
DEBUG,
FileHandler,
Formatter,
StreamHandler,
getLogger,
debug,
info,
warning,
error,
)
LONGFORMAT = "%(levelname)8s: %(asctime)s %(filename)10s: %(lineno)4d:\t%(message)s"
SHORTFORMAT = "%(levelname)-8s: %(message)s"
# Root logger gets everything. Handlers defined below will filter it out...
getLogger("").setLevel(DEBUG)
def init(filename):
filehandler = FileHandler(filename, mode="a", encoding="utf-8")
filehandler.setLevel(INFO)
filehandler.setFormatter(Formatter(LONGFORMAT))
getLogger("").addHandler(filehandler)
info("logging initialized")
# define a Handler which writes to sys.stderr
console = StreamHandler()
console.setLevel(DEBUG)
console.setFormatter(Formatter(SHORTFORMAT))
# add the handler to the root logger
getLogger("").addHandler(console)