I use the following setting for logging
Yaml based configuration
Create a yaml file called logging.yml , like this
version: 1 formatters: simple: format: "%(name)s - %(lineno)d - %(message)s" complex: format: "%(asctime)s - %(name)s - %(lineno)d - %(message)s" handlers: console: class: logging.StreamHandler level: DEBUG formatter: simple file: class: logging.handlers.TimedRotatingFileHandler when: midnight backupCount: 5 level: DEBUG formatter: simple filename : Thrift.log loggers: qsoWidget: level: INFO handlers: [console,file] propagate: yes __main__: level: DEBUG handlers: [console] propagate: yes
Python is the main
The "core" module should look like this:
import logging.config import logging with open('logging.yaml','rt') as f: config=yaml.safe_load(f.read()) f.close() logging.config.dictConfig(config) logger=logging.getLogger(__name__) logger.info("Contest is starting")
Submodules / Classes
They should start as follows
import logging class locator(object): def __init__(self): self.logger = logging.getLogger(__name__) self.logger.debug('{} initialized')
Hope this helps you ...
source share