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


Python WatchedFileHandler.emit方法代码示例

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


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

示例1: emit

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import emit [as 别名]
    def emit(self, record):
        self._lock.acquire(timeout=2)
        try:
            WatchedFileHandler.emit(self, record)

        finally:
            self._lock.release()
开发者ID:jay-katta,项目名称:wok,代码行数:9,代码来源:safewatchedfilehandler.py

示例2: emit

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import emit [as 别名]
 def emit(self, record):
     old_umask = os.umask(self.umask)
     try:
         # This does not work on py 2.6
         # WatchedFileHandler is probably old style class in 2.6
         # super(UmaskWatchedFileHandler, self).emit(record)
         WatchedFileHandler.emit(self, record)
     finally:
         os.umask(old_umask)
开发者ID:juhamust,项目名称:multiproject,代码行数:11,代码来源:log.py

示例3: TextLogger

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import emit [as 别名]
class TextLogger(Logger):
    """Logs messages with plain text. Rotating-friendly."""

    FORMAT = "%(asctime)s [%(protocol)s:%(pid)s] %(srcname)s >> %(text)s"

    def __init__(self, filename, tz=timezone.utc):
        self.loghandler = WatchedFileHandler(filename, encoding="utf-8", delay=True)
        self.loghandler.setLevel(logging.INFO)
        self.loghandler.setFormatter(logging.Formatter("%(message)s"))
        self.tz = tz

    def log(self, msg: Message):
        d = msg._asdict()
        d["asctime"] = datetime.fromtimestamp(msg.time, self.tz).strftime("%Y-%m-%d %H:%M:%S")
        d["srcname"] = msg.src.alias
        d["srcid"] = msg.src.id
        self.loghandler.emit(logging.makeLogRecord({"msg": self.FORMAT % d}))

    def commit(self):
        pass
开发者ID:gumblex,项目名称:orizonhub,代码行数:22,代码来源:logger.py

示例4: MPHandler

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import emit [as 别名]
class MPHandler(logging.Handler):
    """
    Logger class allowing serial logging from multiple processes into a single log file.

    To realize this, the MPHandler creates a thread listening for log messages, whereas the
    emit method has been overwritten by a method sending the log message to the listening
    thread. Therefore, only one process (the one hosting the listener thread) actually writes
    into the log file.
    """
    def __init__(self, name, mode):
        logging.Handler.__init__(self)

        self._handler = WatchedFileHandler(name, mode)
        self.queue = multiprocessing.Queue(-1)

        t = threading.Thread(target=self.receive)
        t.daemon = True
        t.start()

    def setFormatter(self, fmt):
        logging.Handler.setFormatter(self, fmt)
        self._handler.setFormatter(fmt)

    def receive(self):
        while True:
            try:
                record = self.queue.get()
                self._handler.emit(record)
            except (KeyboardInterrupt, SystemExit):
                raise
            except EOFError:
                break
            except:
                traceback.print_exc(file=sys.stderr)

    def send(self, s):
        self.queue.put_nowait(s)

    def _format_record(self, record):
        # Ensure that exc_info and args have been serialized to strings
        # to suppress any chance of them not being able to be pickled.
        # Furthermore, this possibly reduces the size of messages sent
        # over the pipe.
        if record.args:
            record.msg = record.msg % record.args
            record.args = None
        if record.exc_info:
            self.format(record)
            record.exc_info = None

        return record

    def emit(self, record):
        try:
            s = self._format_record(record)
            self.send(s)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.handleError(record)

    def close(self):
        self._handler.close()
        logging.Handler.close(self)
开发者ID:daemotron,项目名称:backtory,代码行数:66,代码来源:log.py


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