Hi, How can I log events that take place inside a TTW Python Script, and log them immediately? I have a script that converts a few hundreds of objects in a "for" loop. One of these objects causes my script to fail. I need to find out which object it is. In other words, which iteration. TTW scripts of course runs is a single transaction for Zope, and if anything fails, Zope will discard the whole transaction and not tell me which iteration the problem was in. If I put logging in the TTW script, it will not help, because the logging itself will be discarded too! Please help. -- Milos Prudek
--On Sonntag, 6. März 2005 13:00 Uhr +0100 Milos Prudek <prudek@bvx.cz> wrote:
Hi,
How can I log events that take place inside a TTW Python Script, and log them immediately?
I have a script that converts a few hundreds of objects in a "for" loop. One of these objects causes my script to fail. I need to find out which object it is. In other words, which iteration.
TTW scripts of course runs is a single transaction for Zope, and if anything fails, Zope will discard the whole transaction and not tell me which iteration the problem was in.
If I put logging in the TTW script, it will not help, because the logging itself will be discarded too!
Why should logging within a PythonScript (e.g. through zLOG) be discarded? The zLOG engine is *not* tied to transactions. -aj
Why should logging within a PythonScript (e.g. through zLOG) be discarded? The zLOG engine is *not* tied to transactions.
Thank you Andreas. Could you please post a one-line simplest example of using zLOG in a TTW Python Script ? -- Milos Prudek
--On Sonntag, 6. März 2005 13:38 Uhr +0100 Milos Prudek <prudek@bvx.cz> wrote:
Why should logging within a PythonScript (e.g. through zLOG) be discarded? The zLOG engine is *not* tied to transactions.
Thank you Andreas. Could you please post a one-line simplest example of using zLOG in a TTW Python Script ?
*wink* the zLOG API is documented :-) -> zLOG package from zLOG import lOG, INFO LOG(ident, INFO, reason) Of course you have to enable the import of the zLOG for PythonScripts. -aj
Andreas Jung wrote:
--On Sonntag, 6. März 2005 13:38 Uhr +0100 Milos Prudek <prudek@bvx.cz> wrote:
Why should logging within a PythonScript (e.g. through zLOG) be discarded? The zLOG engine is *not* tied to transactions.
Thank you Andreas. Could you please post a one-line simplest example of using zLOG in a TTW Python Script ?
*wink* the zLOG API is documented :-) -> zLOG package
from zLOG import lOG, INFO
LOG(ident, INFO, reason)
and enabling zLOG may be an adventure by itself. Try using something along this general idea. request = container.REQUEST RESPONSE = request.RESPONSE write = RESPONSE.write <...stuff...> for o in some_objects_somehwere: <...more..stuff...> write('some_cool_message_like_iter_number') it will write messages to the page as they are processed, w/o waiting for the transaction to commit or finish. Another way to do things is to create an error_log object in the containing folder and see what it logs (you may want to edit the errors it omits). Hope this helps. /dario -- -- ------------------------------------------------------------------- Dario Lopez-Kästen, IT Systems & Services Chalmers University of Tech. "...and click? damn, I need to kill -9 Word again..." - b using macosx
Dario Lopez-Kästen wrote:
and enabling zLOG may be an adventure by itself. Try using something along this general idea.
really? should just be a one-liner in Products/PythonScripts/standard.py cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
*wink* the zLOG API is documented :-) -> zLOG package
I wish these APIs were documented in Zope Book. Anyway, I just wrote an external method def logger(Text): from zLOG import LOG, ERROR LOG('Zope', ERROR,Text) and call it from TTW Python as "context.logger("some text") Cumbersome. But works. Thank you again Andreas. -- Milos Prudek _________________ Most websites are confused chintzy gaudy conflicting tacky unpleasant... unusable. Learn how usable YOUR website is! http://www.spoxdesign.com
participants (4)
-
Andreas Jung -
Chris Withers -
Dario Lopez-Kästen -
Milos Prudek