本文整理汇总了Python中twisted.internet.protocol.ServerFactory.extra_loggers方法的典型用法代码示例。如果您正苦于以下问题:Python ServerFactory.extra_loggers方法的具体用法?Python ServerFactory.extra_loggers怎么用?Python ServerFactory.extra_loggers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.ServerFactory
的用法示例。
在下文中一共展示了ServerFactory.extra_loggers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from twisted.internet.protocol import ServerFactory [as 别名]
# 或者: from twisted.internet.protocol.ServerFactory import extra_loggers [as 别名]
def start(root_node, auth_backend=None, port=8023, logfile=None, extra_loggers=None):
"""
Start telnet server
"""
# Set logging
if logfile:
logging.basicConfig(filename=logfile, level=logging.DEBUG)
else:
logging.basicConfig(filename='/dev/stdout', level=logging.DEBUG)
# Thread sensitive interface for stdout/stdin
std.setup()
# Telnet
factory = ServerFactory()
factory.connectionPool = set() # List of currently, active connections
factory.protocol = lambda: TelnetTransport(TelnetDeployer)
factory.root_node = root_node()
factory.auth_backend = auth_backend
factory.extra_loggers = extra_loggers or []
# Handle signals
def handle_sigint(signal, frame):
if factory.connectionPool:
logging.info('Running, %i active session(s).' % len(factory.connectionPool))
else:
logging.info('No active sessions, exiting')
reactor.stop()
signal.signal(signal.SIGINT, handle_sigint)
# Run the reactor!
logging.info('Listening for incoming telnet connections on localhost:%s...' % port)
# Set process name
suffix = (' --log "%s"' % logfile if logfile else '')
setproctitle('deploy:%s telnet-server --port %i%s' %
(root_node.__class__.__name__, port, suffix))
# Run server
reactor.listenTCP(port, factory)
reactor.run()