Python twisted.python.log.startLoggingWithObserver() Examples
The following are 14
code examples of twisted.python.log.startLoggingWithObserver().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.python.log
, or try the search function
.
Example #1
Source File: app.py From python-for-android with Apache License 2.0 | 6 votes |
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()
Example #2
Source File: _twisted.py From maas with GNU Affero General Public License v3.0 | 6 votes |
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) )
Example #3
Source File: cli.py From carml with The Unlicense | 6 votes |
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)
Example #4
Source File: output.py From Paradrop with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: runner.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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)
Example #6
Source File: syslog.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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)
Example #7
Source File: runner.py From learn_python3_spider with MIT License | 5 votes |
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)
Example #8
Source File: syslog.py From learn_python3_spider with MIT License | 5 votes |
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)
Example #9
Source File: runner.py From python-for-android with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: syslog.py From python-for-android with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: twisted_logger.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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))
Example #12
Source File: twisted_logger.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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))
Example #13
Source File: runner.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: cli.py From carml with The Unlicense | 5 votes |
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