Rotate the log
This commit is contained in:
parent
e7f8684918
commit
59880f6bf1
1 changed files with 11 additions and 3 deletions
|
@ -5,11 +5,15 @@ import glob
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import logging.handlers
|
||||||
|
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
|
||||||
sys.dont_write_bytecode = True
|
sys.dont_write_bytecode = True
|
||||||
|
|
||||||
|
LOGFILE_MAX_BYTES = 50 * 1024 * 1024 # 50 MB
|
||||||
|
LOGFILE_BACKUPS = 5
|
||||||
|
|
||||||
|
|
||||||
class RtmBot(object):
|
class RtmBot(object):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
@ -40,10 +44,14 @@ class RtmBot(object):
|
||||||
self.debug = self.config.get('DEBUG', False)
|
self.debug = self.config.get('DEBUG', False)
|
||||||
|
|
||||||
# establish logging
|
# establish logging
|
||||||
|
root_logger = logging.getLogger()
|
||||||
log_file = config.get('LOGFILE', 'rtmbot.log')
|
log_file = config.get('LOGFILE', 'rtmbot.log')
|
||||||
logging.basicConfig(filename=log_file,
|
root_handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=LOGFILE_MAX_BYTES, backupCount=LOGFILE_BACKUPS)
|
||||||
level=logging.DEBUG if self.debug else logging.INFO,
|
root_formatter = logging.Formatter('%(asctime)s %(module)s %(levelname)s: %(message)s')
|
||||||
format='%(asctime)s %(module)s %(levelname)s: %(message)s')
|
root_handler.setFormatter(root_formatter)
|
||||||
|
root_logger.addHandler(root_handler)
|
||||||
|
root_logger.setLevel(logging.DEBUG if self.debug else logging.INFO)
|
||||||
|
|
||||||
logging.info('Initialized in: {}'.format(self.directory))
|
logging.info('Initialized in: {}'.format(self.directory))
|
||||||
|
|
||||||
# initialize stateful fields
|
# initialize stateful fields
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue