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


Python WatchedFileHandler._name方法代码示例

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


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

示例1: __init__

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import _name [as 别名]
    def __init__(
        self,
        level=logging.DEBUG,
        name=None,
        logdir="./",
        stdout=True,
        multiFile=False,
        post=False,
        ws="www-qa.coraid.com",
    ):
        self.logdir = logdir
        self.ws = ws
        self.instance = os.environ.get("instance") or ""
        self.level = level
        logging.addLevelName(COMMENT, "COMMENT")

        # Root Logger
        self.logger = logging.getLogger("otto" + self.instance)
        self.logger.addHandler(logging.NullHandler())

        """
        Root Logger Threshold is WARNING by default.
        We will set the threshold as low as possible
        """
        self.logger.setLevel(DEBUG)

        """
        The STDOUT handler will use the logger default threshold for printing.
        If the level is set to INFO the STDOUT should only display INFO messages and greater
        """
        if stdout:
            StdOutHandler = logging.StreamHandler(sys.stdout)
            StdOutHandler._name = "STDOUT"
            StdOutHandler.setLevel(level)
            StdOutHandler.setFormatter(Dispatcher())
            self.logger.addHandler(StdOutHandler)

        if name is None:
            frame = inspect.stack()[1]
            name = inspect.getfile(frame[0]).split("/")[-1].split(".py")[0]

        logFileBase = self.logdir + name + "-" + time.strftime("%Y%m%d_%H%M")

        """
        The Full log will contain every level of output and will be created
        in any configuration for use when posting the log to the web server.
        """
        fullLogFile = logFileBase + "_FULL.log"
        self.fullLogFile = fullLogFile
        FullLogFileHandler = WatchedFileHandler(fullLogFile)
        FullLogFileHandler.setLevel(level)
        FullLogFileHandler._name = "LogFile-FULL"
        FullLogFileHandler.setFormatter(Dispatcher())
        self.logger.addHandler(FullLogFileHandler)

        """
        In the case of multiFile = True:
        Create a FileHandler for each level and attatch the appropriate level name to the file suffix
        Then set a filter on each handler to return only the appropriate level per file
        """
        if multiFile:
            # Set up filename variables
            debugLogFile = logFileBase + "_DEBUG.log"
            commentLogFile = logFileBase + "_COMMENT.log"
            infoLogFile = logFileBase + "_INFO.log"
            warningLogFile = logFileBase + "_WARNING.log"
            errorLogFile = logFileBase + "_ERROR.log"

            # Create FileHandler objects
            DebugFileHandler = WatchedFileHandler(debugLogFile)
            DebugFileHandler._name = "LogFile-DEBUG"
            CommentFileHandler = WatchedFileHandler(commentLogFile)
            CommentFileHandler._name = "LogFile-COMMENT"
            InfoFileHandler = WatchedFileHandler(infoLogFile)
            InfoFileHandler._name = "LogFile-INFO"
            WarningFileHandler = WatchedFileHandler(warningLogFile)
            WarningFileHandler._name = "LogFile-WARNING"
            ErrorFileHandler = WatchedFileHandler(errorLogFile)
            ErrorFileHandler._name = "LogFile-ERROR"

            # Add filters at corresponding levels
            DebugFileHandler.addFilter(LogFilter(DEBUG))
            CommentFileHandler.addFilter(LogFilter(COMMENT))
            InfoFileHandler.addFilter(LogFilter(INFO))
            WarningFileHandler.addFilter(LogFilter(WARNING))
            ErrorFileHandler.addFilter(LogFilter(ERROR))

            # Add format Dispatcher
            DebugFileHandler.setFormatter(Dispatcher())
            CommentFileHandler.setFormatter(Dispatcher())
            InfoFileHandler.setFormatter(Dispatcher())
            WarningFileHandler.setFormatter(Dispatcher())
            ErrorFileHandler.setFormatter(Dispatcher())

            # Add handlers to root logger
            self.logger.addHandler(DebugFileHandler)
            self.logger.addHandler(CommentFileHandler)
            self.logger.addHandler(InfoFileHandler)
            self.logger.addHandler(WarningFileHandler)
            self.logger.addHandler(ErrorFileHandler)
开发者ID:mennis,项目名称:oTTo,代码行数:102,代码来源:log.py


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