2

I am about to configure a python logging system using the dictconfig format in settings.py as suggested by Django. For effectiveness, I would like to log entries in monthly splitted log files regardless of number of days in the month (or, in the future, depending of workload of my project, by iso week number). Unfortunately, the python's TimedRotatingFileHandler can't do that. I had the idea to use the standard FileHandler and dynamically change the filename (customizing it btw).

'fichierMensuelCustom': {
    'level': 'INFO',
    'class': 'logging.FileHandler',
    'filename': lambda x: 'logs/projet/projet_{0}.log'.format(time.strftime('%m-%Y')),
    'formatter': 'complet'
    },

(please don't laugh at it) It doesn't work, I'm stuck… Any suggestions?

Bogey Jammer
  • 638
  • 2
  • 8
  • 23
  • `filename` doesn't take a callable, so indeed that won't work. – Martijn Pieters Dec 22 '12 at 21:45
  • I just tried the lambda technique to generate the filename on the run… I knew that it had few chances to work. – Bogey Jammer Dec 22 '12 at 21:49
  • 1
    I'd say this cannot be done with the default rotating handler. You'll have to use a custom logging handler (subclassing `TimedRotatingFileHandler `, probably). Perhaps using the external `logrotate` facility would be better, not sure if Django can be configured to re-open log files on a `HUP` signal or similar though. – Martijn Pieters Dec 22 '12 at 22:15
  • do you know indeed if there's a mechanical system like `HUP` signal for django? – FlogFR Jan 20 '15 at 09:33

0 Answers0