Skip to content

Instantly share code, notes, and snippets.

@Calzzetta
Created January 30, 2015 20:39
Show Gist options
  • Save Calzzetta/dc0985ae8f62888d8e5d to your computer and use it in GitHub Desktop.
Save Calzzetta/dc0985ae8f62888d8e5d to your computer and use it in GitHub Desktop.
Logging with TimedRotatingFileHandler
from logging.handlers import TimedRotatingFileHandler
import logging
logHandler = TimedRotatingFileHandler('file_name.log', when="midnight")
logFormatter = logging.Formatter('%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
logHandler.setFormatter(logFormatter)
logger = logging.getLogger('time_rotate_logger')
logger.addHandler(logHandler)
logger.setLevel(logging.DEBUG)
logger.debug('Running...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment