Skip to content

Instantly share code, notes, and snippets.

@ustun
Created October 27, 2018 16:09
Show Gist options
  • Select an option

  • Save ustun/a8cff6d4125179dbdc2bcb26d48f353a to your computer and use it in GitHub Desktop.

Select an option

Save ustun/a8cff6d4125179dbdc2bcb26d48f353a to your computer and use it in GitHub Desktop.

Revisions

  1. ustun created this gist Oct 27, 2018.
    34 changes: 34 additions & 0 deletions basic_logging.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import logging
    import logging.config


    def configure_logging():
    LOG_DIR = "logs/"

    LOGGING = {
    "version": 1,
    "disable_existing_loggers": True,
    "formatters": {
    "verbose": {
    "format": "Logger: %(name)s %(levelname)s %(asctime)s %(module)s %(process)d %(thread)d [%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
    },
    "simple": {"format": "%(levelname)s %(asctime)s %(message)s"},
    "only_message": {"format": "%(message)s"},
    },
    "handlers": {
    "file": {
    "level": "INFO",
    "class": "logging.FileHandler",
    "filename": LOG_DIR + "logs.log",
    "formatter": "verbose",
    },
    "console": {
    "level": "DEBUG",
    "class": "logging.StreamHandler",
    "formatter": "simple",
    },
    },
    "root": {"level": "DEBUG", "handlers": ["file", "console"]},
    }

    logging.config.dictConfig(LOGGING)