This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: logging fileConfig swallows handler exception
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: tdir, vinay.sajip
Priority: normal Keywords:

Created on 2006-06-18 19:33 by tdir, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
config.py tdir, 2006-06-22 23:19
Messages (4)
msg28827 - (view) Author: tdir (tdir) Date: 2006-06-18 19:33
If you specify a handler such as a RotatingFileHandler
and the path you provide in the args specification
('option') is bad, config.fileConfig() catches the
exception and 'swallows' it. The result is later on,
when that handler is specified for a logger, you get an
exception saying there is no such handler. A much
friendlier behavior would be for fileConfig() to raise
an exception so the real cause of the problem can be
easily identified. Also, if there is a bug in the code
itself, it would also get swallowed in similar fashion.
In general, silently swallowing exceptions is rarely
the best choice IMHO.

Example ini with bad path (assuming /bad/path does not
exist):
[handler_defaultrotatingfile]
class=handlers.RotatingFileHandler
args=("/bad/path/logdir/my_log.log", 'w', 100000, 10)
formatter=std

msg28828 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-06-22 16:37
Logged In: YES 
user_id=308438

Can you give some more details? I don't get the problem: see
the transcript below.

ActivePython 2.4 Build 243 (ActiveState Corp.) based on
Python 2.4 (#60, Nov 30 2004, 09:34:21) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import logging.config
>>> logging.config.fileConfig("junk.ini")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python\lib\logging\config.py", line 83, in fileConfig
    handlers = _install_handlers(cp, formatters)
  File "C:\Python\lib\logging\config.py", line 151, in
_install_handlers
    h = apply(klass, args)
  File "C:\Python\lib\logging\handlers.py", line 109, in
__init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding)
  File "C:\Python\lib\logging\handlers.py", line 61, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding)
  File "C:\Python\lib\logging\__init__.py", line 770, in
__init__
    stream = open(filename, mode)
IOError: [Errno 2] No such file or directory:
'/bad/path/junk.log'
msg28829 - (view) Author: tdir (tdir) Date: 2006-06-22 23:18
Logged In: YES 
user_id=1541624

Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit
(Intel)] on win32

ABOVE IS THE PYTHON SIGNON

I HAVE ALSO ATTACHED THE config.py FROM THE INSTALL. IT
CONTAINS NO _install_handlers 

APPEARS TO BE A VERY DIFFERENT VERSION FROM YOURS


msg28830 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-06-23 06:10
Logged In: YES 
user_id=308438

Ok, then the bug has already been fixed (or superseded by 
changes to the code).

I'll close this report: if you want to use the latest code, 
just download it from the Python subversion repository. It 
should run without problems in 2.4.2.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43519
2006-06-18 19:33:12tdircreate