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.

ChaimG
  • 7,024
  • 4
  • 38
  • 46
  • Possible duplicate of [logging.info doesn't show up on console but warn and error do](http://stackoverflow.com/questions/11548674/logging-info-doesnt-show-up-on-console-but-warn-and-error-do) – Thtu May 04 '16 at 01: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. – Jamie Bull May 04 '16 at 01:22
  • The code in Thomas's link worked for me. Check out my answer below with the line of code that worked. – MattCorr May 04 '16 at 01: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. – ChaimG May 04 '16 at 03:35

2 Answers2

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.

Guoliang
  • 885
  • 2
  • 12
  • 20
  • Thanks. I tried again using your code and it worked. That led me to trace down the problem. See the revised question. – ChaimG May 04 '16 at 03:13
-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

Community
  • 1
  • 1
MattCorr
  • 371
  • 3
  • 11