[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2012-05-18 Thread Marc Abramowitz

Marc Abramowitz msabr...@gmail.com added the comment:

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 `Vinay's 
Google Group post 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/21be57fae7e9381a`
 into this bug, in case the Google group goes away or the URL changes.

The values in the config file are interpreted in the context of the
logging module's namespace. Hence, one way of achieving what you 
want is putting any custom handlers in a module of your own, and
providing a binding in the logging module's namespace. For example: 
assuming your DBHandler is defined in a module customhandlers, you 
could do this somewhere in your code, before loading the 
configuration:

import logging
import customhandlers # Use your own module name here

logging.custhandlers = customhandlers # Bind your module to 
custhandlers in logging

and then your logging configuration can refer to 
custhandlers.DBHandler. Of course I merely used custhandlers and 
customhandlers to show how you can bind to an arbitrary name.

--
nosy: +Marc.Abramowitz

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1436
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2012-05-18 Thread Marc Abramowitz

Marc Abramowitz msabr...@gmail.com added the comment:

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))

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1436
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2007-11-20 Thread sebastian

sebastian added the comment:

thank you very much...

but: [...] the class and arguments are evaluated using the
logging package's namespace. [...]

does this mean, it is not possible to use user-defined handlers,
naturally residing outside python's class library (and logging package),
when applying fileConfig()?

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1436
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2007-11-20 Thread Vinay Sajip

Vinay Sajip added the comment:

No, it doesn't. See this post:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/21be57fae7e9381a

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1436
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2007-11-13 Thread Christian Heimes

Christian Heimes added the comment:

confirmed

The problem is in logging.config._install_handlers(cp, formatters). The
code is usin klass = eval(klass, vars(logging)) args = eval(args,
vars(logging)) to get the logger class from the logging module.

--
nosy: +tiran
versions: +Python 2.6, Python 3.0

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1436
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2007-11-13 Thread Christian Heimes

Changes by Christian Heimes:


--
assignee:  - vsajip
nosy: +vsajip
priority:  - normal

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1436
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2007-11-13 Thread Guido van Rossum

Guido van Rossum added the comment:

Somebody please propose a patch!

--
nosy: +gvanrossum

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1436
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2007-11-13 Thread Vinay Sajip

Vinay Sajip added the comment:

This is not a bug: I think you are missing something. In the first
example (interactive usage), the lines import logging and import
logging.handlers do not magically introduce RotatingFileHandler into
your interactive session's globals. To do this, you would have to say
from logging.handlers import RotatingFileHandler. An analogous example
unrelated to logging:

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
logging package's namespace. This means that for a handler defined in
the logging package itself (such as StreamHandler) no qualification is
required, but for a handler defined in the handlers subpackage, you
should specify handlers.RotatingFileHandler in the configuration file
rather than RotatingFileHandler or logging.handlers.RotatingFileHandler.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1436
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

2007-11-13 Thread Vinay Sajip

Changes by Vinay Sajip:


--
resolution:  - invalid
status: open - closed

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1436
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com