Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print out only log messages for a given logger?

Currently I am doing this in my code:

logger = logging.getLogger(__name__)
logger.info("something happened")

Then at the top of my main scripts I do this:

logging.basicConfig(level=logging.INFO)

Problem is that there are too many messages. Is there any way to restrict it to one or a few different loggers?

like image 297
cammil Avatar asked Nov 04 '22 01:11

cammil


1 Answers

You can control individual loggers by name. (In your example, you used name, which will be the module name, so each logger will have a different name, module by module). You can use the logging config file to control the logging level of each logger individually. Have a look at the PEP: http://www.python.org/dev/peps/pep-0282/

like image 87
Art Swri Avatar answered Nov 09 '22 10:11

Art Swri