<div class="gmail_quote">On Wed, Nov 16, 2011 at 2:27 PM, Don Dwiggins <span dir="ltr"><<a href="mailto:ddwiggins@advpubtech.com">ddwiggins@advpubtech.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<u></u>
<div bgcolor="#ffffff" text="#000000">
On 11/15/2011 8:57 AM, Christopher Armstrong wrote:
<blockquote 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 href="http://twistedmatrix.com/documents/current/api/twisted.python.log.ILogObserver.html" target="_blank">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" target="_blank"><code>failure.Failure</code></a>
instance, <span>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 href="http://twistedmatrix.com/documents/current/core/howto/logging.html" target="_blank">http://twistedmatrix.com/documents/current/core/howto/logging.html</a>.<br><font color="#888888">
<br>
<br>
<div>-- <br>
<pre>Don Dwiggins
Advanced Publishing Technology
</pre>
</div>
</font></div><br></blockquote></div><br>Please open a ticket for this, so it doesn't get lost.<br><br>Thx.<br><br>Kevin Horn<br>