16

A logging.FileHandler is constructed with a file name, so is there any way to get the file name from the logging.FileHandler object?

I tried dir(logging.FileHandler) but didn't see any possible solutions.

1

2 Answers 2

21
>>> import logging
>>> fh = logging.FileHandler('/Users/defuz/test.txt')
>>> fh.baseFilename
'/Users/defuz/test.txt'
>>> fh.stream.name
'/Users/defuz/test.txt'
Sign up to request clarification or add additional context in comments.

Comments

6

Please find dir(logging.FileHandler)

 ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', 
  '__getattribute__', '__hash__', '__init__', '__module__', '__new__', 
  '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', 
  '__str__', '__subclasshook__', '__weakref__', '_name', '_open', 'acquire', 
  'addFilter', 'baseFilename', 'close', 'createLock', 'emit', 'encoding', 'filter', 
  'filters', 'flush', 'format', 'formatter', 'get_name', 'handle', 'handleError', 
  'level', 'lock', 'mode', 'name', 'release', 'removeFilter', 'setFormatter', 'setLevel', 
  'set_name', 'stream']

You have option obj.baseFilename to get the file name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.