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


Python BufferingHandler.setFormatter方法代码示例

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


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

示例1: DebugDumper

# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
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,代码行数:37,代码来源:debug_dumper.py

示例2: create_session_logger

# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
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,代码行数:15,代码来源:oc3_server.py

示例3: create_logger

# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
    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,代码行数:25,代码来源:server.py

示例4: create_logger

# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
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,代码行数:26,代码来源:Log.py

示例5: BufferingHandler

# 需要导入模块: from logging.handlers import BufferingHandler [as 别名]
# 或者: from logging.handlers.BufferingHandler import setFormatter [as 别名]
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)

HANDLER = {"CPC-file": fil_handl, "CPC-buffer": buf_handl}
ACTIVE_HANDLER = "BASE"
URLMAP = {}

NAME = "pyoic"

OAS = None

PASSWD = [("diana", "krall"), ("babs", "howes"), ("upper", "crust")]


#noinspection PyUnusedLocal
def devnull(txt):
    pass
开发者ID:asheidan,项目名称:pyoidc,代码行数:33,代码来源:server.py


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