本文整理汇总了Python中twisted.python.log.startLoggingWithObserver函数的典型用法代码示例。如果您正苦于以下问题:Python startLoggingWithObserver函数的具体用法?Python startLoggingWithObserver怎么用?Python startLoggingWithObserver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startLoggingWithObserver函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 )
开发者ID:azurit,项目名称:rpclib,代码行数:7,代码来源:soap_http_static.py
示例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()
开发者ID:AmirKhooj,项目名称:VTK,代码行数:33,代码来源:workertrial.py
示例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
开发者ID:jrha,项目名称:aquilon,代码行数:34,代码来源:twisted_patches.py
示例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
开发者ID:JimmyOhn,项目名称:gst-devtools,代码行数:29,代码来源:loggable.py
示例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()
开发者ID:plq,项目名称:spyne,代码行数:26,代码来源:soap_http_static.py
示例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)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:29,代码来源:terminal.py
示例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)
开发者ID:DrDomAdmin,项目名称:kippo,代码行数:29,代码来源:ssh.py
示例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)
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:35,代码来源:output.py
示例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)
开发者ID:dNG-git,项目名称:pas_http_core,代码行数:31,代码来源:server_twisted.py
示例10: logToStdout
def logToStdout():
def observer(event):
stdout.write( formatEvent(event, includeType=True) + '\n' )
stdout.flush()
startLoggingWithObserver(observer)
开发者ID:jnewland,项目名称:graphite,代码行数:7,代码来源:log.py
示例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)
开发者ID:DxCx,项目名称:twimp,代码行数:8,代码来源:log.py
示例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()
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:8,代码来源:app.py
示例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)
开发者ID:tadeck,项目名称:twicecache,代码行数:9,代码来源:twice.py
示例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
开发者ID:Mimino666,项目名称:crawlmi,代码行数:9,代码来源:log.py
示例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()
开发者ID:radical-software,项目名称:radicalspam,代码行数:9,代码来源:app.py
示例16: set_up_logging_for_script
def set_up_logging_for_script(options, name, logfile):
"""Create a `Logger` object and configure twisted to use it.
This also configures oops reporting to use the section named
'name'."""
logger_object = logger(options, name)
observer = set_up_oops_reporting(name, name, logfile)
log.startLoggingWithObserver(observer)
return logger_object
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:9,代码来源:loggingsupport.py
示例17: start
def start(logfile=None, loglevel='INFO', logstdout=True, logencoding='utf-8', crawler=None):
loglevel = _get_log_level(loglevel)
file = open(logfile, 'a') if logfile else sys.stderr
sflo = ScrapyFileLogObserver(file, loglevel, logencoding, crawler)
_oldshowwarning = warnings.showwarning
log.startLoggingWithObserver(sflo.emit, setStdout=logstdout)
# restore warnings, wrongly silenced by Twisted
warnings.showwarning = _oldshowwarning
return sflo
开发者ID:00gpowe,项目名称:scrapy,代码行数:9,代码来源:log.py
示例18: start
def start(logfile=None, loglevel='INFO', logstdout=True, logencoding='utf-8'):
if log.defaultObserver: # check twisted log not already started
loglevel = _get_log_level(loglevel)
file = open(logfile, 'a') if logfile else sys.stderr
sflo = ScrapyFileLogObserver(file, loglevel, logencoding)
_oldshowwarning = warnings.showwarning
log.startLoggingWithObserver(sflo.emit, setStdout=logstdout)
# restore warnings, wrongly silenced by Twisted
warnings.showwarning = _oldshowwarning
开发者ID:AnthonyZhu,项目名称:scrapy,代码行数:9,代码来源:log.py
示例19: initialize
def initialize(services, tns='spyne.examples.twisted.resource'):
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
observer = log.PythonLoggingObserver('twisted')
log.startLoggingWithObserver(observer.emit, setStdout=False)
return Application(services, 'spyne.examples.twisted.hello',
in_protocol=HttpRpc(), out_protocol=HttpRpc())
开发者ID:knoxsp,项目名称:spyne,代码行数:9,代码来源:resource.py
示例20: _setUpLogFile
def _setUpLogFile(self):
self._tearDownLogFile()
if self.logfile == '-':
logFile = sys.stdout
else:
logFile = file(self.logfile, 'a')
self._logFileObject = logFile
self._logFileObserver = log.FileLogObserver(logFile)
log.startLoggingWithObserver(self._logFileObserver.emit, 0)
开发者ID:shelmesky,项目名称:twisted,代码行数:9,代码来源:runner.py
注:本文中的twisted.python.log.startLoggingWithObserver函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论