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

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

On Mon, Feb 1, 2016 at 3:52 PM, Louis D. Burr <ldanielburr@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... Best regards, Patryk

Hi Patryk,
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@me.com (312) 656-8387

On 2/1/16 4:45 AM, Patryk Ściborek wrote:
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

On Mon, Feb 1, 2016 at 3:52 PM, Louis D. Burr <ldanielburr@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... Best regards, Patryk

Hi Patryk,
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@me.com (312) 656-8387

On 2/1/16 4:45 AM, Patryk Ściborek wrote:
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
participants (3)
-
Louis D. Burr
-
Patryk Ściborek
-
Werner Thie