1

I am having difficulty with the built-in logger module. WARNING messages show up but not INFO messages. Like so:

Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.info('Info')  # This line was inserted.
>>> logging.basicConfig(level=logging.DEBUG)
>>> logging.warning('Warning')
WARNING:root:Warning
>>> logging.info('Info')
>>>

Interestingly, after walking away from my desk for an hour or so and then starting a new session I got the following:

Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> logging.warning('Warning')
WARNING:root:Warning
>>> logging.info('Info')
INFO:root:Info
>>> 

It worked! The question is why did the first version not work.

Note: The question has been edited.

4
  • Possible duplicate of logging.info doesn't show up on console but warn and error do Commented May 4, 2016 at 1:22
  • Strange. That would be the expected behaviour if you hadn't set the level=logging.DEBUG parameter. It works for me as expected as you have it though. Commented May 4, 2016 at 1:22
  • The code in Thomas's link worked for me. Check out my answer below with the line of code that worked. Commented May 4, 2016 at 1:34
  • FYI: There is a bug in PyScripter (which is otherwise a great debugging environment) and it does not properly display logging messages when using the recommended remote Python interpreter. Commented May 4, 2016 at 3:35

2 Answers 2

2

I'm confused with your output, it may worth to try again using just the logging code: e.g.

Python 2.7.10 (default, May 23 2015, 09:40:32)
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> logging.warning('warning')
WARNING:root:warning
>>> logging.debug('debug')
DEBUG:root:debug
>>> logging.info('info')
INFO:root:info

you may refer to https://docs.python.org/2/library/logging.html to get more details.

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

1 Comment

Thanks. I tried again using your code and it worked. That led me to trace down the problem. See the revised question.
-1

The default level that logging is set to is warning. Any messages below that level(such as info messages) do not display. To change that, use this code:

logging.getLogger().setLevel(logging.INFO)

Reference:

logging.info doesn't show up on console but warn and error do

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.