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


Python logging._handlers方法代碼示例

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


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

示例1: resetLogging

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def resetLogging():
    """ Reset the handlers and loggers so that we
    can rerun the tests starting from a blank slate.
    """
    __pragma__("skip")
    logging._handlerList = []

    import weakref
    logging._handlers = weakref.WeakValueDictionary()

    logging.root = logging.RootLogger(logging.WARNING)
    logging.Logger.root = logging.root
    logging.Logger.manager = logging.Manager(logging.root)
    logging.root.manager = logging.Logger.manager
    __pragma__("noskip")

    if __envir__.executor_name == __envir__.transpiler_name:
        logging._resetLogging() 
開發者ID:QQuick,項目名稱:Transcrypt,代碼行數:20,代碼來源:utils.py

示例2: fileConfig

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
    """
    Read the logging configuration from a ConfigParser-format file.

    This can be called several times from an application, allowing an end user
    the ability to select from various pre-canned configurations (if the
    developer provides a mechanism to present the choices and load the chosen
    configuration).
    """
    import configparser

    cp = configparser.ConfigParser(defaults)
    if hasattr(fname, 'readline'):
        cp.read_file(fname)
    else:
        cp.read(fname)

    formatters = _create_formatters(cp)

    # critical section
    logging._acquireLock()
    try:
        logging._handlers.clear()
        del logging._handlerList[:]
        # Handlers add themselves to logging._handlers
        handlers = _install_handlers(cp, formatters)
        _install_loggers(cp, handlers, disable_existing_loggers)
    finally:
        logging._releaseLock() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:31,代碼來源:config.py

示例3: get_logging__handlers

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def get_logging__handlers(self):
        # _handlers is a WeakValueDictionary
        return id(logging._handlers), logging._handlers, logging._handlers.copy() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:5,代碼來源:regrtest.py

示例4: fileConfig

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
    """
    Read the logging configuration from a ConfigParser-format file.

    This can be called several times from an application, allowing an end user
    the ability to select from various pre-canned configurations (if the
    developer provides a mechanism to present the choices and load the chosen
    configuration).
    """
    import ConfigParser

    cp = ConfigParser.ConfigParser(defaults)
    if hasattr(fname, 'readline'):
        cp.readfp(fname)
    else:
        cp.read(fname)

    formatters = _create_formatters(cp)

    # critical section
    logging._acquireLock()
    try:
        logging._handlers.clear()
        del logging._handlerList[:]
        # Handlers add themselves to logging._handlers
        handlers = _install_handlers(cp, formatters)
        _install_loggers(cp, handlers, disable_existing_loggers)
    finally:
        logging._releaseLock() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:31,代碼來源:config.py

示例5: fileConfig

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
    """
    Read the logging configuration from a ConfigParser-format file.

    This can be called several times from an application, allowing an end user
    the ability to select from various pre-canned configurations (if the
    developer provides a mechanism to present the choices and load the chosen
    configuration).
    """
    import configparser

    if isinstance(fname, configparser.RawConfigParser):
        cp = fname
    else:
        cp = configparser.ConfigParser(defaults)
        if hasattr(fname, 'readline'):
            cp.read_file(fname)
        else:
            cp.read(fname)

    formatters = _create_formatters(cp)

    # critical section
    logging._acquireLock()
    try:
        logging._handlers.clear()
        del logging._handlerList[:]
        # Handlers add themselves to logging._handlers
        handlers = _install_handlers(cp, formatters)
        _install_loggers(cp, handlers, disable_existing_loggers)
    finally:
        logging._releaseLock() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:34,代碼來源:config.py

示例6: setUp

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def setUp(self):
        """Setup the default logging stream to an internal StringIO instance,
        so that we can examine log output as we want."""
        logger_dict = logging.getLogger().manager.loggerDict
        logging._acquireLock()
        try:
            self.saved_handlers = logging._handlers.copy()
            self.saved_handler_list = logging._handlerList[:]
            self.saved_loggers = saved_loggers = logger_dict.copy()
            self.saved_name_to_level = logging._nameToLevel.copy()
            self.saved_level_to_name = logging._levelToName.copy()
            self.logger_states = logger_states = {}
            for name in saved_loggers:
                logger_states[name] = getattr(saved_loggers[name],
                                              'disabled', None)
        finally:
            logging._releaseLock()

        # Set two unused loggers
        self.logger1 = logging.getLogger("\xab\xd7\xbb")
        self.logger2 = logging.getLogger("\u013f\u00d6\u0047")

        self.root_logger = logging.getLogger("")
        self.original_logging_level = self.root_logger.getEffectiveLevel()

        self.stream = io.StringIO()
        self.root_logger.setLevel(logging.DEBUG)
        self.root_hdlr = logging.StreamHandler(self.stream)
        self.root_formatter = logging.Formatter(self.log_format)
        self.root_hdlr.setFormatter(self.root_formatter)
        if self.logger1.hasHandlers():
            hlist = self.logger1.handlers + self.root_logger.handlers
            raise AssertionError('Unexpected handlers: %s' % hlist)
        if self.logger2.hasHandlers():
            hlist = self.logger2.handlers + self.root_logger.handlers
            raise AssertionError('Unexpected handlers: %s' % hlist)
        self.root_logger.addHandler(self.root_hdlr)
        self.assertTrue(self.logger1.hasHandlers())
        self.assertTrue(self.logger2.hasHandlers()) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:41,代碼來源:test_logging.py

示例7: tearDown

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def tearDown(self):
        """Remove our logging stream, and restore the original logging
        level."""
        self.stream.close()
        self.root_logger.removeHandler(self.root_hdlr)
        while self.root_logger.handlers:
            h = self.root_logger.handlers[0]
            self.root_logger.removeHandler(h)
            h.close()
        self.root_logger.setLevel(self.original_logging_level)
        logging._acquireLock()
        try:
            logging._levelToName.clear()
            logging._levelToName.update(self.saved_level_to_name)
            logging._nameToLevel.clear()
            logging._nameToLevel.update(self.saved_name_to_level)
            logging._handlers.clear()
            logging._handlers.update(self.saved_handlers)
            logging._handlerList[:] = self.saved_handler_list
            loggerDict = logging.getLogger().manager.loggerDict
            loggerDict.clear()
            loggerDict.update(self.saved_loggers)
            logger_states = self.logger_states
            for name in self.logger_states:
                if logger_states[name] is not None:
                    self.saved_loggers[name].disabled = logger_states[name]
        finally:
            logging._releaseLock() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:30,代碼來源:test_logging.py

示例8: test_config14_ok

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def test_config14_ok(self):
        with support.captured_stdout() as output:
            self.apply_config(self.config14)
            h = logging._handlers['hand1']
            self.assertEqual(h.foo, 'bar')
            self.assertEqual(h.terminator, '!\n')
            logging.warning('Exclamation')
            self.assertTrue(output.getvalue().endswith('Exclamation!\n')) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:10,代碼來源:test_logging.py

示例9: cleanup

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def cleanup(self):
        setattr(logging.root, 'handlers', self.handlers)
        logging._handlers.clear()
        logging._handlers.update(self.saved_handlers)
        logging._handlerList[:] = self.saved_handler_list
        logging.root.level = self.original_logging_level 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:8,代碼來源:test_logging.py

示例10: fileConfig

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
    """
    Read the logging configuration from a ConfigParser-format file.

    This can be called several times from an application, allowing an end user
    the ability to select from various pre-canned configurations (if the
    developer provides a mechanism to present the choices and load the chosen
    configuration).
    """
    import configparser

    if isinstance(fname, configparser.RawConfigParser):
        cp = fname
    else:
        cp = configparser.ConfigParser(defaults)
        if hasattr(fname, 'readline'):
            cp.read_file(fname)
        else:
            cp.read(fname)

    formatters = _create_formatters(cp)

    # critical section
    logging._acquireLock()
    try:
        _clearExistingHandlers()

        # Handlers add themselves to logging._handlers
        handlers = _install_handlers(cp, formatters)
        _install_loggers(cp, handlers, disable_existing_loggers)
    finally:
        logging._releaseLock() 
開發者ID:CedricGuillemet,項目名稱:Imogen,代碼行數:34,代碼來源:config.py

示例11: _clearExistingHandlers

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def _clearExistingHandlers():
    """Clear and close existing handlers"""
    logging._handlers.clear()
    logging.shutdown(logging._handlerList[:])
    del logging._handlerList[:] 
開發者ID:CedricGuillemet,項目名稱:Imogen,代碼行數:7,代碼來源:config.py

示例12: test_config14_ok

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def test_config14_ok(self):
        with captured_stdout() as output:
            self.apply_config(self.config14)
            h = logging._handlers['hand1']
            self.assertEqual(h.foo, 'bar')
            self.assertEqual(h.terminator, '!\n')
            logging.warning('Exclamation')
            self.assertTrue(output.getvalue().endswith('Exclamation!\n')) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:10,代碼來源:test_logging.py

示例13: _register_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def _register_logger(self, name):
        if self.app.config["debug"]:
            logger = logging.getLogger(name)
            logger.addHandler(logging._handlers["unit_console"])
            logger.propagate = False
            logger.setLevel(logging.DEBUG) 
開發者ID:aioli-framework,項目名稱:aioli,代碼行數:8,代碼來源:unit.py

示例14: handle

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _handlers [as 別名]
def handle(self, shard, service, project, **kwargs):
        logging._handlers = []
        logging.basicConfig(level=logging.DEBUG)

        shard, _ = models.Shard.objects.get_or_create(name=shard)
        service, _ = models.Service.objects.get_or_create(name=service)
        project, _ = models.Project.objects.get_or_create(
            name=project, defaults={"shard": shard, "service": service}
        )

        alert = models.Alert.objects.create(body=json.dumps(self.data), error_count=1)

        tasks.process_alert(alert.pk)

        alert.alerterror_set.create(message="Test from CLI") 
開發者ID:line,項目名稱:promgen,代碼行數:17,代碼來源:alerts-test.py


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