Discussion:
[Twisted-Python] twisted.logger and log filtering in twistd plugin
Patryk Ściborek
2016-02-01 14:45:40 UTC
Permalink
Hi Guys!

I'm using twisted.logger in my new app. I'm running it as a twistd plugin
and I don't know how to enable log message filtering. I know that twistd
still uses twisted.python.log but I have to disable debug messages somehow.
What's the best way to do that in my ServiceMaker?

Best regards,
Patryk
Louis D. Burr
2016-02-01 14:52:38 UTC
Permalink
Hi Patryk,
Post by Patryk Ściborek
Hi Guys!
I'm using twisted.logger in my new app. I'm running it as a twistd plugin and I don't know how to enable log message filtering. I know that twistd still uses twisted.python.log but I have to disable debug messages somehow. What's the best way to do that in my ServiceMaker?
Best regards,
Patryk
Best bet is to look into the —logger parameter which you can use to pass a custom logger to twistd.

Hope this helps,

Daniel
--
L. Daniel Burr
***@me.com
(312) 656-8387
Patryk Ściborek
2016-02-01 17:12:30 UTC
Permalink
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...

Best regards,
Patryk
Louis D. Burr
2016-02-01 18:48:00 UTC
Permalink
Hi Patryk,
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
***@me.com
(312) 656-8387

Werner Thie
2016-02-01 17:20:54 UTC
Permalink
Post by Patryk Ściborek
Hi Guys!
I'm using twisted.logger in my new app. I'm running it as a twistd
plugin and I don't know how to enable log message filtering. I know that
twistd still uses twisted.python.log but I have to disable debug
messages somehow. What's the best way to do that in my ServiceMaker?
Best regards,
Patryk
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Hello Patryk

That's what I'm using in my .tac files:

from twisted.python import log
from twisted.python.log import ILogObserver, FileLogObserver

:
service = service.Application(myPackage)
service.setComponent(ILogObserver, FileLogObserver(LogFile('myLog.log',
'/var/log', rotateLength=10000)).emit)

Hope this helps, Werner
Loading...