niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
Logging
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Neil Benn
*nix forums beginner


Joined: 25 Apr 2005
Posts: 28

PostPosted: Wed Feb 02, 2005 10:52 am    Post subject: Logging Reply with 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 :

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

PostPosted: Wed Feb 02, 2005 11:01 am    Post subject: Re: Logging Reply with quote

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

PostPosted: Thu Feb 03, 2005 5:15 am    Post subject: Re: Logging Reply with quote

"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

PostPosted: Thu Feb 03, 2005 9:56 am    Post subject: Re: Logging Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Fri Jan 09, 2009 12:15 am | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Filtering logging, don't log monitor station Tory M Blue Postfix 1 Thu Jul 20, 2006 6:07 pm
No new posts logging control alexis Exim 0 Wed Jul 19, 2006 7:02 pm
No new posts smtp_accept_max and smtp_accept_max_per_host logging Marten Lehmann Exim 1 Tue Jul 18, 2006 7:37 pm
No new posts Database or table level logging? David Felio MySQL 5 Tue Jul 18, 2006 6:57 pm
No new posts Logging console output to external server tomec@obywatel.pl security 4 Tue Jul 18, 2006 5:34 pm

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
[ Time: 0.9924s ][ Queries: 16 (0.8916s) ][ GZIP on - Debug on ]