mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-25 12:12:53 +01:00
f786242730
Closes #84. Logs, PID files, and relay DBs will name themselves differently for every instance, to prevent conflicts. The default is always config.yml.
30 lines
795 B
Python
30 lines
795 B
Python
import logging
|
|
import sys
|
|
import os
|
|
|
|
from conf import conf, confname
|
|
|
|
level = conf['bot'].get('loglevel') or 'DEBUG'
|
|
try:
|
|
level = getattr(logging, level.upper())
|
|
except AttributeError:
|
|
print('ERROR: Invalid log level %r specified in config.' % level)
|
|
sys.exit(3)
|
|
|
|
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, '%s.log' % confname), mode='w')
|
|
logfile.setFormatter(logformat)
|
|
|
|
global log
|
|
log = logging.getLogger()
|
|
log.addHandler(logfile)
|