Created
June 20, 2020 09:18
-
-
Save ProfAvery/266d93afd22fc760c15d51295b30d316 to your computer and use it in GitHub Desktop.
Simple logging configuration for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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