forked from zhayujie/bot-on-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
54 lines (41 loc) · 1.12 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# encoding:utf-8
import logging
import sys
SWITCH = True
def _get_logger():
log = logging.getLogger('log')
log.setLevel(logging.INFO)
console_handle = logging.StreamHandler(sys.stdout)
console_handle.setFormatter(logging.Formatter('[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d] - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'))
log.addHandler(console_handle)
return log
def close_log():
global SWITCH
SWITCH = False
def debug(arg, *args):
if SWITCH:
if len(args) == 0:
logger.debug(arg)
else:
logger.debug(arg.format(*args))
def info(arg, *args):
if SWITCH:
if len(args) == 0:
logger.info(arg)
else:
logger.info(arg.format(*args))
def warn(arg, *args):
if len(args) == 0:
logger.warning(arg)
else:
logger.warning(arg.format(*args))
def error(arg, *args):
if len(args) == 0:
logger.error(arg)
else:
logger.error(arg.format(*args))
def exception(e):
logger.exception(e)
# 日志句柄
logger = _get_logger()