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


Python logging.html方法代碼示例

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


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

示例1: capture_output

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def capture_output(log_level: int) -> bool:
    """Utility function used in subprocess for captured output.

    Available log levels are: https://docs.python.org/3/library/logging.html#levels
    10 is the value for Debug, so if it's not "DEBUG", return true and capture output.

    Args:
        log_level: the logging level

    Returns:
        Bool indicator on capturing output
    """
    return log_level != 10


####################################################################################################
# CLEAN TRIAL RUNNING FUNCTIONS
#################################################################################################### 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:20,代碼來源:run.py

示例2: modify_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def modify_logger(logger, log_file):
    # refer: https://docs.python.org/3.5/library/logging.html#logrecord-attributes
    formatter = logging.Formatter(
        fmt='\n'.join([
            '[%(name)s] %(asctime)s.%(msecs)d',
            '\t%(pathname)s [line: %(lineno)d]',
            '\t%(processName)s[%(process)d] => %(threadName)s[%(thread)d] => %(module)s.%(filename)s:%(funcName)s()',
            '\t%(levelname)s: %(message)s\n'
        ]),
        datefmt='%Y-%m-%d %H:%M:%S'
    )
    # stream_handler = logging.StreamHandler()
    # stream_handler.setFormatter(formatter)
    # logger.addHandler(stream_handler)

    file_handler = logging.FileHandler(log_file, mode='a', encoding='utf-8')
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    logger.setLevel(logging.DEBUG)

    return logger 
開發者ID:gsw945,項目名稱:schedule-system,代碼行數:24,代碼來源:server.py

示例3: log

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def log(self, msg, lvl=logging.INFO, *args, **kwargs):
        """Log a message within a set level

        This method abstracts the logging.Logger.log() method. We use this
        method during major state changes, errors, or critical events during
        the optimization run.

        You can check logging levels on this `link`_. In essence, DEBUG is 10,
        INFO is 20, WARNING is 30, ERROR is 40, and CRITICAL is 50.

        .. _link: https://docs.python.org/3/library/logging.html#logging-levels

        Parameters
        ----------
        msg : str
            Message to be logged
        lvl : int, optional
            Logging level. Default is `logging.INFO`
        """
        self.logger.log(lvl, msg, *args, **kwargs) 
開發者ID:ljvmiranda921,項目名稱:pyswarms,代碼行數:22,代碼來源:reporter.py

示例4: log_to_console

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def log_to_console(status=True, level=None):
    """Log events to the console.

    Parameters
    ----------
    status: bool, optional, default=True
        Whether logging to console should be turned on(True) or off(False)
    level: string, optional, default=None
        Level of logging; whichever level is chosen all higher levels
        will be logged. See: https://docs.python.org/2/library/logging.html#levels

    """
    set_log_level(level)
    if status:
        console_handler = logging.StreamHandler()
        formatter = logging.Formatter(_LOGGER_FORMAT_STR)
        console_handler.setFormatter(formatter)
        _LOGGER.addHandler(console_handler)
    else:
        _remove_log_handler(logging.StreamHandler) 
開發者ID:corteva,項目名稱:geocube,代碼行數:22,代碼來源:logger.py

示例5: tlog

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def tlog(self, level, text, *args):
        """
        記錄文本日誌信息,較高級別的日誌(FATAL)會被收集到總控統一存儲以備後續追查。
        實際的文本日誌組裝和輸出是由標準庫\
         `logging — Logging facility for Python <https://docs.python.org/2.7/library/logging.html>`_\ 提供的

        :param int level: 日誌級別,級別包括:DEBUG < INFO < WARNING < ERROR < CRITICAL
        :param obj text: 要輸出的文本信息,通過python字符串的%語法可以獲得類似c語言printf的效果
        :param args: 格式化字符串中占位符對應的變量值,如果變量是對象則打印成json
        :returns: 無返回
        :rtype: None
        """
        logger = logging.getLogger(self._log_name)
        texts, json_args = self._format_request(logger.getEffectiveLevel(), text, args)
        if len(json_args) > 0:
            logger.log(level, texts, *json_args)
        else:
            logger.log(level, texts) 
開發者ID:baidu,項目名稱:ARK,代碼行數:20,代碼來源:log.py

示例6: _formatTime

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def _formatTime(self) -> str:
        """
        Return the creation time of the specified log event as formatted text.

        This code is borrowed from:
        https://docs.python.org/3/library/logging.html#logging.Formatter.formatTime

        The basic behaviour is as follows: an ISO8601-like (or RFC 3339-like) format is used.
        This function uses `time.localtime()` to convert the creation time to a tuple.
        """
        _converter = time.localtime
        _formatter = logging.Formatter()

        now = time.time()
        msecs = (now - int(now)) * 1000

        ct = _converter(now)  # type: ignore
        t = time.strftime(_formatter.default_time_format, ct)
        s = _formatter.default_msec_format % (t, msecs)
        return s 
開發者ID:komuw,項目名稱:naz,代碼行數:22,代碼來源:log.py

示例7: _heartbeat

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def _heartbeat(self) -> None:
        if not self.heartbeatInterval:
            return

        # check if `heartbeatInterval` seconds have passed.
        # if they have, emit a heartbeat log record to the target handler
        _now = time.monotonic()
        _diff = _now - self._s_time
        if _diff >= self.heartbeatInterval:
            self._s_time = _now
            # see: https://docs.python.org/3/library/logging.html#logging.LogRecord
            record = logging.makeLogRecord(
                {
                    "level": logging.INFO,
                    "name": "BreachHandler",
                    "pathname": ".../naz/naz/log.py",
                    "func": "BreachHandler._heartbeat",
                    "msg": {
                        "event": "naz.BreachHandler.heartbeat",
                        "heartbeatInterval": self.heartbeatInterval,
                    },
                }
            )
            self.target.emit(record=record)  # type: ignore # pytype: disable=attribute-error 
開發者ID:komuw,項目名稱:naz,代碼行數:26,代碼來源:log.py

示例8: setup_default_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def setup_default_logger(logfile=None, level=logging.DEBUG, formatter=None, maxBytes=0, backupCount=0, disableStderrLogger=False):
    """
    Deprecated. Use `logzero.loglevel(..)`, `logzero.logfile(..)`, etc.

    Globally reconfigures the default `logzero.logger` instance.

    Usage:

    .. code-block:: python

        from logzero import logger, setup_default_logger
        setup_default_logger(level=logging.WARN)
        logger.info("hello")  # this will not be displayed anymore because minimum loglevel was set to WARN

    :arg string logfile: If set, also write logs to the specified filename.
    :arg int level: Minimum `logging-level <https://docs.python.org/2/library/logging.html#logging-levels>`_ to display (default: `logging.DEBUG`).
    :arg Formatter formatter: `Python logging Formatter object <https://docs.python.org/2/library/logging.html#formatter-objects>`_ (by default uses the internal LogFormatter).
    :arg int maxBytes: Size of the logfile when rollover should occur. Defaults to 0, rollover never occurs.
    :arg int backupCount: Number of backups to keep. Defaults to 0, rollover never occurs.
    :arg bool disableStderrLogger: Should the default stderr logger be disabled. Defaults to False.
    """
    global logger
    logger = setup_logger(name=LOGZERO_DEFAULT_LOGGER, logfile=logfile, level=level, formatter=formatter, disableStderrLogger=disableStderrLogger)
    return logger 
開發者ID:metachris,項目名稱:logzero,代碼行數:26,代碼來源:__init__.py

示例9: loglevel

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def loglevel(level=logging.DEBUG, update_custom_handlers=False):
    """
    Set the minimum loglevel for the default logger (`logzero.logger`).

    This reconfigures only the internal handlers of the default logger (eg. stream and logfile).
    You can also update the loglevel for custom handlers by using `update_custom_handlers=True`.

    :arg int level: Minimum `logging-level <https://docs.python.org/2/library/logging.html#logging-levels>`_ to display (default: `logging.DEBUG`).
    :arg bool update_custom_handlers: If you added custom handlers to this logger and want this to update them too, you need to set `update_custom_handlers` to `True`
    """
    logger.setLevel(level)

    # Reconfigure existing internal handlers
    for handler in list(logger.handlers):
        if hasattr(handler, LOGZERO_INTERNAL_LOGGER_ATTR) or update_custom_handlers:
            # Don't update the loglevel if this handler uses a custom one
            if hasattr(handler, LOGZERO_INTERNAL_HANDLER_IS_CUSTOM_LOGLEVEL):
                continue

            # Update the loglevel for all default handlers
            handler.setLevel(level)

    global _loglevel
    _loglevel = level 
開發者ID:metachris,項目名稱:logzero,代碼行數:26,代碼來源:__init__.py

示例10: formatter

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def formatter(formatter, update_custom_handlers=False):
    """
    Set the formatter for all handlers of the default logger (``logzero.logger``).

    This reconfigures only the logzero internal handlers by default, but you can also
    reconfigure custom handlers by using ``update_custom_handlers=True``.

    Beware that setting a formatter which uses colors also may write the color codes
    to logfiles.

    :arg Formatter formatter: `Python logging Formatter object <https://docs.python.org/2/library/logging.html#formatter-objects>`_ (by default uses the internal LogFormatter).
    :arg bool update_custom_handlers: If you added custom handlers to this logger and want this to update them too, you need to set ``update_custom_handlers`` to `True`
    """
    for handler in list(logger.handlers):
        if hasattr(handler, LOGZERO_INTERNAL_LOGGER_ATTR) or update_custom_handlers:
            handler.setFormatter(formatter)

    global _formatter
    _formatter = formatter 
開發者ID:metachris,項目名稱:logzero,代碼行數:21,代碼來源:__init__.py

示例11: setup_default_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def setup_default_logger(logfile=None, level=logging.DEBUG, formatter=None, maxBytes=0, backupCount=0):
    """
    Deprecated. Use `logzero.loglevel(..)`, `logzero.logfile(..)`, etc.

    Globally reconfigures the default `logzero.logger` instance.

    Usage:

    .. code-block:: python

        from logzero import logger, setup_default_logger
        setup_default_logger(level=logging.WARN)
        logger.info("hello")  # this will not be displayed anymore because minimum loglevel was set to WARN

    :arg string logfile: If set, also write logs to the specified filename.
    :arg int level: Minimum `logging-level <https://docs.python.org/2/library/logging.html#logging-levels>`_ to display (default: `logging.DEBUG`).
    :arg Formatter formatter: `Python logging Formatter object <https://docs.python.org/2/library/logging.html#formatter-objects>`_ (by default uses the internal LogFormatter).
    :arg int maxBytes: Size of the logfile when rollover should occur. Defaults to 0, rollover never occurs.
    :arg int backupCount: Number of backups to keep. Defaults to 0, rollover never occurs.
    """
    global logger
    logger = setup_logger(name=LOGZERO_DEFAULT_LOGGER, logfile=logfile, level=level, formatter=formatter)
    return logger 
開發者ID:neargle,項目名稱:ver-observer,代碼行數:25,代碼來源:__init__.py

示例12: getLoggerPassFilters

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def getLoggerPassFilters(loggerName: str) -> Logger:
    """
    Returns a logger instance where the filters of all the parent chain are applied to it.
    This is needed since Filters do NOT get inherited from parent logger to child logger.
    See: https://docs.python.org/3/library/logging.html#filter-objects
    """
    logger = logging.getLogger(loggerName)
    subLoggerNames = loggerName.split(".")
    filterList = []
    parentLoggerName = ""
    for subLoggerName in subLoggerNames:
        parentLoggerName += subLoggerName
        parentLogger = logging.getLogger(parentLoggerName)
        filterList += parentLogger.filters
        parentLoggerName += "."
    [logger.addFilter(parentFilter) for parentFilter in filterList]
    return logger 
開發者ID:GoSecure,項目名稱:pyrdp,代碼行數:19,代碼來源:helpers.py

示例13: __init__

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def __init__(self, lvl=logging.DEBUG, format=None):
        self._lvl = lvl
        if not format:
            format = "  %(log_color)s%(styledname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s"
        self.format = format
        logging.root.setLevel(self._lvl)
        self.formatter = colorlog.ColoredFormatter(self.format)
        self.stream = logging.StreamHandler()
        self.stream.setLevel(self._lvl)
        self.stream.setFormatter(self.formatter)
        self.logger = logging.getLogger('pythonConfig')
        self.logger.setLevel(self._lvl)
        self.logger.addHandler(self.stream)
        self.theme = THEME
        self.extra = {"styledname": self.theme[self._lvl]}

    # the magic happens here: we use the "extra" argument documented in
    # https://docs.python.org/2/library/logging.html#logging.Logger.debug
    # to inject new items into the logging.LogRecord objects
    # we also create our convenience methods here 
開發者ID:ManufacturaInd,項目名稱:python-zenlog,代碼行數:22,代碼來源:__init__.py

示例14: _json_default

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def _json_default(obj):
    """
    Coerce everything to strings.

    All objects representing time get output as ISO8601.
    """
    if isinstance(obj, (datetime.date, datetime.time, datetime.datetime)):
        return obj.isoformat()

    elif isinstance(obj, Exception):
        return "Exception: %s" % str(obj)

    return str(obj)


# skip natural LogRecord attributes
# http://docs.python.org/library/logging.html#logrecord-attributes 
開發者ID:quay,項目名稱:quay,代碼行數:19,代碼來源:loghandler.py

示例15: __init__

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import html [as 別名]
def __init__(self, *args, **kwargs):
        """
        :param json_default: a function for encoding non-standard objects
            as outlined in http://docs.python.org/2/library/json.html
        :param json_encoder: optional custom encoder
        :param json_serializer: a :meth:`json.dumps`-compatible callable
            that will be used to serialize the log record.
        :param prefix: an optional key prefix to nest logs
        """
        self.json_default = kwargs.pop("json_default", _json_default)
        self.json_encoder = kwargs.pop("json_encoder", None)
        self.json_serializer = kwargs.pop("json_serializer", json.dumps)
        self.default_values = kwargs.pop("default_extra", {})
        self.prefix_key = kwargs.pop("prefix_key", "data")

        logging.Formatter.__init__(self, *args, **kwargs)

        self._fmt_parameters = self._parse_format_string()
        self._skip_fields = set(self._fmt_parameters)
        self._skip_fields.update(RESERVED_ATTRS) 
開發者ID:quay,項目名稱:quay,代碼行數:22,代碼來源:loghandler.py


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