Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get filename from a python logger

I have the following code

job_logger = logging.getLogger("abc")
job_handler = logging.FileHandler(filename)
job_logger.addHandler(job_handler)
print job_logger.something

I want to know the filename from the job_logger object. Any ideas?

like image 594
hyades Avatar asked Sep 24 '14 12:09

hyades


1 Answers

Assuming the job_logger object has only one handler for now.

>>> handler = job_logger.handlers[0]
>>> filename = handler.baseFilename
>>> print(filename)
'/tmp/test_logging_file'

And when there're multiple handlers, design your logic to get them all or get the very last one.

like image 131
starrify Avatar answered Oct 14 '22 07:10

starrify