简体   繁体   中英

PyDev Console not printing logging for all levels

I have average experience with python, btw i just installed eclipse and pydev on top of it. And strangely the behavior of logging module looks weird.

import datetime
import logging

print datetime.date.today()
print logging
logging.info("test")
print logging.info("test2")

--------
OUTPUT::
--------
2012-10-25
<module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'>
None

Any clue why logging.info din't work ?

btw not sure if this is related, but just after pydev installation import logging itself wasn't working. Then i checked python interpreter setting and logging module wasn't there in forced builtins list (Windows->preference->Pydev->Interpreter(python)->Forced Builtins). So i added that manually to make import logging work. Thanks in advance for any pointers.

Because the default loglevel is WARNING and logging.info() logs at level lower than that. See the explanation here and the docs .

To do what you want you could try this:

logger = logging.getLogger('name_of_your_logger')
logger.setLevel(logging.INFO)
logger.info("Should get logged")

您可以在第一个日志记录语句之前使用setLevel更改默认级别。

logging.getLogger().setLevel(logging.DEBUG)

Try this if want to write into stdout:

import sys
import logging

logger = logging.getLogger()
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logger.info('teste')

Output:

teste

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM