forked from ysc3839/bilibili-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
29 lines (23 loc) · 807 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pylint: disable=I0011,C0103,C0111
import logging
import logging.handlers
def getLogger():
logger = logging.getLogger('blive')
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
logger.addHandler(stream_handler)
syslog_handler = None
for addr in ['/dev/log', '/var/run/syslog']:
try:
syslog_handler = logging.handlers.SysLogHandler(address=addr)
except:
pass
else:
break
if syslog_handler:
syslog_handler.setFormatter(logging.Formatter('%(filename)s[%(process)d]: [%(levelname)s] %(message)s'))
logger.addHandler(syslog_handler)
logger.setLevel(logging.DEBUG)
return logger