Python Plumber's Helpers
Copyright © 2001 Chris Gonnerman
chris@gonnerman.org
Usage:
These modules define some interesting file-like objects:
Logger.py: This module provides a convenient file-like object (writing only) which dates output lines automatically.
There is also a public function, logtime(), which returns the current date in the format used by the LogFile class.
Example:
import sys
from Logger import LogFile
sys.stderr = LogFile(open("example.log", "a"))
NWayOutput: This module implements a class, NWayOutput, which must be instantiated with one or more file-like objects (capable of write). The file-like objects may be given as a tuple, list, or as multiple arguments.
Assuming you have done this:
import NWayOutput
nf = NWayOutput.NWayOutput(file1, file2, file3)
any call of nf.write() calls file1.write(), file2.write(), and file3.write()
with the given arguments.
What's it good for? How about this:
import sys
from NWayOutput import NWayOutput
sys.stderr = \
NWayOutput(sys.stderr, open("logfile.txt", "w"))
As you can imagine, this is very handy combined with Logger.py.
Installation:
This package includes a Distutils-based installer. Assuming you are running Python 2.0 or higher or have installed the Distutils, you can just do this:
python setup.py install
(as root/Adminstrator if necessary) and you're done.
Alternately, just copy the included Logger.py and NWayOutput.py to your site-packages directory or somewhere else in sys.path.