cammil
cammil

Reputation: 9919

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?

Upvotes: 5

Views: 141

Answers (1)

Art Swri
Art Swri

Reputation: 2804

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/

Upvotes: 2

Related Questions