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


Python logging.setLoggerClass方法代碼示例

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


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

示例1: setup_rp_logging

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def setup_rp_logging(self):
        "Setup reportportal logging"
        try:
            # Setting up a logging.
            logging.setLoggerClass(RPLogger)
            rp_logger = logging.getLogger(__name__)
            rp_logger.setLevel(logging.INFO)
            # Create handler for Report Portal.
            rp_handler = RPLogHandler(pytest.config._config.py_test_service)
            # Set INFO level for Report Portal handler.
            rp_handler.setLevel(logging.INFO)
            return rp_logger
        except Exception as e:
            self.write("Exception when trying to set rplogger")
            self.write(str(e))
            self.exceptions.append("Error when setting up the reportportal logger") 
開發者ID:qxf2,項目名稱:qxf2-page-object-model,代碼行數:18,代碼來源:Base_Logging.py

示例2: _static_init

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def _static_init():
        if Log._initialized:
            return

        logging.setLoggerClass(_Logger)
        # The root logger's type is unfortunately (and surprisingly) not affected by
        # `setLoggerClass`. Monkey patch it instead. TODO(vimota): Remove this, see the TODO
        # associated with _Logger.
        logging.RootLogger.findCaller = _Logger.findCaller
        log_to_file = _LOG_TO_FILE_ENV.lower() in ("yes", "true", "t", "1") if _LOG_TO_FILE_ENV is not None else True
        if log_to_file:
            handler = logging.FileHandler(filename='/tmp/kaggle.log', mode='w')
        else:
            handler = logging.StreamHandler()
        
        # ".1s" is for the first letter: http://stackoverflow.com/a/27453084/1869.
        format_string = "%(asctime)s %(levelname).1s %(process)d %(filename)s:%(lineno)d] %(message)s"
        handler.setFormatter(_LogFormatter(format_string))
        logging.basicConfig(level=logging.INFO, handlers=[handler])
        Log._initialized = True 
開發者ID:Kaggle,項目名稱:docker-python,代碼行數:22,代碼來源:log.py

示例3: setup_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def setup_logger(loglevel=DEBUG):
    """Set up logger and add stdout handler"""
    logging.setLoggerClass(IPDLogger)
    logger = logging.getLogger("icloudpd")
    logger.setLevel(loglevel)
    has_stdout_handler = False
    for handler in logger.handlers:
        if handler.name == "stdoutLogger":
            has_stdout_handler = True
    if not has_stdout_handler:
        formatter = logging.Formatter(
            fmt="%(asctime)s %(levelname)-8s %(message)s",
            datefmt="%Y-%m-%d %H:%M:%S")
        stdout_handler = logging.StreamHandler(stream=sys.stdout)
        stdout_handler.setFormatter(formatter)
        stdout_handler.name = "stdoutLogger"
        logger.addHandler(stdout_handler)
    return logger 
開發者ID:ndbroadbent,項目名稱:icloud_photos_downloader,代碼行數:20,代碼來源:logger.py

示例4: test_logger_tqdm_fallback

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def test_logger_tqdm_fallback(self):
        logging.setLoggerClass(IPDLogger)
        logger = logging.getLogger("icloudpd-test")
        logger.log = MagicMock()
        logger.set_tqdm_description("foo")
        logger.log.assert_called_once_with(logging.INFO, "foo")

        logger.log = MagicMock()
        logger.tqdm_write("bar")
        logger.log.assert_called_once_with(logging.INFO, "bar")

        logger.set_tqdm(MagicMock())
        logger.tqdm.write = MagicMock()
        logger.tqdm.set_description = MagicMock()
        logger.log = MagicMock()
        logger.set_tqdm_description("baz")
        logger.tqdm.set_description.assert_called_once_with("baz")
        logger.tqdm_write("qux")
        logger.tqdm.write.assert_called_once_with("qux")
        logger.log.assert_not_called 
開發者ID:ndbroadbent,項目名稱:icloud_photos_downloader,代碼行數:22,代碼來源:test_logger.py

示例5: getLogger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def getLogger(name):
    """Returns a logger instance to use for the given name that implements the Scalyr agent's extra logging features.

    This should be used in place of logging.getLogger when trying to retrieve a logging instance that implements
    Scalyr agent's extra features.

    Note, the logger instance will be configured to emit records at INFO level and above.

    @param name: The name of the logger, such as the module name. If this is for a particular monitor instance, then
        the monitor id should be appended at the end surrounded by brackets, such as "my_monitor[1]"

    @return: A logger instance implementing the extra features.
    """
    logging.setLoggerClass(AgentLogger)
    result = logging.getLogger(name)
    result.setLevel(logging.INFO)
    return result


# The single AgentLogManager instance that tracks all of the process wide information necessary to implement
# our logging strategy.  This variable is set to the real variable down below. 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:23,代碼來源:scalyr_logging.py

示例6: uninstall_filter

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def uninstall_filter():
    """Uninstall the rate filter installed by install_filter().

    Do nothing if the filter was already uninstalled.
    """

    if install_filter.log_filter is None:
        # not installed (or already uninstalled)
        return

    # Restore the old logger class
    logging.setLoggerClass(install_filter.logger_class)

    # Remove the filter from all existing loggers
    for logger in _iter_loggers():
        logger.removeFilter(install_filter.log_filter)

    install_filter.logger_class = None
    install_filter.log_filter = None 
開發者ID:openstack,項目名稱:oslo.log,代碼行數:21,代碼來源:rate_limit.py

示例7: get_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def get_logger(name="insteon_mqtt"):
    """Get a logger object to use.

    This will return a logging object to use for messages.

    Args:
      name (str):  The name of the logging objectd.

    Returns:
      The requested logging object.
    """
    # Force the logging system to use our custom logger class, then restore
    # whatever was set when we're done.
    save = logging.getLoggerClass()
    try:
        logging.setLoggerClass(Logger)
        return logging.getLogger(name)
    finally:
        logging.setLoggerClass(save)


#=========================================================================== 
開發者ID:TD22057,項目名稱:insteon-mqtt,代碼行數:24,代碼來源:log.py

示例8: _initialize

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def _initialize(log_config_path):
        """
        Initialize the logging facility for Ignis
        """
        logging.setLoggerClass(IgnisLogger)

        log_config = IgnisLogging._load_config_file(log_config_path)
        # Reading the config file content
        IgnisLogging._file_logging_enabled = \
            log_config.get('file_logging') == "true"
        IgnisLogging._log_file = log_config.get('log_file') if \
            log_config.get('log_file') is not None else "ignis.log"
        max_size = log_config.get('max_size')
        IgnisLogging._max_bytes = int(max_size) if \
            max_size is not None and max_size.isdigit() else 0
        max_rotations = log_config.get('max_rotations')
        IgnisLogging._max_rotations = int(max_rotations) if \
            max_rotations is not None and max_rotations.isdigit() else 0 
開發者ID:Qiskit,項目名稱:qiskit-ignis,代碼行數:20,代碼來源:ignis_logging.py

示例9: _init_log

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def _init_log():
    """Initializes the Astropy log--in most circumstances this is called
    automatically when importing astropy.
    """

    global log

    orig_logger_cls = logging.getLoggerClass()
    logging.setLoggerClass(AstropyLogger)
    try:
        log = logging.getLogger('astropy')
        log._set_defaults()
    finally:
        logging.setLoggerClass(orig_logger_cls)

    return log 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:18,代碼來源:logger.py

示例10: get_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def get_logger(name=None):
    """
    Build a logger with the given name and returns the logger.

    :param name: The name for the logger. This is usually the module
                 name, ``__name__``.
    :return: logger object
    """
    logging.setLoggerClass(CustomLogger)

    logger = logging.getLogger(name)
    logger.setLevel(logging.DEBUG)

    logger.addHandler(_get_info_handler())
    logger.addHandler(_get_out_handler())
    logger.addHandler(_get_warn_handler())
    logger.addHandler(_get_error_handler())
    logger.addHandler(_get_critical_handler())
    logger.addHandler(_get_success_handler())
    logger.propagate = False

    return logger 
開發者ID:ansible-community,項目名稱:molecule,代碼行數:24,代碼來源:logger.py

示例11: init_logging

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def init_logging():
    # type: () -> None
    """
    Initialize logging (set up forwarding to Go backend and sane defaults)
    """
    # Forward to Go backend
    logging.addLevelName(TRACE_LEVEL, 'TRACE')
    logging.setLoggerClass(AgentLogger)
    logging.captureWarnings(True)  # Capture warnings as logs so it's easier for log parsers to handle them.

    rootLogger = logging.getLogger()
    rootLogger.addHandler(AgentLogHandler())
    rootLogger.setLevel(_get_py_loglevel(datadog_agent.get_config('log_level')))

    # `requests` (used in a lot of checks) imports `urllib3`, which logs a bunch of stuff at the info level
    # Therefore, pre emptively increase the default level of that logger to `WARN`
    urllib_logger = logging.getLogger("requests.packages.urllib3")
    urllib_logger.setLevel(logging.WARN)
    urllib_logger.propagate = True 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:21,代碼來源:log.py

示例12: set_logging_level

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def set_logging_level(cls, level):
        if cls._qkc_logger:
            Logger.warning("logging_level has already been set")
            return
        level_map = {
            "DEBUG": logging.DEBUG,
            "INFO": logging.INFO,
            "WARNING": logging.WARNING,
            "ERROR": logging.ERROR,
            "CRITICAL": logging.CRITICAL,
        }
        level = level.upper()
        if level not in level_map:
            raise RuntimeError("invalid level {}".format(level))

        original_logger_class = logging.getLoggerClass()
        logging.setLoggerClass(QKCLogger)
        cls._qkc_logger = logging.getLogger("qkc")
        logging.setLoggerClass(original_logger_class)

        logging.root.setLevel(level_map[level])

        formatter = QKCLogFormatter()
        handler = logging.StreamHandler()
        handler.setFormatter(formatter)
        logging.root.addHandler(handler) 
開發者ID:QuarkChain,項目名稱:pyquarkchain,代碼行數:28,代碼來源:utils.py

示例13: getLogger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def getLogger(self, name):
        logging.setLoggerClass(SLogger)
        return super(SManager, self).getLogger(name) 
開發者ID:QuarkChain,項目名稱:pyquarkchain,代碼行數:5,代碼來源:slogging.py

示例14: _logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def _logger(self):
        """Return the logger. The default_args property is not available in init."""
        logging.setLoggerClass(TraceLogger)
        logger = logging.getLogger(self.logger_name)
        logger.setLevel(logging.TRACE)
        return logger 
開發者ID:ThreatConnect-Inc,項目名稱:tcex,代碼行數:8,代碼來源:logger.py

示例15: getLogger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import setLoggerClass [as 別名]
def getLogger(name):
    og_class = logging.getLoggerClass()
    try:
        logging.setLoggerClass(Logger)
        return logging.getLogger(name)
    finally:
        logging.setLoggerClass(og_class)


# The main 'eyed3' logger 
開發者ID:nicfit,項目名稱:eyeD3,代碼行數:12,代碼來源:log.py


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