|
|
|
|
|
|
| Author |
Message |
Neil Benn *nix forums beginner
Joined: 25 Apr 2005
Posts: 28
|
Posted: Wed Feb 02, 2005 10:52 am Post subject:
Logging
|
|
|
Hello,
I'm running a test and having issues with logging, if I call
logging.shutdown() and then want to start the logging going again then I
get a problem as if I call shutdown, I can't get the root logger again,
such as :
..>>> import logging
..>>> objTestLogger = logging.getLogger()
..>>> objTestLogger.setLevel(logging.INFO)
..>>> objTestLogger.addHandler(logging.FileHandler('c:\\test.log'))
..>>> objTestLogger.info("THIS IS A TEST")
..>>> logging.shutdown()
..>>> objTestLogger = logging.getLogger()
..>>> objTestLogger.setLevel(logging.INFO)
..>>> objTestLogger.info("THIS IS A TEST")
..Traceback (most recent call last):
.. File "<stdin>", line 1, in ?
.. File "c:\program files\python23\lib\logging\__init__.py", line 893,
in info
.. apply(self._log, (INFO, msg, args), kwargs)
.. File "c:\program files\python23\lib\logging\__init__.py", line 994,
in _log
.. self.handle(record)
.. File "c:\program files\python23\lib\logging\__init__.py", line 1004,
in handle
.. self.callHandlers(record)
.. File "c:\program files\python23\lib\logging\__init__.py", line 1037,
in callHandlers
.. hdlr.handle(record)
.. File "c:\program files\python23\lib\logging\__init__.py", line 592,
in handle
.. self.emit(record)
.. File "c:\program files\python23\lib\logging\handlers.py", line 103,
in emit
.. self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
..ValueError: I/O operation on closed file
..>>>
This means that I any code that write or use, if it calls
logging.shutdown the logging is buggered for that process - is my
analysis correct?
Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : benn@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com |
|
| Back to top |
|
 |
Neil Benn *nix forums beginner
Joined: 25 Apr 2005
Posts: 28
|
Posted: Wed Feb 02, 2005 11:01 am Post subject:
Re: Logging
|
|
|
Neil Benn wrote:
| Quote: | Hello,
I'm running a test and having issues with logging, if I call
logging.shutdown() and then want to start the logging going again then
I get a problem as if I call shutdown, I can't get the root logger
again, such as :
.<snip
|
Previous code missed out a line :
..>>> import logging
..>>> objTestLogger = logging.getLogger()
..>>> objTestLogger.setLevel(logging.INFO)
..>>> objTestLogger.addHandler(logging.FileHandler('c:\\test.log'))
..>>> objTestLogger.info("THIS IS A TEST")
..>>> logging.shutdown()
..>>> objTestLogger = logging.getLogger()
..>>> objTestLogger.setLevel(logging.INFO)
..>>> objTestLogger.addHandler(logging.FileHandler('c:\\test.log'))
..>>> objTestLogger.info("THIS IS A TEST")
..Traceback (most recent call last):
.. File "c:\program files\python23\lib\logging\__init__.py", line 679, in
emit
.. self.stream.write("%s\n" % msg)
..ValueError: I/O operation on closed file
..>>>
Sorry for the orginal mispost!!
Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : benn@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com |
|
| Back to top |
|
 |
Samuel Kilchenmann *nix forums beginner
Joined: 03 Feb 2005
Posts: 1
|
Posted: Thu Feb 03, 2005 5:15 am Post subject:
Re: Logging
|
|
|
"Neil Benn" <benn@cenix-bioscience.com> schrieb im Newsbeitrag
news:mailman.1750.1107345636.22381.python-list@python.org...
| Quote: | Neil Benn wrote:
Hello,
I'm running a test and having issues with logging, if I call
logging.shutdown() and then want to start the logging going again
then I get a problem as if I call shutdown, I can't get the root
logger again, such as :
.<snip
Previous code missed out a line :
.>>> import logging
.>>> objTestLogger = logging.getLogger()
.>>> objTestLogger.setLevel(logging.INFO)
.>>> objTestLogger.addHandler(logging.FileHandler('c:\\test.log'))
.>>> objTestLogger.info("THIS IS A TEST")
.>>> logging.shutdown()
.>>> objTestLogger = logging.getLogger()
.>>> objTestLogger.setLevel(logging.INFO)
.>>> objTestLogger.addHandler(logging.FileHandler('c:\\test.log'))
.>>> objTestLogger.info("THIS IS A TEST")
.Traceback (most recent call last):
. File "c:\program files\python23\lib\logging\__init__.py", line 679,
in emit
. self.stream.write("%s\n" % msg)
.ValueError: I/O operation on closed file
.
logging.shutdown() doesn't clean up the dict of handlers at the module |
level and the list of handlers maintained and at the level of the
manager of loggers. So after calling logging.getLogger() etc. for the
second time, you still have the closed filehandle in the list of
loghandlers. The new FileHandler with the open filehandle is appended to
this list of handlers. Then when you call ...info("...") this call is
dispatched to all handlers in the handlerlist, i.e. also to the one with
the closed filehandle.
I don't know if this has to be considered a bug in the logging module or
if your use case is simply not covered.
If you add something like
..>>> logging._handlers.clear()
..>>> logging.root.handlers = []
..>>> for l in logging.Logger.manager.loggerDict.values():
..>>> l.handlers = []
after logging.shutdown() and before getting the new logger, your script
will probably run without errors.
hth,
Samuel |
|
| Back to top |
|
 |
Neil Benn *nix forums beginner
Joined: 25 Apr 2005
Posts: 28
|
Posted: Thu Feb 03, 2005 9:56 am Post subject:
Re: Logging
|
|
|
Samuel Kilchenmann wrote:
| Quote: | "<snip
.>>> logging._handlers.clear()
.>>> logging.root.handlers = []
.>>> for l in logging.Logger.manager.loggerDict.values():
.>>> l.handlers = []
after logging.shutdown() and before getting the new logger, your
script will probably run without errors.
|
<snip>
Hello,
Yeah, I worked that out after a bit, I solved it by keeping a
record of all the handlers and then calling flush on the handler
followed by removeHandler from the logger. It's a bit of a pain but I'd
prefer to do that rather than go poking around inside the logging
package but I will put the cleaning up of the dict on a shutdown() call
as a feature request for logging.
Thanks for the comm.
Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : benn@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Fri Jan 09, 2009 12:15 am | All times are GMT
|
|
Debt Consolidation | Loans | Debt Consolidation | Web Advertising | Buy Anything On eBay
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|