当前位置: 首页>>代码示例>>Python>>正文


Python logging.getLoggerClass方法代码示例

本文整理汇总了Python中logging.getLoggerClass方法的典型用法代码示例。如果您正苦于以下问题:Python logging.getLoggerClass方法的具体用法?Python logging.getLoggerClass怎么用?Python logging.getLoggerClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging的用法示例。


在下文中一共展示了logging.getLoggerClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: json_console_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def json_console_logger(init_context):
    level = init_context.logger_config['log_level']
    name = init_context.logger_config['name']

    klass = logging.getLoggerClass()
    logger_ = klass(name, level=level)

    handler = logging.StreamHandler()

    class JsonFormatter(logging.Formatter):
        def format(self, record):
            return json.dumps(record.__dict__)

    handler.setFormatter(JsonFormatter())
    logger_.addHandler(handler)

    return logger_ 
开发者ID:dagster-io,项目名称:dagster,代码行数:19,代码来源:custom_logger.py

示例2: json_console_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def json_console_logger(init_context):
    level = coerce_valid_log_level(init_context.logger_config['log_level'])
    name = init_context.logger_config['name']

    klass = logging.getLoggerClass()
    logger_ = klass(name, level=level)

    handler = coloredlogs.StandardErrorHandler()

    class JsonFormatter(logging.Formatter):
        def format(self, record):
            return seven.json.dumps(record.__dict__)

    handler.setFormatter(JsonFormatter())
    logger_.addHandler(handler)

    return logger_ 
开发者ID:dagster-io,项目名称:dagster,代码行数:19,代码来源:__init__.py

示例3: get_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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

示例4: set_up_notify_log_level

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def set_up_notify_log_level():
    """Add up a global notify severity to the python logging package.

    NOTIFY severity is logging level between INFO and WARNING.
    By default it outputs only echo step and step name
    with description.
    """

    # could (should?) be checking hasattr like so:
    # hasattr(logging, levelName):
    # hasattr(logging, methodName):
    # hasattr(logging.getLoggerClass(), methodName):
    # but this extra check is arguably *more* overhead than just assigning it?
    logging.addLevelName(NOTIFY, "NOTIFY")
    logging.NOTIFY = NOTIFY
    logging.getLoggerClass().notify = notify 
开发者ID:pypyr,项目名称:pypyr-cli,代码行数:18,代码来源:logger.py

示例5: _init_log

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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

示例6: set_logging_level

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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

示例7: getLogger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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

示例8: add_logging_level

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def add_logging_level(levelName, levelNum, methodName = None):
        """ Adds a new logging level to the `logging` module and the currently configured logging class.
        `levelName` becomes an attribute of the `logging` module with the value `levelNum`.
        `methodName` becomes a convenience method for both `logging` itself and the class returned by `logging.getLoggerClass()`
        (usually just `logging.Logger`). If `methodName` is not specified, `levelName.lower()` is used.

        To avoid accidental clobberings of existing attributes, this method will raise an `AttributeError` if the level name
        is already an attribute of the `logging` module or if the method name is already present .

        Example
        -------
        >>> add_logging_level('TRACE', logging.DEBUG - 5)
        >>> logging.getLogger(__name__).setLevel("TRACE")
        >>> logging.getLogger(__name__).trace('that worked')
        >>> logging.trace('so did this')
        >>> logging.TRACE
        5
        """

        if not methodName:
                methodName = levelName.lower()

        if hasattr(logging, levelName) or hasattr(logging, methodName) or hasattr(logging.getLoggerClass(), methodName):
                return

        def logForLevel(self, message, *args, **kwargs):
                if self.isEnabledFor(levelNum):
                        self._log(levelNum, message, args, **kwargs)
        def logToRoot(message, *args, **kwargs):
                logging.log(levelNum, message, *args, **kwargs)

        logging.addLevelName(levelNum, levelName)
        setattr(logging, levelName, levelNum)
        setattr(logging.getLoggerClass(), methodName, logForLevel)
        setattr(logging, methodName, logToRoot) 
开发者ID:SystemRage,项目名称:py-kms,代码行数:37,代码来源:pykms_Misc.py

示例9: test_set_logger_class

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def test_set_logger_class(self):
        self.assertRaises(TypeError, logging.setLoggerClass, object)

        class MyLogger(logging.Logger):
            pass

        logging.setLoggerClass(MyLogger)
        self.assertEqual(logging.getLoggerClass(), MyLogger)

        logging.setLoggerClass(logging.Logger)
        self.assertEqual(logging.getLoggerClass(), logging.Logger) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_logging.py

示例10: viewLogs

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def viewLogs() -> None:
        QDesktopServices.openUrl(QUrl.fromLocalFile(logging.getLoggerClass().root.handlers[0].baseFilename)) 
开发者ID:ozmartian,项目名称:vidcutter,代码行数:4,代码来源:videocutter.py

示例11: test_file_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def test_file_logger(init_context):
    klass = logging.getLoggerClass()
    logger_ = klass(
        init_context.logger_config['name'], level=init_context.logger_config['log_level']
    )
    handler = LogTestFileHandler(init_context.logger_config['file_path'])
    logger_.addHandler(handler)
    handler.setLevel(init_context.logger_config['log_level'])
    return logger_ 
开发者ID:dagster-io,项目名称:dagster,代码行数:11,代码来源:test_logging.py

示例12: construct_single_handler_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def construct_single_handler_logger(name, level, handler):
    check.str_param(name, 'name')
    check.inst_param(handler, 'handler', logging.Handler)

    level = coerce_valid_log_level(level)

    @logger
    def single_handler_logger(_init_context):
        klass = logging.getLoggerClass()
        logger_ = klass(name, level=level)
        logger_.addHandler(handler)
        handler.setLevel(level)
        return logger_

    return single_handler_logger 
开发者ID:dagster-io,项目名称:dagster,代码行数:17,代码来源:log.py

示例13: create_logger

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def create_logger(app):
    """Creates a logger for the given application.  This logger works
    similar to a regular Python logger but changes the effective logging
    level based on the application's debug flag.  Furthermore this
    function also removes all attached handlers in case there was a
    logger with the log name before.
    """
    Logger = getLoggerClass()

    class DebugLogger(Logger):
        def getEffectiveLevel(x):
            if x.level == 0 and app.debug:
                return DEBUG
            return Logger.getEffectiveLevel(x)

    class DebugHandler(StreamHandler):
        def emit(x, record):
            StreamHandler.emit(x, record) if app.debug else None

    handler = DebugHandler()
    handler.setLevel(DEBUG)
    handler.setFormatter(Formatter(app.debug_log_format))
    logger = getLogger(app.logger_name)
    # just in case that was not a new logger, get rid of all the handlers
    # already attached to it.
    del logger.handlers[:]
    logger.__class__ = DebugLogger
    logger.addHandler(handler)
    return logger 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:31,代码来源:logging.py

示例14: install_filter

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def install_filter(burst, interval, except_level='CRITICAL'):
    """Install a rate limit filter on existing and future loggers.

    Limit logs to *burst* messages every *interval* seconds, except of levels
    >= *except_level*. *except_level* is a log level name like 'CRITICAL'. If
    *except_level* is an empty string, all levels are filtered.

    The filter uses a monotonic clock, the timestamp of log records is not
    used.

    Raise an exception if a rate limit filter is already installed.
    """

    if install_filter.log_filter is not None:
        raise RuntimeError("rate limit filter already installed")

    try:
        except_levelno = _LOG_LEVELS[except_level]
    except KeyError:
        raise ValueError("invalid log level name: %r" % except_level)

    log_filter = _LogRateLimit(burst, interval, except_levelno)

    install_filter.log_filter = log_filter
    install_filter.logger_class = logging.getLoggerClass()

    class RateLimitLogger(install_filter.logger_class):
        def __init__(self, *args, **kw):
            logging.Logger.__init__(self, *args, **kw)
            self.addFilter(log_filter)

    # Setup our own logger class to automatically add the filter
    # to new loggers.
    logging.setLoggerClass(RateLimitLogger)

    # Add the filter to all existing loggers
    for logger in _iter_loggers():
        logger.addFilter(log_filter) 
开发者ID:openstack,项目名称:oslo.log,代码行数:40,代码来源:rate_limit.py

示例15: _use_logger_class

# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def _use_logger_class(logger_class: Type[logging.Logger]) -> Iterator[None]:
    original_logger_class = logging.getLoggerClass()
    logging.setLoggerClass(logger_class)
    try:
        yield
    finally:
        logging.setLoggerClass(original_logger_class) 
开发者ID:ethereum,项目名称:eth-utils,代码行数:9,代码来源:logging.py


注:本文中的logging.getLoggerClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。