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


Python logging.getLogRecordFactory方法代碼示例

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


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

示例1: setUp

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import getLogRecordFactory [as 別名]
def setUp(self):
        class CheckingFilter(logging.Filter):
            def __init__(self, cls):
                self.cls = cls

            def filter(self, record):
                t = type(record)
                if t is not self.cls:
                    msg = 'Unexpected LogRecord type %s, expected %s' % (t,
                            self.cls)
                    raise TypeError(msg)
                return True

        BaseTest.setUp(self)
        self.filter = CheckingFilter(DerivedLogRecord)
        self.root_logger.addFilter(self.filter)
        self.orig_factory = logging.getLogRecordFactory() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:test_logging.py

示例2: setup_logging

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import getLogRecordFactory [as 別名]
def setup_logging(app, logfile, debug=True):
    old_factory = logging.getLogRecordFactory()

    def spell_record_factory(*args, **kwargs):
        record = old_factory(*args, **kwargs)
        if record.name != 'conjure-up':
            record.filename = '{}: {}'.format(record.name, record.filename)
        spell_name = app.config.get('spell', consts.UNSPECIFIED_SPELL)
        record.name = 'conjure-up/{}'.format(spell_name)
        return record

    logging.setLogRecordFactory(spell_record_factory)

    cmdslog = TimedRotatingFileHandler(logfile,
                                       when='D',
                                       interval=1,
                                       backupCount=7)
    cmdslog.setFormatter(logging.Formatter(
        "%(asctime)s [%(levelname)s] %(name)s - "
        "%(filename)s:%(lineno)d - %(message)s"))

    root_logger = logging.getLogger()
    app_logger = logging.getLogger('conjure-up')

    if debug:
        app_logger.setLevel(logging.DEBUG)
        root_logger.setLevel(logging.DEBUG)
    else:
        # always use DEBUG level for app, for now
        app_logger.setLevel(logging.DEBUG)
        root_logger.setLevel(logging.INFO)

    root_logger.addHandler(cmdslog)
    if os.path.exists('/dev/log'):
        st_mode = os.stat('/dev/log').st_mode
        if stat.S_ISSOCK(st_mode):
            syslog_h = SysLogHandler(address='/dev/log')
            syslog_h.set_name('conjure-up')
            app_logger.addHandler(syslog_h)

    return app_logger 
開發者ID:conjure-up,項目名稱:conjure-up,代碼行數:43,代碼來源:log.py

示例3: test_automatic_log_record_factory_install

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import getLogRecordFactory [as 別名]
def test_automatic_log_record_factory_install(elasticapm_client):
    """
    Use the elasticapm_client fixture to load the client, which in turn installs
    the log_record_factory. Check to make sure it happened.
    """
    transaction = elasticapm_client.begin_transaction("test")
    with capture_span("test") as span:
        record_factory = logging.getLogRecordFactory()
        record = record_factory(__name__, logging.DEBUG, __file__, 252, "dummy_msg", [], None)
        assert record.elasticapm_transaction_id == transaction.id
        assert record.elasticapm_trace_id == transaction.trace_parent.trace_id
        assert record.elasticapm_span_id == span.id
        assert record.elasticapm_labels 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:15,代碼來源:logging_tests.py

示例4: log_record_factory

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import getLogRecordFactory [as 別名]
def log_record_factory(wrapped, instance, args, kwargs):
    """
    Decorator, designed to wrap the python log record factory (fetched by
    logging.getLogRecordFactory), adding the same custom attributes as in
    the LoggingFilter provided above.

    :return:
        LogRecord object, with custom attributes for APM tracing fields
    """
    record = wrapped(*args, **kwargs)
    return _add_attributes_to_log_record(record) 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:13,代碼來源:logging.py

示例5: _define_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import getLogRecordFactory [as 別名]
def _define_logger(self):

        # Use double-checked locking to avoid taking lock unnecessarily.
        if self._logger is not None:
            return self._logger

        with self._logger_lock:
            try:
                self._logger = _logging.getLogger("nemo_logger")
                # By default, silence all loggers except the logger for rank 0
                self.remove_stream_handlers()
                if get_envbool(NEMO_ENV_VARNAME_TESTING, False):
                    old_factory = _logging.getLogRecordFactory()

                    def record_factory(*args, **kwargs):
                        record = old_factory(*args, **kwargs)
                        record.rank = get_envint("RANK", 0)
                        return record

                    _logging.setLogRecordFactory(record_factory)
                    self.add_stream_handlers(formatter=DebugNeMoFormatter)
                elif get_envint("RANK", 0) == 0:
                    self.add_stream_handlers()

            finally:
                level = Logger.INFO
                if get_envbool(NEMO_ENV_VARNAME_TESTING, False):
                    level = Logger.DEBUG
                self.set_verbosity(verbosity_level=level)

        self._logger.propagate = False 
開發者ID:NVIDIA,項目名稱:NeMo,代碼行數:33,代碼來源:nemo_logging.py

示例6: __init__

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import getLogRecordFactory [as 別名]
def __init__(self) -> None:
        self.user: Optional[str] = None
        self.previous = logging.getLogRecordFactory() 
開發者ID:PacktPublishing,項目名稱:Mastering-Object-Oriented-Python-Second-Edition,代碼行數:5,代碼來源:ch16_ex6.py


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