Ticket #5331: 5331-bridgedb-rotate-logfiles.patch

File 5331-bridgedb-rotate-logfiles.patch, 1.9 KB (added by aagbsn, 8 years ago)

add logfile rotation to BridgeDB

  • bridgedb.conf

    diff --git a/bridgedb.conf b/bridgedb.conf
    index e5d7314..0ed9f79 100644
    a b PIDFILE = "bridgedb.pid" 
    1111
    1212# Either a file to log to, or None if we should log to the console.
    1313LOGFILE = "bridgedb.log"
     14
     15# Logfile rotation settings
     16LOGFILE_COUNT = 5
     17LOGFILE_ROTATE_SIZE = 10000000
     18
    1419# One of "DEBUG", "INFO", "WARNING", "ERROR"...
    15 LOGLEVEL = "INFO"
     20LOGLEVEL = "WARNING"
    1621
    1722# Files from which we read bridge descriptors, on start and on SIGHUP.
    1823BRIDGE_FILES = [ "./bridge-descriptors" ]
  • lib/bridgedb/Main.py

    diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py
    index 55f2956..8d99de1 100644
    a b import signal 
    1111import sys
    1212import time
    1313import logging
     14import logging.handlers
    1415import gettext
    1516
    1617from twisted.internet import reactor
    def configureLogging(cfg): 
    108109    """
    109110    level = getattr(cfg, 'LOGLEVEL', 'WARNING')
    110111    level = getattr(logging, level)
    111     extra = {}
    112     if getattr(cfg, "LOGFILE"):
    113         extra['filename'] = cfg.LOGFILE
    114112
    115     logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
    116                         datefmt="%b %d %H:%M:%S",
    117                         level=level,
    118                         **extra)
     113    logging.getLogger().setLevel(level)
     114    if getattr(cfg, "LOGFILE"):
     115        logfile_count = getattr(cfg, "LOGFILE_COUNT", 5)
     116        logfile_rotate_size = getattr(cfg, "LOGFILE_ROTATE_SIZE", 10000000)
     117
     118        handler = logging.handlers.RotatingFileHandler(cfg.LOGFILE, 'a',
     119                                                       logfile_rotate_size,
     120                                                       logfile_count)
     121        formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s', "%b %d %H:%M:%S")
     122        handler.setFormatter(formatter)
     123        logging.getLogger().addHandler(handler)
    119124
    120125def getKey(fname):
    121126    """Load the key stored in fname, or create a new 32-byte key and store