0

I use python 2.7.5 I created a file with configurations for logger:

[loggers]
keys=root,api

[logger_root]
handlers=screen,file

[logger_api]
handlers=fileapi
qualname=api

[formatters]
keys=simple,complex

[formatter_simple]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s

[formatter_complex]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s : %(lineno)d - %(message)s

[handlers]
keys=file,screen,fileapi

[handler_screen]
class=StreamHandler
formatter=simple
level=NOTSET
args=(sys.stdout,)

[handler_file]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=NOTSET
args=('/var/log/FMV/fmv.log',)

[handler_fileapi]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=NOTSET
args=('/var/log/FMV/fmv_api.log',)

when i call in my code logger.info and etc:

_api_logger = logging.getLogger("api")
_api_logger.info("/index was called")
_api_logger.debug("/index was called")
_api_logger.error("/index was called")

in my log file (/var/log/FMV/fmv_api.log) i see following:

2013-06-12 01:17:55,599 - api - ERROR - api : 13 - /index was called

So only error messages are recorder to log file. Why it doesn't write all message to file?

2 Answers 2

1

Logger.setLevel(lvl) Sets the threshold for this logger to lvl. Logging messages which are less severe than lvl will be ignored. When a logger is created, the level is set to NOTSET (which causes all messages to be processed when the logger is the root logger, or delegation to the parent when the logger is a non-root logger). Note that the root logger is created with level WARNING.

The term ‘delegation to the parent’ means that if a logger has a level of NOTSET, its chain of ancestor loggers is traversed until either an ancestor with a level other than NOTSET is found, or the root is reached.

http://docs.python.org/2/library/logging.html#logging.Logger.setLevel

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

2 Comments

I have set logger level in my config file - level=NOTSET. Why it doesn't work ?
Yes i have read it. But a cannot understand it. Why when i set level from code - it works, and when i set level from config file it doesn't work?
0

The problem is solved with adding the following code:

[logger_api]
handlers=fileapi
qualname=api
level=DEBUG   <--- Added

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.