當前位置: 首頁>>代碼示例>>Python>>正文


Python globalLogBeginner.beginLoggingTo方法代碼示例

本文整理匯總了Python中twisted.logger.globalLogBeginner.beginLoggingTo方法的典型用法代碼示例。如果您正苦於以下問題:Python globalLogBeginner.beginLoggingTo方法的具體用法?Python globalLogBeginner.beginLoggingTo怎麽用?Python globalLogBeginner.beginLoggingTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.logger.globalLogBeginner的用法示例。


在下文中一共展示了globalLogBeginner.beginLoggingTo方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init

# 需要導入模塊: from twisted.logger import globalLogBeginner [as 別名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 別名]
def init(debug=False):
    debug_enabled = debug or os.environ.get('DEBUG', False)
    logging_level = logging.DEBUG if debug_enabled else logging.INFO

    logging.basicConfig(level=logging_level,
                        format='%(asctime)s [%(name)s] %(levelname)s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        filemode='a')

    logging.getLogger('gnupg').setLevel(logging.WARN)
    logging.getLogger('gnupg').addFilter(PrivateKeyFilter())

    def formatter(event):
        try:
            event['log_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(event['log_time']))
            event['log_level'] = event['log_level'].name.upper()
            event['log_format'] = str(event['log_format']) + '\n' if event.get('log_format') else ''
            logstring = u'{log_time} [{log_namespace}] {log_level} ' + event['log_format']
            return logstring.format(**event)
        except Exception as e:
            return "Error while formatting log event: {!r}\nOriginal event: {!r}\n".format(e, event)

    observers = [FileLogObserver(sys.stdout, formatter)]
    globalLogBeginner.beginLoggingTo(observers) 
開發者ID:pixelated,項目名稱:pixelated-user-agent,代碼行數:26,代碼來源:logger.py

示例2: start_logging

# 需要導入模塊: from twisted.logger import globalLogBeginner [as 別名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 別名]
def start_logging(out=_stdout, level='info'):
    """
    Start logging to the file-like object in ``out``. By default, this
    is stdout.
    """
    global _loggers, _observer, _log_level, _started_logging

    if level not in log_levels:
        raise RuntimeError(
            "Invalid log level '{0}'; valid are: {1}".format(
                level, ', '.join(log_levels)
            )
        )

    if _started_logging:
        return

    _started_logging = True

    _log_level = level
    set_global_log_level(_log_level)

    if out:
        _observer = _LogObserver(out)

    _observers = []
    if _observer:
        _observers.append(_observer)
    globalLogBeginner.beginLoggingTo(_observers) 
開發者ID:crossbario,項目名稱:txaio,代碼行數:31,代碼來源:tx.py

示例3: init_logging

# 需要導入模塊: from twisted.logger import globalLogBeginner [as 別名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 別名]
def init_logging(configuration, program_name):
    """Given a basic configuration, set up logging."""
    logging.init_app_logging(configuration.log_dir, configuration.log_level,
                             progname=program_name,
                             quiet=configuration.quiet)
    # Initialize twisted logging, even if we don't explicitly use it,
    # because of leaky logs https://twistedmatrix.com/trac/ticket/8164
    globalLogBeginner.beginLoggingTo(
        [lambda _: None], redirectStandardIO=False, discardBuffer=True) 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:11,代碼來源:deployment.py

示例4: twlog

# 需要導入模塊: from twisted.logger import globalLogBeginner [as 別名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 別名]
def twlog():
    from sys import stdout
    from twisted.logger import globalLogBeginner
    from twisted.logger import textFileLogObserver

    globalLogBeginner.beginLoggingTo([textFileLogObserver(stdout)]) 
開發者ID:gridsync,項目名稱:gridsync,代碼行數:8,代碼來源:test_streamedlogs.py


注:本文中的twisted.logger.globalLogBeginner.beginLoggingTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。