Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

python - Twisted starting/stopping factory/protocol less noisy log messages

Is there a way to tell to twistd to not log all factory and protocol start and stop. I use many type of protocols and performs a lot of connections ... and my log file grows a lot. So i'm looking for a simple way to disable those messages.

Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can set the noisy attribute of a factory to False to prevent it from logging these messages. See also http://twistedmatrix.com/trac/ticket/4021 which will probably be resolved by the next Twisted release.

For example, here's a program with two clients, but only one will log its start/stop messages:

import sys

from twisted.internet import reactor, protocol
from twisted.python import log

log.startLogging(sys.stdout)

f = protocol.ClientFactory()
f.protocol = protocol.Protocol
reactor.connectTCP('localhost', 22, f)

g = protocol.ClientFactory()
g.noisy = False
g.protocol = protocol.Protocol
reactor.connectTCP('localhost', 25, g)

reactor.run()

And the output:

2011-02-22 09:43:23-0500 [-] Log opened.
2011-02-22 09:43:23-0500 [-] Starting factory <twisted.internet.protocol.ClientFactory instance at 0x8f422cc>
^C
2011-02-22 09:43:26-0500 [-] Received SIGINT, shutting down.
2011-02-22 09:43:26-0500 [Protocol,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x8f422cc>
2011-02-22 09:43:26-0500 [-] Main loop terminated.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...