2015-07-05 22:22:17 +02:00
|
|
|
import logging
|
2015-07-07 21:14:55 +02:00
|
|
|
import sys
|
2015-07-19 05:11:29 +02:00
|
|
|
import os
|
|
|
|
|
2015-07-07 21:14:55 +02:00
|
|
|
from conf import conf
|
|
|
|
|
2015-07-19 05:11:29 +02:00
|
|
|
level = conf['bot'].get('loglevel') or 'DEBUG'
|
2015-07-07 21:14:55 +02:00
|
|
|
try:
|
2015-07-19 05:11:29 +02:00
|
|
|
level = getattr(logging, level.upper())
|
2015-07-07 21:14:55 +02:00
|
|
|
except AttributeError:
|
|
|
|
print('ERROR: Invalid log level %r specified in config.' % level)
|
|
|
|
sys.exit(3)
|
|
|
|
|
2015-07-19 05:11:29 +02:00
|
|
|
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)
|
2015-07-20 01:48:04 +02:00
|
|
|
logfile = logging.FileHandler(os.path.join(logdir, 'pylink.log'), mode='w')
|
2015-07-19 05:11:29 +02:00
|
|
|
logfile.setFormatter(logformat)
|
2015-07-05 22:22:17 +02:00
|
|
|
|
|
|
|
global log
|
|
|
|
log = logging.getLogger()
|
2015-07-19 05:11:29 +02:00
|
|
|
log.addHandler(logfile)
|