Projet

Général

Profil

« Précédent | Suivant » 

Révision d33bb414

Ajouté par Jérôme Schneider il y a environ 12 ans

Fix #1265: manage log rotation

  • mandaye/config.py: add rotation options * mandaye/log.py: use TimedRotatingFileHandler * mandaye_server.py: cosmetic

Voir les différences:

mandaye/config.py
11 11
syslog = False
12 12
log_file = '/var/log/mandaye/mandaye.log'
13 13
log_level = logging.INFO
14
# Log rotation
15
# W[0-6] : weekly (0: Monday), D: day, ... (python doc)
16
log_when = 'W6'
17
# Every week
18
log_interval = 1
19
# BackupCount (keep one year of log)
20
log_backup = 52
14 21

  
15 22
# Template directory
16 23
template_directory = 'mandaye/templates'
......
72 79
        'session.expire': 3600,
73 80
}
74 81

  
75
# token timeout (for Vincennes)
82
# token timeout
76 83
# timeout in seconds
77 84
token_timeout = 60
78 85

  
mandaye/log.py
1 1

  
2 2
import logging
3
from logging import FileHandler
4
from logging.handlers import SysLogHandler
5
from mandaye.config import log_level, syslog, log_file
3
from logging.handlers import SysLogHandler, TimedRotatingFileHandler
4
from mandaye.config import log_level, log_file, syslog
5
from mandaye.config import log_when, log_interval, log_backup
6 6

  
7 7
logger = logging.getLogger('mandaye')
8 8
logger.setLevel(log_level)
......
16 16

  
17 17
# File logging
18 18
if log_file:
19
    filehandler = FileHandler(log_file)
19
    filehandler = TimedRotatingFileHandler(log_file, when=log_when,
20
            interval=log_interval, backupCount=log_backup)
21
    filehandler.setFormatter(
22
            logging.Formatter('%(asctime)s %(levelname)s %(message)s',
23
            datefmt='%Y-%m-%d %H:%M:%S'))
20 24
    logger.addHandler(filehandler)
21 25
else:
22 26
    filehandler = None
mandaye_server.py
22 22
    """ The ``gunicorn`` command line runner for launcing Gunicorn with
23 23
    generic WSGI applications.
24 24
    """
25
    logger.info('Launching Mandaye ...')
25
    logger.info('Mandaye start')
26 26
    WSGIApplication("%prog [OPTIONS]").run()
27 27

  
28 28
if __name__ == "__main__":

Formats disponibles : Unified diff