Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging : fileConfig does not check existance of the file #42682

Closed
dpinte mannequin opened this issue Dec 12, 2005 · 5 comments
Closed

logging : fileConfig does not check existance of the file #42682

dpinte mannequin opened this issue Dec 12, 2005 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@dpinte
Copy link
Mannequin

dpinte mannequin commented Dec 12, 2005

BPO 1378755
Nosy @vsajip

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/vsajip'
closed_at = <Date 2005-12-15.09:00:33.000>
created_at = <Date 2005-12-12.14:24:16.000>
labels = ['invalid', 'library']
title = 'logging : fileConfig does not check existance of the file'
updated_at = <Date 2005-12-15.09:00:33.000>
user = 'https://bugs.python.org/dpinte'

bugs.python.org fields:

activity = <Date 2005-12-15.09:00:33.000>
actor = 'vinay.sajip'
assignee = 'vinay.sajip'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2005-12-12.14:24:16.000>
creator = 'dpinte'
dependencies = []
files = []
hgrepos = []
issue_num = 1378755
keywords = []
message_count = 5.0
messages = ['27053', '27054', '27055', '27056', '27057']
nosy_count = 3.0
nosy_names = ['nnorwitz', 'vinay.sajip', 'dpinte']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1378755'
versions = ['Python 2.4']

@dpinte
Copy link
Mannequin Author

dpinte mannequin commented Dec 12, 2005

Hi,

The fileConfig method from the logging.config module
does not check for the existance of the config file
before trying to load it.

Worst, if the file does not exist, the exception is
totally unrelated to the file.

Example :

did@geru-itea:~/$ python
Python 2.3.5 (#2, Nov 20 2005, 16:40:39)
[GCC 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)] on
linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> from logging import config
>>> config.fileConfig('')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/logging/config.py", line 68,
in fileConfig
    flist = cp.get("formatters", "keys")
  File "/usr/lib/python2.3/ConfigParser.py", line 505,
in get
    raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'formatters'

It is really important that the exception is correctly
reported.

In fact, the problem seems to be here :

/usr/lib/python2.3/ConfigParser.py, line 258

        for filename in filenames:
            try:
                fp = open(filename)
            except IOError:
                continue
            self._read(fp, filename)

The documentation of the read method says "Files that
cannot be opened are silently ignored;".

The behaviour of logging.config.fileConfig is highly
related to the user actions. He must be informed of the
fact that the logging system have not opened its file.

I will provide a very basic path :
File /usr/lib/python2.3/logging/config.py, line 61
-------------------------------------------------

import os
if not (os.path.file(fname)):
   raise IOError('Provided filename is not existing')

Didrik

@dpinte dpinte mannequin closed this as completed Dec 12, 2005
@dpinte dpinte mannequin added the invalid label Dec 12, 2005
@dpinte dpinte mannequin assigned vsajip Dec 12, 2005
@dpinte dpinte mannequin added the stdlib Python modules in the Lib dir label Dec 12, 2005
@dpinte dpinte mannequin closed this as completed Dec 12, 2005
@dpinte dpinte mannequin added the invalid label Dec 12, 2005
@dpinte dpinte mannequin assigned vsajip Dec 12, 2005
@dpinte dpinte mannequin added the stdlib Python modules in the Lib dir label Dec 12, 2005
@dpinte
Copy link
Mannequin Author

dpinte mannequin commented Dec 12, 2005

Logged In: YES
user_id=970259

i've reported it for Python 2.4 but I reproduced it on
Python 2.3.

@dpinte
Copy link
Mannequin Author

dpinte mannequin commented Dec 12, 2005

Logged In: YES
user_id=970259

Oups, the patch should be the following :

File /usr/lib/python2.3/logging/config.py, line 61
-------------------------------------------------

import os
if not (os.path.isfile(fname)):
   raise IOError('Provided filename is not existing')

@nnorwitz
Copy link
Mannequin

nnorwitz mannequin commented Dec 15, 2005

Logged In: YES
user_id=33168

Vinay, any comments?

@vsajip
Copy link
Member

vsajip commented Dec 15, 2005

Logged In: YES
user_id=308438

I don't believe this is a logging bug. The logging code
defers to ConfigParser, and it is the responsibility of
ConfigParser to raise exceptions with appropriate messages.
Clearly, you could also pass an existing file with an
invalid format - the logging config code does not try to do
error recovery in these cases, but lets the exceptions
propagate up to calling code. Doing otherwise would amount
to defensive programming which I do not believe justified in
this case.

Please consider logging an issue against ConfigParser. After
all, a change there would benefit more than just the logging
package.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant