-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlog.py
36 lines (28 loc) · 752 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 logging
import coloredlogs
import argparse
import functools
log = logging.getLogger("main")
exception = log.exception
info = log.info
debug = log.debug
error = log.error
warn = log.warning
def get_arg(arg):
try:
parser = argparse.ArgumentParser()
parser.add_argument("--log", help="log help", default="INFO")
args = parser.parse_args()
return vars(args)[arg]
except:
return "INFO"
def setup(level="INFO"):
print("setting logging with level: ", level)
log.setLevel(level)
logging.getLogger().setLevel(logging.ERROR)
coloredlogs.install(
level=level,
fmt="%(asctime)s %(threadName)s %(levelname)s %(message)s",
logger=log,
)
setup(get_arg("log"))