Last active
December 2, 2020 07:38
-
-
Save richardstrnad/b67474cccc7ec010e2d8ac916e47fd0d to your computer and use it in GitHub Desktop.
Simple Logging Setup for Python3, requires pyyaml
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
import logging | |
import logging.config | |
import module | |
import yaml | |
logging_config = 'logging.conf' | |
with open(logging_config) as fp: | |
config = yaml.safe_load(fp) | |
logging.config.dictConfig(config) | |
logger = logging.getLogger('main') | |
logger.debug('Welcome to my logging setup') | |
logger.info('Welcome to my logging setup') | |
logger.warning('Welcome to my logging setup') | |
logger.error('Welcome to my logging setup') | |
module.test_func() |
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
version: 1 | |
formatters: | |
simple: | |
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
short: | |
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
datefmt: '%H:%M:%S' | |
handlers: | |
console: | |
class: logging.StreamHandler | |
level: DEBUG | |
formatter: short | |
stream: ext://sys.stdout | |
file: | |
class : logging.handlers.RotatingFileHandler | |
level: INFO | |
formatter: simple | |
filename: logconfig.log | |
maxBytes: 104857600 | |
backupCount: 5 | |
loggers: | |
main: | |
level: DEBUG | |
handlers: [console, file] | |
propagate: no | |
root: | |
level: NOTSET | |
handlers: [console, file] | |
propagate: yes |
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
import logging | |
logger = logging.getLogger('main.module') | |
logger.addHandler(logging.NullHandler()) | |
def test_func(): | |
logger.debug('Module Logged!') | |
logger.info('Module Logged!') | |
logger.warning('Module Logged!') | |
logger.error('Module Logged!') | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment