本文整理匯總了Python中twisted.python.log.startLoggingWithObserver方法的典型用法代碼示例。如果您正苦於以下問題:Python log.startLoggingWithObserver方法的具體用法?Python log.startLoggingWithObserver怎麽用?Python log.startLoggingWithObserver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.python.log
的用法示例。
在下文中一共展示了log.startLoggingWithObserver方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: start
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
def start(self, application):
"""
Initialize the logging system.
If an L{ILogObserver} component has been set on C{application}, then
it will be used as the log observer. Otherwise a log observer will be
created based on the command-line options.
@param application: The application on which to check for an
L{ILogObserver}.
"""
observer = application.getComponent(ILogObserver, None)
if observer is None:
observer = self._getLogObserver()
self._observer = observer
log.startLoggingWithObserver(self._observer)
self._initialLog()
示例2: _startLoggingWithObserver
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
def _startLoggingWithObserver(observer, setStdout=1):
"""Replacement for `t.p.log.startLoggingWithObserver`.
When `twistd` starts in 16.0 it initialises the legacy logging system.
Intercept this to DTRT with either a modern or legacy observer.
In Xenial (with Twisted 16.0) `observer` is probably a legacy observer,
like twisted.python.log.FileLogObserver, but we should check if it's
modern. In either case we should call through to the `globalLogBeginner`
ourselves. In Yakkety (with Twisted 16.4) this function will not be
called; `t.application.app.AppLogger` does the right thing already.
"""
if not twistedModern.ILogObserver.providedBy(observer):
observer = twistedModern.LegacyLogObserverWrapper(observer)
twistedModern.globalLogBeginner.beginLoggingTo(
[observer], discardBuffer=False, redirectStandardIO=bool(setStdout)
)
示例3: carml
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
def carml(ctx, timestamps, no_color, info, quiet, debug, debug_protocol, password, connect, color, json):
if (color == 'always' and no_color) or \
(color == 'no' and no_color is True):
raise click.UsageError(
"--no-color={} but --color={}".format(no_color, color)
)
cfg = Config()
ctx.obj = cfg
cfg.timestamps = timestamps
cfg.no_color = no_color
cfg.info = info
cfg.quiet = quiet
cfg.debug = debug
cfg.password = password
cfg.connect = connect
cfg.color = color
cfg.debug_protocol = debug_protocol
cfg.json = True if json else False
# start logging
_log_observer = LogObserver()
log.startLoggingWithObserver(_log_observer, setStdout=False)
示例4: startLogging
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
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)
示例5: _setUpLogFile
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
def _setUpLogFile(self):
self._tearDownLogFile()
if self.logfile == '-':
logFile = sys.stdout
else:
logFile = open(self.logfile, 'a')
self._logFileObject = logFile
self._logFileObserver = log.FileLogObserver(logFile)
log.startLoggingWithObserver(self._logFileObserver.emit, 0)
示例6: startLogging
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
def startLogging(prefix='Twisted', options=DEFAULT_OPTIONS,
facility=DEFAULT_FACILITY, setStdout=1):
"""
Send all Twisted logging output to syslog from now on.
The prefix, options and facility arguments are passed to
C{syslog.openlog()}, see the Python syslog documentation for details. For
other parameters, see L{twisted.python.log.startLoggingWithObserver}.
"""
obs = SyslogObserver(prefix, options, facility)
log.startLoggingWithObserver(obs.emit, setStdout=setStdout)
示例7: _setUpLogFile
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
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)
示例8: start
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
def start(error_log_level = logging.ERROR,
info_log_level = logging.INFO ):
"""Writes twisted output to a logger using 'twisted' as the
logger name (i.e., 'twisted' is passed as name arg to logging.getLogger(name)).
"""
o = LogLogObserver(error_log_level, info_log_level)
# We do not use twisted setStdout logging because it is not clear to me
# how to differentiate twisted-generated log entries and
# redirected output. It is possible that all stdout and stderr
# output has system '-', but from looking at twisted source code
# there does not appear to be any guarantee that this is the case.
# A simpler way of handling this is to simply separate
# stdio and stderr redirection from twisted logging. --Dave
log.startLoggingWithObserver(o.emit , setStdout = 0) #setStdout=int(capture_output))
示例9: __init__
# 需要導入模塊: from twisted.python import log [as 別名]
# 或者: from twisted.python.log import startLoggingWithObserver [as 別名]
def __init__(self, timestamp=False, flush=True):
self.timestamp = timestamp
self.flush = flush
# we keep our own copies of these, because Twisted's
# startLoggingWithObserver overwrites them with its own
# monitoring machinery
self.stdout = sys.stdout
self.stderr = sys.stderr