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.
The logger name hierarchy is analogous to the Python package hierarchy, and identical to it if you organise your loggers on a per-module basis using the recommended construction logging.getLogger(__name__) . That's because in a module, __name__ is the module's name in the Python package namespace.
FileHandler. The FileHandler class, located in the core logging package, sends logging output to a disk file. It inherits the output functionality from StreamHandler .
>>> import logging
>>> fh = logging.FileHandler('/Users/defuz/test.txt')
>>> fh.baseFilename
'/Users/defuz/test.txt'
>>> fh.stream.name
'/Users/defuz/test.txt'
                        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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With