[Twisted-Python] twisted.logger and log filtering in twistd plugin

Louis D. Burr ldanielburr at me.com
Mon Feb 1 11:48:00 MST 2016


Hi Patryk,


> On Feb 1, 2016, at 11:12 AM, Patryk Ściborek <patryk at sciborek.com> wrote:
> 
> On Mon, Feb 1, 2016 at 3:52 PM, Louis D. Burr <ldanielburr at me.com <mailto:ldanielburr at me.com>> wrote:
> 
> Best bet is to look into the —logger parameter which you can use to pass a custom logger to twistd.
> 
> Hi Daniel,
> 
> Thank you for your response. Logger option sets the name of the logger factory which should create something which implements ILogObserver. But still - it's part of the legacy api (twisted.python.log). I'm wondering what's the right way to use new logging system here...
> 

You can most definitely use the new logging system with the —logger parameter.  Here is an untested example:

from twisted import logger

def myLogger():
    outFile = open('/path/to/log.txt', 'w')
    observer = logger.textFileLogObserver(outFile)
    loglevel = logger.LogLevel.levelWithName('info')
    predicate = logger.LogLevelFilterPredicate()
    predicate.setLogLevelForNamespace("", loglevel)
    filter = logger.FilteringLogObserver(observer, [predicate])

    return filter
twistd [whatever] --logger=mypackage.mymodule.myLogger

Hope this helps,

Daniel
--
L. Daniel Burr
ldanielburr at me.com
(312) 656-8387
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20160201/f3957341/attachment-0002.html>


More information about the Twisted-Python mailing list