Skip to content

Instantly share code, notes, and snippets.

@ProfAvery
Created June 20, 2020 09:18
Show Gist options
  • Save ProfAvery/266d93afd22fc760c15d51295b30d316 to your computer and use it in GitHub Desktop.
Save ProfAvery/266d93afd22fc760c15d51295b30d316 to your computer and use it in GitHub Desktop.
Simple logging configuration for Python
#
# Simple logging configuration for Python
#
# NOTE: Don't add spaces between comma-separated lists in this file
#
[DEFAULT]
filename = 'output.log'
[loggers]
keys = root
[logger_root]
level = INFO
handlers = console,logfile
[handlers]
keys = console,logfile
[handler_console]
class = StreamHandler
args = (sys.stdout,)
formatter = simple
[handler_logfile]
class = FileHandler
args = (%(filename)s,)
formatter = simple
[formatters]
keys = simple
[formatter_simple]
format = [%(asctime)s] %(levelname)-8s %(message)s
datefmt = %m/%d/%y %H:%M:%S %Z
#!/usr/bin/env python3
import logging.config
logging.config.fileConfig('logging.ini')
logger = logging.getLogger(__name__)
logger.info('Logging configured successfully.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment