How to get file name of logging.FileHandler in Python?
Asked Answered
R

2

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.

Roof answered 10/10, 2012 at 6:39 Comment(1)
python.6.n6.nabble.com/…Underlaid
T
21
>>> import logging
>>> fh = logging.FileHandler('/Users/defuz/test.txt')
>>> fh.baseFilename
'/Users/defuz/test.txt'
>>> fh.stream.name
'/Users/defuz/test.txt'
Tenebrae answered 10/10, 2012 at 6:46 Comment(0)
O
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.

Overbear answered 30/9, 2013 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.