Last active
April 2, 2020 19:51
-
-
Save mleuthold/d904527856c42d71191d51195fe779d7 to your computer and use it in GitHub Desktop.
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
######################### | |
# 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