Write log file from script
I am looking for a simple strategy to write a debug log file from a python script. I used to have such a beast but somewhere in a shuffle it got lost -- and my brain seems to be dead this morning trying to figure it out. Anybody out there have something like this or a url explaining how to do it?
How about creating a string or list, then appending your debug info to the string/list, then returning the string/list to the calling routine which then displays the string/list? Jonathan ----- Original Message ----- From: Brian Sullivan To: zope@zope.org Sent: Friday, October 07, 2005 11:42 AM Subject: [Zope] Write log file from script I am looking for a simple strategy to write a debug log file from a python script. I used to have such a beast but somewhere in a shuffle it got lost -- and my brain seems to be dead this morning trying to figure it out. Anybody out there have something like this or a url explaining how to do it? ------------------------------------------------------------------------------ _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Depends upon what you want to do and how much access you have. For debugging purposes I often use an external procedure def debugWindow( data ): fd = open('/tmp/debugWindow",'a') fd.write( str(data)) fd.close() and look at the output with tail -f /tmp/debugWindow Or, you can use the same approach to write to syslog using the Python logging module Or you can piggyback into the Zope logging mechanism--see the sources for that exercise. I find the external procedure approach to be useful in its simplicity On Fri, 7 Oct 2005, Brian Sullivan wrote:
I am looking for a simple strategy to write a debug log file from a python script. I used to have such a beast but somewhere in a shuffle it got lost -- and my brain seems to be dead this morning trying to figure it out. Anybody out there have something like this or a url explaining how to do it?
On 10/7/05, Dennis Allison <allison@shasta.stanford.edu> wrote:
Depends upon what you want to do and how much access you have. For debugging purposes I often use an external procedure
def debugWindow( data ): fd = open('/tmp/debugWindow",'a') fd.write( str(data)) fd.close()
and look at the output with
tail -f /tmp/debugWindow
Or, you can use the same approach to write to syslog using the Python logging module
Or you can piggyback into the Zope logging mechanism--see the sources for that exercise.
I find the external procedure approach to be useful in its simplicity
OK -- thanks to those that replied (many with a similar solution). I do have access to the server (Win2000 in my case) so I can pretty well do anything I want. It comes back now -- I did something like that but then called it through a gateway Python script that allowed me to turn off all logging in one spot easily (by modifying the script) in case I wanted to leave the debug statements there temporarily and not incur the expense of a huge log file.
Am Freitag, den 07.10.2005, 09:03 -0700 schrieb Dennis Allison:
Depends upon what you want to do and how much access you have. For debugging purposes I often use an external procedure
def debugWindow( data ): fd = open('/tmp/debugWindow",'a') fd.write( str(data)) fd.close()
Actually this is a bit dangerous if you dont lock the file. import zLOG def log(self,message): zLOG.LOG("PythonScript", zLOG.INFO, message) as external method should be enough.
On 10/7/05, Tino Wildenhain <tino@wildenhain.de> wrote:
Am Freitag, den 07.10.2005, 09:03 -0700 schrieb Dennis Allison:
Depends upon what you want to do and how much access you have. For debugging purposes I often use an external procedure
def debugWindow( data ): fd = open('/tmp/debugWindow",'a') fd.write( str(data)) fd.close()
Actually this is a bit dangerous if you dont lock the file.
import zLOG
def log(self,message): zLOG.LOG("PythonScript", zLOG.INFO <http://zLOG.INFO>, message)
as external method should be enough.
And where does this log information end up?
We are running on a linux host. The file information ends upon in the local file system in the /tmp directory. On Fri, 7 Oct 2005, Brian Sullivan wrote:
On 10/7/05, Tino Wildenhain <tino@wildenhain.de> wrote:
Am Freitag, den 07.10.2005, 09:03 -0700 schrieb Dennis Allison:
Depends upon what you want to do and how much access you have. For debugging purposes I often use an external procedure
def debugWindow( data ): fd = open('/tmp/debugWindow",'a') fd.write( str(data)) fd.close()
Actually this is a bit dangerous if you dont lock the file.
import zLOG
def log(self,message): zLOG.LOG("PythonScript", zLOG.INFO <http://zLOG.INFO>, message)
as external method should be enough.
And where does this log information end up?
--
On 10/7/05, Dennis Allison <allison@shasta.stanford.edu> wrote:
We are running on a linux host. The file information ends upon in the local file system in the /tmp directory.
import zLOG
def log(self,message): zLOG.LOG("PythonScript", zLOG.INFO <http://zLOG.INFO> < http://zLOG.INFO>, message)
as external method should be enough.
And where does this log information end up?
--
I was referring to the zLOG info. Where does it go?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Brian Sullivan wrote:
On 10/7/05, Dennis Allison <allison@shasta.stanford.edu> wrote:
We are running on a linux host. The file information ends upon in the local file system in the /tmp directory.
import zLOG
def log(self,message): zLOG.LOG("PythonScript", zLOG.INFO <http://zLOG.INFO> <
http://zLOG.INFO>, message)
as external method should be enough.
And where does this log information end up?
--
I was referring to the zLOG info. Where does it go?
Wherever you configure it in your zope.conf file. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDRsCB+gerLs4ltQ4RAmfIAJwKY6LD41TCJpTV0SVChnuOMSCraQCfaA9c +S0/kddAoFQeYvYrOIa3kJk= =bzfo -----END PGP SIGNATURE-----
as external method should be enough.
And where does this log information end up?
--
I was referring to the zLOG info. Where does it go?
Wherever you configure it in your zope.conf file.
-
OK -- that is useful information. I didn't understand how this worked -- I will have a look at the config file.
On Fri, Oct 07, 2005 at 11:42:16AM -0400, Brian Sullivan wrote:
I am looking for a simple strategy to write a debug log file from a python script. I used to have such a beast but somewhere in a shuffle it got lost -- and my brain seems to be dead this morning trying to figure it out. Anybody out there have something like this or a url explaining how to do it?
Why not zLOG? Look at: Zope-2.8.1-home/lib/python/zLOG/__init__.py There are lots of examples of the use of the LOG function, defined in that file, scattered throughout the Zope code. And, your_instance/etc/zope.conf enables you to control the logging output. Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman
Dave Kuhlman wrote:
Why not zLOG? Look at:
Zope-2.8.1-home/lib/python/zLOG/__init__.py
Well, zLOG is hopefully going away some time soon ;-) You should really be using the python logging module, for which zLOG is now just a facade: import logging logger = logging.getLogger('event.whatever') logger.info('Argh! Help, the world with end in %i seconds',end_of_time) I'm just writing a proposal to make this available in untrusted code such as Script (Python)'s, but in the meantime, you can use an external method: import logging logger = logging.getLogger('event.myapplogger') def log(self,level,message,*args,exc_info=False): logger.log(getattr(logging,level), message, *args, exc_info = exc_info cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Brian Sullivan wrote at 2005-10-7 11:42 -0400:
I am looking for a simple strategy to write a debug log file from a python script.
In an External Method (trusted code), you can write files as usual in Python. An elementary log function could be: def log(msg): open(LOGFILE, "a").write(msg) You cannot use "open" in untrusted code (for obvious reasons). -- Dieter
participants (8)
-
Brian Sullivan -
Chris Withers -
Dave Kuhlman -
Dennis Allison -
Dieter Maurer -
Jonathan -
Tino Wildenhain -
Tres Seaver