Working Ninja
2017-08-27T08:56:34

Here's how I set up logging where:

  • Log files rotate nightly (at midnight).
  • We keep 10 total log files (as history).
import logging import os # Set up logging logger = logging.getLogger(__file__) handler_kwargs = { 'filename': os.path.join(base_dir, 'file.log'), 'when': 'midnight', 'backupCount': 10 } handler …

READ MORE

2016-11-21T23:42:35
import logging logging_config = { 'filename': '/var/log/app_log', 'format': '%(asctime)s [%(levelname)s] %(message)s', 'level': logging.INFO } logging.basicConfig(**logging_config) logging.info('Our logged message.')

This will output the following to /var/log/app_log:

2016-11-21 23:50:53,677 [INFO] Our logged message.

Source: https://docs.python.org/2/howto/logging.html#logging-basic-tutorial

READ MORE