Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file the Python logging module is currently logging to?

Tags:

python

logging

Is there a way to do this? If logging.config.fileConfig('some.log') is the setter, what's the getter? Just curious if this exists.

like image 784
Bialecki Avatar asked Jul 22 '10 16:07

Bialecki


1 Answers

Below simple logic for single file handler:

>>> import logging
>>> logger = logging.getLogger("test")
>>> handler = logging.FileHandler("testlog.log")
>>> logger.addHandler(handler)
>>> print logger.handlers[0].baseFilename
/home/nav/testlog.log
>>>
like image 135
Naveen Avatar answered Oct 30 '22 15:10

Naveen