[albatross-users] Logging from Albatross applications
Ben Golding
bgg at object-craft.com.au
Mon Mar 4 19:09:00 EST 2002
On Monday, March 4, 2002, at 06:46 , Dave Cole wrote:
>>>>>> "Tim" == Tim Churches <tchur at optushome.com.au> writes:
>
> Tim> One thing which almost every application requires is
> Tim> logging. Would it be possible to add some hooks into Albatross so
> Tim> that a logging class is called automatically at given points in
> Tim> teh processing?
>
> I will let Ben reply to this - he has been doing some stuff in that
> area.
I found myself getting frustrated with wanting to log and not having
a simple way of doing that. What I ended up doing was writing a little
LogMixin that looks like:
class LogMixin:
def log(self, s):
sys.stderr.write('%s\n' % s)
sys.stderr.flush()
In my AppContext, I declared it as:
class AppContext(SimpleAppContext, logMixin.LogMixin):
...
self.log('AppContext.get_mailbox: self.locals %s' %
dir(self.locals))
which I thought was great. Apache logs stderr to ite error_log on unix
but by
just changing that single mixin, you could make errors go elsewhere (say,
syslog instead) or handle them completely different (eg, if you were
using
Windows).
I was also able to add the mixin to my own classes and log from them
using
self.log() as well. That meant that all logging went to the same place
and
had the same format.
There's also the possibility of subclassing the mixin to change the
output
to (say) including a timestamp, pid, or something.
I've suggested to Dave that he add a LogMixin class to Albatross because
other, lesser people do have to do debugging from time to time.
Providing
a standard mechanism for that could be a real advantage. If he adds it,
the
names and functionality might change but this should get you going.
Ben.
More information about the Albatross-users
mailing list