mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-25 12:12:53 +01:00
parent
b6275130e1
commit
61804b1ecd
20
log.py
20
log.py
@ -1,15 +1,29 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
from conf import conf
|
from conf import conf
|
||||||
|
|
||||||
level = conf['bot']['loglevel'].upper()
|
level = conf['bot'].get('loglevel') or 'DEBUG'
|
||||||
try:
|
try:
|
||||||
level = getattr(logging, level)
|
level = getattr(logging, level.upper())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print('ERROR: Invalid log level %r specified in config.' % level)
|
print('ERROR: Invalid log level %r specified in config.' % level)
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
logging.basicConfig(level=level, format='%(asctime)s [%(levelname)s] %(message)s')
|
curdir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
logdir = os.path.join(curdir, 'log')
|
||||||
|
# Make sure our log/ directory exists
|
||||||
|
os.makedirs(logdir, exist_ok=True)
|
||||||
|
|
||||||
|
_format = '%(asctime)s [%(levelname)s] %(message)s'
|
||||||
|
logging.basicConfig(level=level, format=_format)
|
||||||
|
|
||||||
|
# Set log file to $CURDIR/log/pylink
|
||||||
|
logformat = logging.Formatter(_format)
|
||||||
|
logfile = logging.FileHandler(os.path.join(logdir, 'pylink.log'))
|
||||||
|
logfile.setFormatter(logformat)
|
||||||
|
|
||||||
global log
|
global log
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
log.addHandler(logfile)
|
||||||
|
Loading…
Reference in New Issue
Block a user