<html><head><base href="x-msg://391/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Mar 14, 2013, at 3:05 AM, Sergey Gerasimov wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div lang="RU" link="blue" vlink="purple"><div class="WordSection1" style="page: WordSection1; "><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">I’m implementing some project based on twisted.<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US"><o:p>&nbsp;</o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">I would like to use some logging mechanism in my modules and see both twisted generated log records and log records from my modules<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">and be able to filter log records by level and &nbsp;source (generated by twisted, or subset of my modules).<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US"><o:p>&nbsp;</o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">What should I do in this case?<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">Log with python logging module in my code and send log records generated by twisted to PythonLoggingObserver?<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">Or should I avoid using of python logging module and log only with twisted logging module? I didn’t find features like filtering logs in twisted logging.<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US"><o:p>&nbsp;</o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">Am I right that twisted based log observer uses blocking i/o? Example:<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US">observer = log.FileLogObserver(sys.stdout) # sys.stdio.write used in implementation<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span lang="EN-US"><o:p>&nbsp;</o:p></span></div></div></div></span></blockquote><br></div><div>FileLogObserver will honor a 'system' kwarg that can be used to log the source of a message, so that:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>log.msg('Important message', system='MY_MODULE')</div><div><br></div><div>yields:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>2012-11-12 18:53:55-0700&nbsp;[MY_MODULE] Important message</div><div><br></div><div><br></div><div>Arbitrary message formatting can be accomplished by suppling a `format` kwarg in place of a message:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>log.msg(format='[%(level)s] %(msg)s', level='CATASTROPHIC', msg='Important Message',&nbsp;system='MY_MODULE')</div><div><br></div><div>yields:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>2012-11-12 18:53:55-0700&nbsp;[MY_MODULE] [CATASTROPHIC] Important message</div><div><br></div><div><br></div><div>That's a bit verbose, so creating a partial wrapper is useful:</div><div><br></div><div>from functools import partial</div><div>alert = partial(log.msg, format='[%(level)s] %(msg)s', level='CATASTROPHIC', system='MY_MODULE')</div><div><br></div><div>alert(msg='Something terrible')</div><div>alert(msg='Not so bad', level='INFO') &nbsp;# override the default level</div><div><br></div><div><br></div><div>More generally, calls to log.msg() accept keyword arguments that can be inspected by any registered observer. You may want to write your own log observer and take advantage of this if you have specific filtering requirements.</div><div><br></div><div><br></div><div><br></div></body></html>