1

Using the Python logger I have two handlers, one used for root and one for everything else. When I set logging as 'main', I can see no handler is set in the logger.handler variable. It instead uses the root handler of syslog.

Below is a copy of the code and Configuration in use.

Code:

def load_config(self):
    logging.config.fileConfig('/etc/msdb/integration/logging.conf')
    log = logging.getLogger('main')
    log.debug("Hello")

Config:

[loggers]
keys=root,props,main,thread,rabbit,blockchain

[handlers]
keys=file,syslog

[formatters]
keys=simple

[logger_root]
level=DEBUG
handlers=syslog

[logger_props]
level=DEBUG
handlers=file
qualname=Properties
propagate=0

[logger_main]
level=DEBUG
handlers=file
qualname=Main
propagate=0

[logger_thread]
level=DEBUG
handlers=file
qualname=Thread
propagate=0

[logger_rabbit]
level=DEBUG
handlers=file
qualname=RabbitMQ
propagate=0

[logger_blockchain]
level=DEBUG
handlers=file
qualname=BigChainDB
propagate=0

[handler_file]
class=logging.handlers.RotatingFileHandler
level=NOTSET
formatter=simple
args=('/var/log/msdb/msdb.intergration.log','a', 100000, 1, 'utf8')

[handler_syslog]
class=StreamHandler
level=DEBUG
formatter=simple
args=(sys.stdout,)

[formatter_simple]
format=%(asctime)s - %(levelname)%s - %(threadName)%s - %(filename)s:%(lineno)d - %(message)s
datefmt=

2 Answers 2

3

It's because your logger in the config is called Main (the qualname setting), but the logger you log to is called main. Logger names are case-sensitive: the names should match exactly for things to work as expected.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you!! Was scratching my head for hours, can't believe it was something so simple!
0

Suppose you're call load_config in main.py, Change logger_main section of logging.conf

[logger_main]
level=DEBUG
handlers=file
qualname=__main__  ## or the __name__ attr of your .py file
propagate=0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.