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


Python handlers.BufferingHandler类代码示例

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


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

示例1: __init__

    def __init__(self, config, level=None):
        BufferingHandler.__init__(self, 1000)
        self.config = config
        self.old_handlers = []
        self.old_level = None

        # set my formatter
        fmt = datefmt = None
        if config.logging_format:
            fmt = config.logging_format
        else:
            fmt = '%(levelname)s:%(name)s:%(message)s'
        if config.logging_datefmt:
            datefmt = config.logging_datefmt
        fmt = logging.Formatter(fmt, datefmt)
        self.setFormatter(fmt)

        # figure the level we're logging at
        if level is not None:
            self.level = level
        elif config.logging_level:
            self.level = config.logging_level
        else:
            self.level = logging.NOTSET

        # construct my filter
        if config.logging_filter:
            self.addFilter(RecordFilter(config.logging_filter))
开发者ID:vrutkovs,项目名称:beehive,代码行数:28,代码来源:log_capture.py

示例2: __init__

    def __init__(self, config, level=None):
        BufferingHandler.__init__(self, 1000)

        self.config = config

        self.old_handlers = []

        # set my formatter
        fmt = datefmt = None
        if config.logging_format:
            fmt = config.logging_format
        else:
            fmt = "%(levelname)s:%(name)s:%(message)s"
        if config.logging_datefmt:
            datefmt = config.logging_datefmt
        fmt = logging.Formatter(fmt, datefmt)
        self.setFormatter(fmt)

        # figure the level we're logging at
        if level is not None:
            self.level = level
        elif config.logging_level:
            self.level = getattr(logging, config.logging_level.upper(), None)
            if self.level is None:
                raise ConfigError('Invalid log level: "%s"' % config.logging_level)
        else:
            self.level = logging.NOTSET

        # construct my filter
        if config.logging_filter:
            self.addFilter(RecordFilter(config.logging_filter))
开发者ID:KevinMarkVI,项目名称:behave-parallel,代码行数:31,代码来源:log_capture.py

示例3: DebugDumper

class DebugDumper(BCRelay):

	def __init__(self, *argz, **kwz):
		super(DebugDumper, self).__init__(*argz, **kwz)

		# Simple buffered handler that never triggers flush
		self.handler = BufferingHandler(capacity=self.conf.capacity)
		self.buffer = self.handler.buffer = deque(maxlen=self.handler.capacity)
		self.handler.capacity += 1
		self.handler.setLevel(self.conf.level)
		self.handler.setFormatter(
			logging.Formatter(self.conf.format, self.conf.datefmt) )
		logging.root.addHandler(self.handler)

		# Signal log-dump interface
		if self.conf.signal and isinstance(self.conf.signal, str):
			signum = getattr(signal, self.conf.signal, None)
			if not signum: signum = getattr(signal, 'SIG{}'.format(self.conf.signal), None)
			self.conf.signal = signum
		if self.conf.signal:
			def signal_handler(sig, frm):
				# Supress buffering of re-issued messages
				self.handler._emit, self.handler.emit = self.handler.emit, lambda *a, **k: None
				for msg in list(self.buffer): log.fatal(self.handler.format(msg))
				self.handler.emit = self.handler._emit
			signal.signal(self.conf.signal, signal_handler)

	def dispatch(self, msg, source=None):
		if msg != self.conf.command:
			log.noise('Ignoring unknown command: {!r} (source: {})'.format(msg, source))
			return
		if not self.conf.direct: source = None # reply to whatever destination channel
		msg = '\n'.join(it.imap(self.handler.format, list(self.buffer)))
		reactor.callLater( 0, self.interface.dispatch,
			msg, source=self, user=source, direct=True )
开发者ID:mk-fg,项目名称:bordercamp-irc-bot,代码行数:35,代码来源:debug_dumper.py

示例4: __init__

 def __init__(self):
     # BufferingHandler takes a "capacity" argument
     # so as to know when to flush. As we're overriding
     # shouldFlush anyway, we can set a capacity of zero.
     # You can call flush() manually to clear out the
     # buffer.
     BufferingHandler.__init__(self, 0)
开发者ID:fungusakafungus,项目名称:superlance,代码行数:7,代码来源:uptimemon_test.py

示例5: __init__

    def __init__(self, target, thresholdLevel, retainLevel):
        BufferingHandler.__init__(self, capacity=0)
        self.target = target
        self.thresholdLevel = thresholdLevel

        if retainLevel is None:
            retainLevel = thresholdLevel
        self.setLevel(retainLevel)
开发者ID:jon-turney,项目名称:calm,代码行数:8,代码来源:abeyance_handler.py

示例6: __init__

    def __init__(self, testcase):
        """Create a logging handler for the given test case.

        Args:
          testcase (unittest.TestCase): Owner of this logging handler.
        """
        BufferingHandler.__init__(self, capacity=0)
        self.setLevel(logging.DEBUG)
        self.testcase = testcase
开发者ID:harrisonfeng,项目名称:cot,代码行数:9,代码来源:cot_testcase.py

示例7: __init__

 def __init__(self, level, capacity, host, port,
                 fromaddr, toaddrs, user=None, passwd=None,
                 subject='logs', encoding='utf-8'):
     BufferingHandler.__init__(self, capacity)
     self.setLevel(level)
     self.host = host
     self.port = port
     self.fromaddr = fromaddr
     self.toaddrs = toaddrs if isinstance(toaddrs, (list, tuple)) else [toaddrs]
     self.user = user
     self.passwd = passwd
     self.subject = Header(subject)
     self.encoding = encoding
开发者ID:Igelko,项目名称:pyroutines,代码行数:13,代码来源:smtp_logger.py

示例8: create_session_logger

def create_session_logger(format="CPC"):
    logger = logging.getLogger("")
    try:
        logger.addHandler(HANDLER["%s-buffer" % format])
    except KeyError:
        _formatter = logging.Formatter(format)
        handl = BufferingHandler(10000)
        handl.setFormatter(_formatter)
        logger.addHandler(handl)

    logger.setLevel(logging.INFO)

    return logger
开发者ID:imsoftware,项目名称:pyoidc,代码行数:13,代码来源:oc3_server.py

示例9: __init__

    def __init__(self, capacity, fd_target):
        """
        :param int capacity: Amount of records to store in memory
            https://github.com/python/cpython/blob/3.3/Lib/logging/handlers.py#L1161-L1176
        :param object fd_target: File descriptor to write output to (e.g. `sys.stdout`)
        """
        # Call our BufferingHandler init
        if issubclass(BufferingTargetHandler, object):
            super(BufferingTargetHandler, self).__init__(capacity)
        else:
            BufferingHandler.__init__(self, capacity)

        # Save target for later
        self._fd_target = fd_target
开发者ID:Gnewbee,项目名称:suplemon,代码行数:14,代码来源:logger.py

示例10: process_request

 def process_request(self, request):
     if (settings.DEBUG or request.user.is_superuser) and request.REQUEST.has_key('query'):
         self.time_started = time.time()
         self.sql_offset_start = len(connection.queries)
     
         if not hasattr(self, 'loghandler'):
             self.loghandler = BufferingHandler(1000) # Create and a handler
             logging.getLogger('').addHandler(self.loghandler)
         else:
             self.loghandler.flush() # Empty it of all messages
开发者ID:garethr,项目名称:django-clue,代码行数:10,代码来源:query.py

示例11: close

    def close(self):
        """Upon `close`, flush our internal info to the target"""
        # Flush our buffers to the target
        # https://github.com/python/cpython/blob/3.3/Lib/logging/handlers.py#L1185
        # https://github.com/python/cpython/blob/3.3/Lib/logging/handlers.py#L1241-L1256
        self.acquire()
        try:
            for record in self.buffer:
                if record.levelno < self.level:
                    continue
                msg = self.format(record)
                print(msg, file=self._fd_target)
        finally:
            self.release()

        # Then, run our normal close actions
        if issubclass(BufferingTargetHandler, object):
            super(BufferingTargetHandler, self).close()
        else:
            BufferingHandler.close(self)
开发者ID:Gnewbee,项目名称:suplemon,代码行数:20,代码来源:logger.py

示例12: create_logger

    def create_logger(filename, base_dir):
        """
        Creates a logger with a given filename.
        :param filename: File name for the log
        :return: A logger class.
        """
        logger = logging.getLogger("")
        logfile_name = base_dir + filename
        handler = logging.FileHandler(logfile_name)
        base_formatter = logging.Formatter(
            "%(asctime)s %(name)s:%(levelname)s %(message)s")
        cpc = ('%(asctime)s %(name)s:%(levelname)s '
               '[%(client)s,%(path)s,%(cid)s] %(message)s')
        handler.setFormatter(base_formatter)
        logger.addHandler(handler)
        logger.setLevel(logging.DEBUG)
        _formatter = logging.Formatter(cpc)
        fil_handler = logging.FileHandler(logfile_name)
        fil_handler.setFormatter(_formatter)

        buf_handler = BufferingHandler(10000)
        buf_handler.setFormatter(_formatter)
        return logger
开发者ID:rhoerbe,项目名称:pefim-proxy,代码行数:23,代码来源:server.py

示例13: process_request

class TemplateMiddleware:
    def process_request(self, request):
        if (settings.DEBUG or request.user.is_superuser) and request.REQUEST.has_key('template'):
            self.time_started = time.time()
            self.templates_used = []
            self.contexts_used = []
        
            if not hasattr(self, 'loghandler'):
                self.loghandler = BufferingHandler(1000) # Create and a handler
                logging.getLogger('').addHandler(self.loghandler)
            else:
                self.loghandler.flush() # Empty it of all messages
        
            template_rendered.connect(
                self._storeRenderedTemplates
            )
    
    def process_response(self, request, response):
        if (settings.DEBUG or request.user.is_superuser) and request.REQUEST.has_key('template'):
            templates = [
                (t.name, t.origin and t.origin.name or 'No origin')
                for t in self.templates_used
            ]

            template_context = Context({
                'server_time': time.time() - self.time_started,
                'templates': templates,
                'template_dirs': settings.TEMPLATE_DIRS,
            })

            response.content = Template(TEMPLATE).render(template_context)            

        return response
    
    def _storeRenderedTemplates(self, signal, sender, template, context, **kwargs):
        self.templates_used.append(template)
        self.contexts_used.append(context)
开发者ID:garethr,项目名称:django-clue,代码行数:37,代码来源:template.py

示例14: create_logger

def create_logger(filename):
    """
    Creates a logger with a given filename.
    :param filename: File name for the log
    :return: A logger class.
    """
    logger = logging.getLogger("")
    LOGFILE_NAME = filename
    hdlr = logging.FileHandler(LOGFILE_NAME)
    base_formatter = logging.Formatter(
        "%(asctime)s %(name)s:%(levelname)s %(message)s")
    CPC = ('%(asctime)s %(name)s:%(levelname)s '
           '[%(client)s,%(path)s,%(cid)s] %(message)s')
    cpc_formatter = logging.Formatter(CPC)
    hdlr.setFormatter(base_formatter)
    logger.addHandler(hdlr)
    logger.setLevel(logging.DEBUG)
    _formatter = logging.Formatter(CPC)
    fil_handl = logging.FileHandler(LOGFILE_NAME)
    fil_handl.setFormatter(_formatter)

    buf_handl = BufferingHandler(10000)
    buf_handl.setFormatter(_formatter)
    return logger
开发者ID:dv10den,项目名称:yais,代码行数:24,代码来源:Log.py

示例15: __init__

	def __init__(self, *argz, **kwz):
		super(DebugDumper, self).__init__(*argz, **kwz)

		# Simple buffered handler that never triggers flush
		self.handler = BufferingHandler(capacity=self.conf.capacity)
		self.buffer = self.handler.buffer = deque(maxlen=self.handler.capacity)
		self.handler.capacity += 1
		self.handler.setLevel(self.conf.level)
		self.handler.setFormatter(
			logging.Formatter(self.conf.format, self.conf.datefmt) )
		logging.root.addHandler(self.handler)

		# Signal log-dump interface
		if self.conf.signal and isinstance(self.conf.signal, str):
			signum = getattr(signal, self.conf.signal, None)
			if not signum: signum = getattr(signal, 'SIG{}'.format(self.conf.signal), None)
			self.conf.signal = signum
		if self.conf.signal:
			def signal_handler(sig, frm):
				# Supress buffering of re-issued messages
				self.handler._emit, self.handler.emit = self.handler.emit, lambda *a, **k: None
				for msg in list(self.buffer): log.fatal(self.handler.format(msg))
				self.handler.emit = self.handler._emit
			signal.signal(self.conf.signal, signal_handler)
开发者ID:mk-fg,项目名称:bordercamp-irc-bot,代码行数:24,代码来源:debug_dumper.py


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