Skip to content

Python Logging

Heath Brown edited this page Jan 24, 2024 · 5 revisions

Python Logging for an Application

Use DictConfig instead of Basicconfig

import logging.config

logger.getLogger("my_app")

logging_config = {
   "version": 1,
   "disable_existing_loggers" : False,
   "filters" : {},
   "formatteres" : {},
   "handlers" : {},
   "loggers" : {}
}

def main():
   logging.config.dictConfig(config=logging_config)
   ...

Python Libraries

should not have configuration You can have logging and handlers but no 'configuration'

Remember log4j!

  • Don't log user input (avoid makeLogRecord)
  • If you do NEED to sanitize the input before logging
  • DO NOT send python objects to logging as pickle

References

Clone this wiki locally