Python logging.handlers.MemoryHandler() Examples

The following are 7 code examples of logging.handlers.MemoryHandler(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module logging.handlers , or try the search function .
Example #1
Source File: handlers.py    From pygogo with MIT License 6 votes vote down vote up
def buffered_hdlr(target=None, capacity=4096, level="error", **kwargs):
    """A memory buffered log handler

    Args:
        target (obj): The target logger handler (default stdout).

        capacity (int): The buffer size (default 4096).

        level (string): The min event level required to flush buffer
            (default: error).

    Returns:
        New instance of :class:`logging.handlers.MemoryHandler`

    Examples:
        >>> buffered_hdlr()  # doctest: +ELLIPSIS
        <...MemoryHandler...>
    """
    target = target or logging.StreamHandler(sys.stdout)
    return hdlrs.MemoryHandler(capacity, level.upper(), target) 
Example #2
Source File: log.py    From oslo.i18n with Apache License 2.0 5 votes vote down vote up
def __init__(self, locale=None, target=None):
        """Initialize a TranslationHandler

        :param locale: locale to use for translating messages
        :param target: logging.Handler object to forward
                       LogRecord objects to after translation
        """
        # NOTE(luisg): In order to allow this handler to be a wrapper for
        # other handlers, such as a FileHandler, and still be able to
        # configure it using logging.conf, this handler has to extend
        # MemoryHandler because only the MemoryHandlers' logging.conf
        # parsing is implemented such that it accepts a target handler.
        handlers.MemoryHandler.__init__(self, capacity=0, target=target)
        self.locale = locale 
Example #3
Source File: gettextutils.py    From eclcli with Apache License 2.0 5 votes vote down vote up
def __init__(self, locale=None, target=None):
        """Initialize a TranslationHandler

        :param locale: locale to use for translating messages
        :param target: logging.Handler object to forward
                       LogRecord objects to after translation
        """
        # NOTE(luisg): In order to allow this handler to be a wrapper for
        # other handlers, such as a FileHandler, and still be able to
        # configure it using logging.conf, this handler has to extend
        # MemoryHandler because only the MemoryHandlers' logging.conf
        # parsing is implemented such that it accepts a target handler.
        handlers.MemoryHandler.__init__(self, capacity=0, target=target)
        self.locale = locale 
Example #4
Source File: Logs.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def make_mem_logger(name,to_log,size=8192):
	from logging.handlers import MemoryHandler
	logger=logging.getLogger(name)
	hdlr=MemoryHandler(size,target=to_log)
	formatter=logging.Formatter('%(message)s')
	hdlr.setFormatter(formatter)
	logger.addHandler(hdlr)
	logger.memhandler=hdlr
	logger.setLevel(logging.DEBUG)
	return logger 
Example #5
Source File: Logs.py    From royal-chaos with MIT License 5 votes vote down vote up
def make_mem_logger(name,to_log,size=8192):
	from logging.handlers import MemoryHandler
	logger=logging.getLogger(name)
	hdlr=MemoryHandler(size,target=to_log)
	formatter=logging.Formatter('%(message)s')
	hdlr.setFormatter(formatter)
	logger.addHandler(hdlr)
	logger.memhandler=hdlr
	logger.setLevel(logging.DEBUG)
	return logger 
Example #6
Source File: log.py    From naz with MIT License 5 votes vote down vote up
def shouldFlush(self, record: logging.LogRecord) -> bool:
        """
        Check for record at the flushLevel or higher.
        Implementation is mostly taken from `logging.handlers.MemoryHandler`
        """
        return record.levelno >= self.flushLevel  # type: ignore # pytype: disable=attribute-error 
Example #7
Source File: log.py    From naz with MIT License 5 votes vote down vote up
def emit(self, record: logging.LogRecord) -> None:
        """
        Emit a record.
        Append the record. If shouldFlush() tells us to, call flush() to process
        the buffer.

        Implementation is taken from `logging.handlers.MemoryHandler`
        """
        self._heartbeat()

        if record.levelno >= self.targetLevel:
            self.buffer.append(record)
        if self.shouldFlush(record):
            self.flush()