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.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined #45777
Comments
fileConfig crashes with a NameError when trying to configure a RotatingFileHandler is available on my system, a qualified name must be Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> import logging.handlers
>>> RotatingFileHandler("test.log", "a", 5000, 5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'RotatingFileHandler' is not defined
>>> logging.handlers.RotatingFileHandler("test.log", "a", 5000, 5)
<logging.handlers.RotatingFileHandler instance at 0x7940d0> fileConfig crashes, with or without qualified names: >>> import logging.config
>>> logging.config.fileConfig("test.ini")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py",
line 84, in fileConfig
handlers = _install_handlers(cp, formatters)
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py",
line 149, in _install_handlers
klass = eval(klass, vars(logging))
File "<string>", line 1, in <module>
NameError: name 'RotatingFileHandler' is not defined
>>> logging.config.fileConfig("test.qualified_name.ini")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py",
line 84, in fileConfig
handlers = _install_handlers(cp, formatters)
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py",
line 149, in _install_handlers
klass = eval(klass, vars(logging))
File "<string>", line 1, in <module>
NameError: name 'logging' is not defined test.ini (in configurationFiles.zip): [handlers] [formatters] [logger_root] [handler_fileHandler] [formatter_simpleFormatter] test.qualified_name.ini (in configurationFiles.zip): [handlers] [formatters] [logger_root] [handler_fileHandler] [formatter_simpleFormatter] |
confirmed The problem is in logging.config._install_handlers(cp, formatters). The |
Somebody please propose a patch! |
This is not a bug: I think you are missing something. In the first ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib
>>> HTTP
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'HTTP' is not defined
>>> httplib.HTTP
<class httplib.HTTP at 0x00A759F0>
>>> In the second example (using fileConfig), the documentation in http://docs.python.org/lib/logging-config-fileformat.html clearly states that the class and arguments are evaluated using the |
thank you very much... but: [...] the class and arguments are evaluated using the does this mean, it is not possible to use user-defined handlers, |
No, it doesn't. See this post: http://groups.google.com/group/comp.lang.python/browse_thread/thread/21be57fae7e9381a |
I just ran into this issue with Python 2.5 (doesn't seem to be an issue in >= 2.6?) and for the benefit of anyone else, I'm copying the answer from
import logging
import customhandlers # Use your own module name here
logging.custhandlers = customhandlers # Bind your module to "custhandlers" in logging
|
Or for a practical example, here's how I used the above technique to solve this problem in web2py: diff --git a/gluon/main.py b/gluon/main.py
index 57bf647..2f69c6b 100644
--- a/gluon/main.py
+++ b/gluon/main.py
@@ -68,6 +68,13 @@ create_missing_folders()
# set up logging for subsequent imports
import logging
import logging.config
+
+# This needed to prevent exception on Python 2.5:
+# NameError: name 'gluon' is not defined
+# See http://bugs.python.org/issue1436
+import gluon.messageboxhandler
+logging.gluon = gluon
+
logpath = abspath("logging.conf")
if os.path.exists(logpath):
logging.config.fileConfig(abspath("logging.conf")) |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: