本文整理汇总了Python中twisted.python.log.startLoggingWithObserver函数的典型用法代码示例。如果您正苦于以下问题:Python startLoggingWithObserver函数的具体用法?Python startLoggingWithObserver怎么用?Python startLoggingWithObserver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startLoggingWithObserver函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv):
observer = log.PythonLoggingObserver('twisted')
log.startLoggingWithObserver(observer.emit, setStdout=False)
wsgi_application = WsgiApplication(soap_application)
return run_twisted( [ (wsgi_application, url) ], port )
示例2: main
def main():
"""
Main function to be run if __name__ == "__main__".
"""
config = WorkerOptions()
config.parseOptions()
from twisted.trial._dist.worker import WorkerProtocol
workerProtocol = WorkerProtocol(config['force-gc'])
protocolIn = os.fdopen(_WORKER_AMP_STDIN)
protocolOut = os.fdopen(_WORKER_AMP_STDOUT, 'w')
workerProtocol.makeConnection(FileWrapper(protocolOut))
observer = WorkerLogObserver(workerProtocol)
startLoggingWithObserver(observer.emit, False)
while True:
try:
r = protocolIn.read(1)
except IOError, e:
if e.args[0] == errno.EINTR:
sys.exc_clear()
continue
else:
raise
if r == '':
break
else:
workerProtocol.dataReceived(r)
protocolOut.flush()
sys.stdout.flush()
sys.stderr.flush()
示例3: set_log_file
def set_log_file(logFile, setStdout=True, start=True):
"""Set up twisted log files in a standard way.
This borrows functionality from the twisted.application.app
AppLogger.start() method, which in turn uses the
twisted.scripts._twistd_unix.UnixAppLogger._getLogObserver method.
That method returns a FileLog that is hard-coded to set a log
rotation of 1 MB. While we're here anyway, overriding that as well
to remove the rotation size. We rotate logs with an external
logrotate command that sends SIGUSR1 to tell the broker to reopen
the log file.
"""
log_file = logfile.LogFile.fromFullPath(logFile, rotateLength=0)
observer = log.FileLogObserver(log_file).emit
try:
import signal
except ImportError:
pass
else:
# Override if signal is set to None or SIG_DFL (0)
if not signal.getsignal(signal.SIGUSR1):
def restartLog(signal, frame):
log_file.flush()
try:
log_file.close()
except:
pass
log_file._openFile()
signal.signal(signal.SIGUSR1, restartLog)
if start:
log.startLoggingWithObserver(observer, setStdout=setStdout)
return observer
示例4: logTwisted
def logTwisted():
"""
Integrate twisted's logger with our logger.
This is done in a separate method because calling this imports and sets
up a reactor. Since we want basic logging working before choosing a
reactor, we need to separate these.
"""
global _initializedTwisted
if _initializedTwisted:
return
debug('log', 'Integrating twisted logger')
# integrate twisted's logging with us
from twisted.python import log as tlog
# this call imports the reactor
# that is why we do this in a separate method
from twisted.spread import pb
# we don't want logs for pb.Error types since they
# are specifically raised to be handled on the other side
observer = _getTheTwistedLogObserver()
observer.ignoreErrors([pb.Error, ])
tlog.startLoggingWithObserver(observer.emit, False)
_initializedTwisted = True
示例5: main
def main(argv):
from twisted.python import log
from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor
from twisted.python import log
observer = log.PythonLoggingObserver('twisted')
log.startLoggingWithObserver(observer.emit, setStdout=False)
static_dir = os.path.abspath('.')
logging.info("registering static folder %r on /" % static_dir)
root = File(static_dir)
wr = TwistedWebResource(soap11_application)
logging.info("registering %r on /%s" % (wr, url))
root.putChild(url, wr)
site = Site(root)
if port[0] == 0:
port[0] = get_open_port()
reactor.listenTCP(port[0], site)
logging.info("listening on: %s:%d" % (host,port))
return reactor.run()
示例6: connectionMade
def connectionMade(self):
ReceiveLineProtocol.connectionMade(self)
self.keyHandlers['\x03'] = self.handle_INT # Control-C
self.keyHandlers['\x04'] = self.handle_EOF # Control-D
self.keyHandlers['\x1c'] = self.handle_QUIT # Control-\
self.keyHandlers['\x0c'] = self.handle_FF # Control-L
#self.keyHandlers['\t' ] = self.handle_TAB # Tab
if self.emulate == "emacs":
# EMACS key bindinds
self.keyHandlers['\x10'] = self.handle_UP # Control-P
self.keyHandlers['\x0e'] = self.handle_DOWN # Control-N
self.keyHandlers['\x02'] = self.handle_LEFT # Control-B
self.keyHandlers['\x06'] = self.handle_RIGHT # Control-F
self.keyHandlers['\x01'] = self.handle_HOME # Control-A
self.keyHandlers['\x05'] = self.handle_END # Control-E
def observer(event):
if not event["isError"]:
return
text = log.textFromEventDict(event)
if text is None:
return
self.service.reactor.callFromThread(self.terminal.write, text)
log.startLoggingWithObserver(observer)
示例7: __init__
def __init__(self):
cfg = config()
# protocol^Wwhatever instances are kept here for the interact feature
self.sessions = {}
# for use by the uptime command
self.starttime = time.time()
# load db loggers
self.dbloggers = []
for x in cfg.sections():
if not x.startswith('database_'):
continue
engine = x.split('_')[1]
dbengine = 'database_' + engine
lcfg = ConfigParser.ConfigParser()
lcfg.add_section(dbengine)
for i in cfg.options(x):
lcfg.set(dbengine, i, cfg.get(x, i))
lcfg.add_section('honeypot')
for i in cfg.options('honeypot'):
lcfg.set('honeypot', i, cfg.get('honeypot', i))
print 'Loading dblog engine: %s' % (engine,)
dblogger = __import__(
'kippo.dblog.%s' % (engine,),
globals(), locals(), ['dblog']).DBLogger(lcfg)
log.startLoggingWithObserver(dblogger.emit, setStdout=False)
self.dbloggers.append(dblogger)
示例8: startLogging
def startLogging(self, filePath=None, stealStdio=False, printToConsole=True):
'''
Begin logging. The output class is ready to go out of the box, but in order
to prevent mere imports from stealing stdio or console logging to vanish
these must be manually turned on.
:param filePath: if provided, begin logging to the given directory. If
not provided, do not write out logs.
:type filePath: str
:param stealStdio: choose to intercept stdio (including vanilla print
statements) or allow it to passthrough
:type stealStdio: bool.
:param printToConsole: output the results of all logging to the console. This
is primarily a performance consideration when running in production
:type printToConsole: bool.
'''
# Initialize printer thread
self.__dict__['logpath'] = None
if filePath is not None:
self.__dict__['queue'] = queue.Queue()
self.__dict__['printer'] = PrintLogThread(filePath, self.queue, LOG_NAME)
self.__dict__['logpath'] = filePath
self.printer.start()
# by default, stdio gets captures. This can be toggled off
self.stealStdio(stealStdio)
self.logToConsole(printToConsole)
# Override twisted logging (allows us to cleanly catch all exceptions)
# This must come after the setattr calls so we get the wrapped object
log.startLoggingWithObserver(self.twisted, setStdout=False)
log.startLoggingWithObserver(self.twistedErr, setStdout=False)
示例9: __init__
def __init__(self):
"""
Constructor __init__(ServerTwisted)
:since: v1.0.0
"""
AbstractServer.__init__(self)
self.log_observer = None
"""
@TODO
"""
self.reactor = None
"""
Twisted reactor instance
"""
self.thread_pool = None
"""
@TODO
"""
log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
if (log_handler is not None):
log_handler.add_logger("twisted")
self.log_observer = log.PythonLoggingObserver("twisted")
self.log_observer.start()
log.startLoggingWithObserver(self.log_observer.emit, setStdout = False)
示例10: logToStdout
def logToStdout():
def observer(event):
stdout.write( formatEvent(event, includeType=True) + '\n' )
stdout.flush()
startLoggingWithObserver(observer)
示例11: hook_twisted
def hook_twisted(levels=None, redirect_stdout=0):
_ensure_main_logger()
if levels:
set_levels(levels)
from twisted.python import log
plo = log.PythonLoggingObserver(TWISTED_CATEGORY)
log.startLoggingWithObserver(plo.emit, setStdout=redirect_stdout)
示例12: startLogging
def startLogging(self, observer):
"""
Initialize the logging system. DEPRECATED.
@param observer: The observer to add to the logging system.
"""
log.startLoggingWithObserver(observer)
self.logger._initialLog()
示例13: setup_log
def setup_log(self, name):
try:
self.log_file = open(name, 'a')
self.log_observer = log.FileLogObserver(self.log_file)
log.startLoggingWithObserver(self.log_observer.emit)
except:
msg = "Error in setup_log:\n%s" % traceback.format_exc()
print msg
mail.error(msg)
示例14: start
def start(logfile=None, loglevel='INFO', logstdout=True, encoding='utf-8'):
loglevel = _get_log_level(loglevel)
file = open(logfile, 'ab') if logfile else sys.stderr
observer = CrawlmiFileLogObserver(file, loglevel, encoding)
_oldshowwarning = warnings.showwarning
log.startLoggingWithObserver(observer.emit, setStdout=logstdout)
# restore warnings, wrongly silenced by Twisted
warnings.showwarning = _oldshowwarning
return observer
示例15: startLogging
def startLogging(self, observer):
"""
Initialize the logging system.
@param observer: The observer to add to the logging system.
"""
log.startLoggingWithObserver(observer)
sys.stdout.flush()
initialLog()