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


Python logging.BASIC_FORMAT屬性代碼示例

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


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

示例1: formatMessage

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def formatMessage(self, record: logging.LogRecord) -> str:
        """Convert the already filled log record to a string."""
        level_color = "0"
        text_color = "0"
        fmt = ""
        if record.levelno <= logging.DEBUG:
            fmt = "\033[0;37m" + logging.BASIC_FORMAT + "\033[0m"
        elif record.levelno <= logging.INFO:
            level_color = "1;36"
            lmsg = record.message.lower()
            if self.GREEN_RE.search(lmsg):
                text_color = "1;32"
        elif record.levelno <= logging.WARNING:
            level_color = "1;33"
        elif record.levelno <= logging.CRITICAL:
            level_color = "1;31"
        if not fmt:
            fmt = "\033[" + level_color + \
                  "m%(levelname)s\033[0m:%(rthread)s:%(name)s:\033[" + text_color + \
                  "m%(message)s\033[0m"
        fmt = _fest + fmt
        record.rthread = reduce_thread_id(record.thread)
        return fmt % record.__dict__ 
開發者ID:src-d,項目名稱:modelforge,代碼行數:25,代碼來源:slogging.py

示例2: handlerAndBytesIO

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def handlerAndBytesIO():
    """
    Construct a 2-tuple of C{(StreamHandler, BytesIO)} for testing interaction
    with the 'logging' module.

    @return: handler and io object
    @rtype: tuple of L{StreamHandler} and L{io.BytesIO}
    """
    output = BytesIO()
    stream = output
    template = py_logging.BASIC_FORMAT
    if _PY3:
        stream = TextIOWrapper(output, encoding="utf-8", newline="\n")
    formatter = py_logging.Formatter(template)
    handler = py_logging.StreamHandler(stream)
    handler.setFormatter(formatter)
    return handler, output 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_stdlib.py

示例3: test_no_kwargs

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def test_no_kwargs(self):
        logging.basicConfig()

        # handler defaults to a StreamHandler to sys.stderr
        self.assertEqual(len(logging.root.handlers), 1)
        handler = logging.root.handlers[0]
        self.assertIsInstance(handler, logging.StreamHandler)
        self.assertEqual(handler.stream, sys.stderr)

        formatter = handler.formatter
        # format defaults to logging.BASIC_FORMAT
        self.assertEqual(formatter._style._fmt, logging.BASIC_FORMAT)
        # datefmt defaults to None
        self.assertIsNone(formatter.datefmt)
        # style defaults to %
        self.assertIsInstance(formatter._style, logging.PercentStyle)

        # level is not explicitly set
        self.assertEqual(logging.root.level, self.original_logging_level) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,代碼來源:test_logging.py

示例4: formatMessage

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def formatMessage(self, record: logging.LogRecord) -> str:
        """Convert the already filled log record to a string."""
        level_color = "0"
        text_color = "0"
        fmt = ""
        if record.levelno <= logging.DEBUG:
            fmt = "\033[0;37m" + logging.BASIC_FORMAT + "\033[0m"
        elif record.levelno <= logging.INFO:
            level_color = "1;36"
            lmsg = record.message.lower()
            if self.GREEN_RE.search(lmsg):
                text_color = "1;32"
        elif record.levelno <= logging.WARNING:
            level_color = "1;33"
        elif record.levelno <= logging.CRITICAL:
            level_color = "1;31"
        if not fmt:
            fmt = (
                "\033["
                + level_color
                + "m%(levelname)s\033[0m:%(rthread)s:%(name)s:\033["
                + text_color
                + "m%(message)s\033[0m"
            )
        fmt = _fest + fmt
        record.rthread = reduce_thread_id(record.thread)
        return fmt % record.__dict__ 
開發者ID:FragileTech,項目名稱:fragile,代碼行數:29,代碼來源:slogging.py

示例5: __init__

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def __init__(self, *args, **kwargs):
        self._file_handler = None
        self._file_formatter = kwargs.pop(
            'file_formatter', logging.BASIC_FORMAT
        )
        super(FileLogger, self).__init__(*args, **kwargs) 
開發者ID:HPENetworking,項目名稱:topology,代碼行數:8,代碼來源:logging.py

示例6: ModuleLogger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def ModuleLogger(globs):
    """Create a module level logger.

    To debug a module, create a _debug variable in the module, then use the
    ModuleLogger function to create a "module level" logger.  When a handler
    is added to this logger or a child of this logger, the _debug variable will
    be incremented.

    All of the calls within functions or class methods within the module should
    first check to see if _debug is set to prevent calls to formatter objects
    that aren't necessary.
    """
    # make sure that _debug is defined
    if '_debug' not in globs:
        raise RuntimeError("define _debug before creating a module logger")

    # logger name is the module name
    logger_name = globs['__name__']

    # create a logger to be assigned to _log
    logger = logging.getLogger(logger_name)

    # put in a reference to the module globals
    logger.globs = globs

    # if this is a "root" logger add a default handler for warnings and up
    if '.' not in logger_name:
        hdlr = logging.StreamHandler()
        hdlr.setLevel(logging.WARNING)
        hdlr.setFormatter(logging.Formatter(logging.BASIC_FORMAT, None))
        logger.addHandler(hdlr)

    return logger

#
#   Typical Use
#

# some debugging 
開發者ID:JoelBender,項目名稱:bacpypes,代碼行數:41,代碼來源:debugging.py

示例7: __init__

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def __init__(self, color=None):
        logging.Formatter.__init__(self, logging.BASIC_FORMAT, None)

        # check the color
        if color is not None:
            if color not in range(8):
                raise ValueError("colors are 0 (black) through 7 (white)")

        # save the color
        self.color = color 
開發者ID:JoelBender,項目名稱:bacpypes,代碼行數:12,代碼來源:debugging.py

示例8: ModuleLogger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def ModuleLogger(globs):
    """Create a module level logger.

    To debug a module, create a _debug variable in the module, then use the
    ModuleLogger function to create a "module level" logger.  When a handler
    is added to this logger or a child of this logger, the _debug variable will
    be incremented.

    All of the calls within functions or class methods within the module should
    first check to see if _debug is set to prevent calls to formatter objects
    that aren't necessary.
    """
    # make sure that _debug is defined
    if not globs.has_key('_debug'):
        raise RuntimeError("define _debug before creating a module logger")

    # logger name is the module name
    logger_name = globs['__name__']

    # create a logger to be assigned to _log
    logger = logging.getLogger(logger_name)

    # put in a reference to the module globals
    logger.globs = globs

    # if this is a "root" logger add a default handler for warnings and up
    if '.' not in logger_name:
        hdlr = logging.StreamHandler()
        hdlr.setLevel(logging.WARNING)
        hdlr.setFormatter(logging.Formatter(logging.BASIC_FORMAT, None))
        logger.addHandler(hdlr)

    return logger

#
#   Typical Use
#

# some debugging 
開發者ID:JoelBender,項目名稱:bacpypes,代碼行數:41,代碼來源:debugging.py

示例9: log_to_stream

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def log_to_stream(stream=sys.stderr, level=logging.NOTSET,
                  fmt=logging.BASIC_FORMAT):
    """ Add :class:`logging.StreamHandler` to logger which logs to a stream.

    :param stream. Stream to log to, default STDERR.
    :param level: Log level, default NOTSET.
    :param fmt: String with log format, default is BASIC_FORMAT.
    """
    fmt = Formatter(fmt)
    handler = StreamHandler()
    handler.setFormatter(fmt)
    handler.setLevel(level)

    log.addHandler(handler) 
開發者ID:AdvancedClimateSystems,項目名稱:uModbus,代碼行數:16,代碼來源:utils.py

示例10: enable_logging

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def enable_logging(verbosity=logging.ERROR, stream=sys.stderr, format=logging.BASIC_FORMAT):
    unconfigure_logging()

    logger.setLevel(verbosity)
    _handler = logging.StreamHandler(stream)
    _handler.setFormatter(logging.Formatter(format, None))
    logger.addHandler(_handler)


# If we are in an interactive environment (like Jupyter), set loglevel to INFO and pipe the output to stdout. 
開發者ID:theislab,項目名稱:diffxpy,代碼行數:12,代碼來源:log_cfg.py

示例11: configure_logging

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import BASIC_FORMAT [as 別名]
def configure_logging(level=logging.INFO, msgfmt=logging.BASIC_FORMAT, datefmt=None, filename=None):
    """Configure root logger for console printing.
    """
    root = logging.getLogger()

    if not root.handlers:
        # Set lower level to be sure that all handlers receive the logs
        root.setLevel(logging.DEBUG)

        if filename:
            # Create a file handler, all levels are logged
            filename = osp.abspath(osp.expanduser(filename))
            dirname = osp.dirname(filename)
            if not osp.isdir(dirname):
                os.makedirs(dirname)
            hdlr = logging.FileHandler(filename)
            hdlr.setFormatter(logging.Formatter(msgfmt, datefmt))
            hdlr.setLevel(logging.DEBUG)
            root.addHandler(hdlr)

        # Create a console handler
        hdlr = BlockConsoleHandler(sys.stdout)
        hdlr.setFormatter(logging.Formatter(msgfmt, datefmt))
        if level is not None:
            hdlr.setLevel(level)
            BlockConsoleHandler.default_level = level
        root.addHandler(hdlr) 
開發者ID:pibooth,項目名稱:pibooth,代碼行數:29,代碼來源:utils.py


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