<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 11/15/2011 8:57 AM, Christopher Armstrong wrote:
<blockquote
cite="mid:CAPkRfUSVEtez1zr9z7HHkm7J0M_ikn6ucUqDpm3S3MXRUMdJoA@mail.gmail.com"
type="cite">
<div class="gmail_quote">If you pass a 'system' kwarg to log.msg
then it will go in that field.
<div><br>
</div>
<div>log.msg("hi", system="stuff") results in <date>
[stuff] hi</div>
</div>
</blockquote>
<br>
This triggered me to look further into what LogPublisher.msg does,
since I've long wanted to customize the format of the output. I
found what I wanted in
<a class="moz-txt-link-freetext" href="http://twistedmatrix.com/documents/current/api/twisted.python.log.ILogObserver.html">http://twistedmatrix.com/documents/current/api/twisted.python.log.ILogObserver.html</a>
:<br>
<br>
In msg(), the message gets added to the kwargs dictionary (along
with a timestamp called 'time'), and that dict is passed to
LogObserver.emit, which uses textFromEventDict() to create what's
actually output. This dictionary has the following keys recognized
by textFromEventDict:<br>
<ul>
<li> <code>message</code>: A <code>tuple</code> of <code>str</code>
containing messages to be logged. </li>
<li> <code>system</code>: A <code>str</code> which indicates the
"system" which is generating this event. </li>
<li> <code>isError</code>: A <code>bool</code> indicating
whether this event represents an error. </li>
<li> <code>failure</code>: A <a
href="http://twistedmatrix.com/documents/current/api/twisted.python.failure.Failure.html"><code>failure.Failure</code></a>
instance, <span class="sd">required if the event is an error.</span>
</li>
<li> <code>why</code>: Used as header of the traceback in case of
errors. </li>
<li> <code>format</code>: A string format used in place of <code>message</code>
to customize the event. The intent is for the observer to format
a message by doing something like <code>format % eventDict</code>.
</li>
</ul>
So, for example, you could do log.msg(format='....', foo='stuff',
bar='things')<br>
<br>
I suggest that this be added to the documentation string of the
msg() method and
<a class="moz-txt-link-freetext" href="http://twistedmatrix.com/documents/current/core/howto/logging.html">http://twistedmatrix.com/documents/current/core/howto/logging.html</a>.<br>
<br>
<br>
<div class="moz-signature">-- <br>
<pre>Don Dwiggins
Advanced Publishing Technology
</pre>
</div>
</body>
</html>