Skip to content

Instantly share code, notes, and snippets.

@mleuthold
Last active April 2, 2020 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mleuthold/d904527856c42d71191d51195fe779d7 to your computer and use it in GitHub Desktop.
Save mleuthold/d904527856c42d71191d51195fe779d7 to your computer and use it in GitHub Desktop.
#########################
# logging.conf
#########################
[loggers]
keys=root,sampleLogger
[handlers]
keys=consoleHandler
[formatters]
keys=sampleFormatter
[logger_root]
level=INFO
handlers=consoleHandler
[logger_sampleLogger]
level=INFO
handlers=consoleHandler
qualname=sampleLogger
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=sampleFormatter
args=(sys.stdout,)
[formatter_sampleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=%Y-%m-%d %H:%M:%S
#########################
# main.py
#########################
import logging, logging.config, json, os
# configure the logger
logging.config.fileConfig('logging.conf')
logger = logging.getLogger(__name__)
# Access all environment variables
logger.info(f'All available environment variables: {os.environ}')
#########################
# main_hardcoded.py
#########################
logging_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logging_datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(
format=self.logging_format, datefmt=self.logging_datefmt, level=logging.INFO
)
logger = logging.getLogger(self.logger_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment