Need help tracing my application errors.
Greetings. I have a problem with an application we have hosted in Zope, and I thought you could give me a hand. Basically, my question is: what's the easiest way to trace errors raised by a python script that's part of the application? This is the exact situation: I have to modify such application. It is a very big application, with a lot of python scripts, sql methods, etc... After testing it for the first time after the modification, nothing happens. By this I mean there is no error message, yet I know the application doesn't work right, since no data were inserted into the database. If it was an application developed in some other language, I'd just print messages on the screen to carry on with the debugging, and be able to know where the application is going. But this doesn't work with Zope. I just can't write "print 'some message'", because nothing gets written on the screen... I have tried with the Error_log object, but since the python script doesn't raise exceptions, no exceptions is captured by such object. I'm out of ideas here. What I basically want is some way of printing stuff somewhere, maybe a file, or the screen itself, to know where the application is in every moment. That way, locating the error would be far easier. Please, any help with this will be highly appreciated. Thank you very much in advance.
--On 7. September 2006 21:05:31 +0200 Jose Carlos Balderas Alberico <josecarlos.balderas@gmail.com> wrote:
I'm out of ideas here. What I basically want is some way of printing stuff somewhere, maybe a file, or the screen itself, to know where the application is in every moment. That way, locating the error would be far easier.
What's wrong with using the standard Python logging module? Likely you need to use allow_module('logging'). See lib/python/Products/PythonScripts/README.txt for details. You can also write an external method that performs logging through any kind of logger you might have available in Python and call this external method from anywhere in Zope since ExternalMethods are first-class Zope objects and can be acquired through standard acquisition. For more information on Python's logging module: Read The Fine Manual (Python library reference). -aj
You can also write an external method that performs logging through any kind of logger you might have available in Python and call this external method from anywhere in Zope since ExternalMethods are first-class Zope objects and can be acquired through standard acquisition.
The simple and effective logger for this situation may be external method defined as: def print_this(text): print text Start zope with runzope script and as Anderas said call your external method from anywhere in Zope . You'll see your printed statements in the console. -- Maciej Wisniowski
Also in case you really want to get into the python debugger from a script, try this: Install zdb, http://www.simplistix.co.uk/software/zope/zdb Add the following line to the script: from zdb import set_trace; set_trace() Stop zope. Restart zope in the foreground. Either of these commands will do that: ./bin/zopectl fg or ./bin/runzope Now when the script runs, you'll get a pdb prompt in the terminal where you ran zope. It'll take a little practice to learn to find your way around. At first you'll likely spend some time blindly stepping through the deep guts of Zope... -- Paul Winkler http://www.slinkp.com
Jose Carlos Balderas Alberico wrote:
Greetings.
I have a problem with an application we have hosted in Zope, and I thought you could give me a hand. Basically, my question is: what's the easiest way to trace errors raised by a python script that's part of the application?
This is the exact situation: I have to modify such application. It is a very big application, with a lot of python scripts, sql methods, etc... After testing it for the first time after the modification, nothing happens. By this I mean there is no error message, yet I know the application doesn't work right, since no data were inserted into the database.
Jose, Sounds like you walked into a real beauty. But your statement: "by this I mean there is no error message, yet I know the application doesnt work right, since no data were inserted into the database" sounds more like a programming error and its unclear how "logging" will solve it (although anything is a start). Could you give us a code fragments of the relevant parts? a) the code fragment that calls zsql (assuming thats what is being called) b) a print out of the "request" (just before the zsql is called unless you pass zsql params directly) c) your zsql that is not adding records You might as well also add your OS version and type, Zope version and which data adapter you are using. ps: if any of your methods are *external* then changes will not show up in some cases (debugging on/off?) unless you update its external python "link" as well. David
Thank you everyone for your help. David, right now I can't give you any code of the application, since I'm at home, and I have nothing here. Tomorrow at work I'll give you more details about the error. Andreas, thank you for telling me about the Python logging module. I had never debugged a Zope application before, so this is all new for me. I will read the documentation on that module, and see if I can solve my problem. I'll keep you updated on my improvements. Once again, thank you all :)
participants (5)
-
Andreas Jung -
David H -
Jose Carlos Balderas Alberico -
Maciej Wisniowski -
Paul Winkler