Commit 31c55cd3 authored by aagbsn's avatar aagbsn
Browse files

5331 - Add log rotation to BridgeDB

Switches BridgeDB logger to use RotatingFileHandler.
The defaults are to keep 5 backups, of 10MB each.
Adds LOGFILE_COUNT, LOGFILE_ROTATE_SIZE to bridgedb.conf, and
sets the default value for LOGLEVEL to WARNING.

Thanks to weasel for this patch.
parent 1b1cc253
......@@ -11,8 +11,13 @@ PIDFILE = "bridgedb.pid"
# Either a file to log to, or None if we should log to the console.
LOGFILE = "bridgedb.log"
# Logfile rotation settings
LOGFILE_COUNT = 5
LOGFILE_ROTATE_SIZE = 10000000
# One of "DEBUG", "INFO", "WARNING", "ERROR"...
LOGLEVEL = "INFO"
LOGLEVEL = "WARNING"
# Files from which we read bridge descriptors, on start and on SIGHUP.
BRIDGE_FILES = [ "./bridge-descriptors" ]
......
......@@ -11,6 +11,7 @@ import signal
import sys
import time
import logging
import logging.handlers
import gettext
from twisted.internet import reactor
......@@ -110,14 +111,18 @@ def configureLogging(cfg):
"""
level = getattr(cfg, 'LOGLEVEL', 'WARNING')
level = getattr(logging, level)
extra = {}
if getattr(cfg, "LOGFILE"):
extra['filename'] = cfg.LOGFILE
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
datefmt="%b %d %H:%M:%S",
level=level,
**extra)
logging.getLogger().setLevel(level)
if getattr(cfg, "LOGFILE"):
logfile_count = getattr(cfg, "LOGFILE_COUNT", 5)
logfile_rotate_size = getattr(cfg, "LOGFILE_ROTATE_SIZE", 10000000)
handler = logging.handlers.RotatingFileHandler(cfg.LOGFILE, 'a',
logfile_rotate_size,
logfile_count)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s', "%b %d %H:%M:%S")
handler.setFormatter(formatter)
logging.getLogger().addHandler(handler)
def getKey(fname):
"""Load the key stored in fname, or create a new 32-byte key and store
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment