本文整理汇总了Python中logging.Formatter.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.__init__方法的具体用法?Python Formatter.__init__怎么用?Python Formatter.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.Formatter
的用法示例。
在下文中一共展示了Formatter.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, stream=None):
"""
Construct this formatter.
Provides colored output if the stream parameter is specified and is an acceptable TTY.
We print hardwired escape sequences, which will probably break in some circumstances;
for this unfortunate shortcoming, we apologize.
"""
# select and construct format string
import curses
format = None
if stream and hasattr(stream, "isatty") and stream.isatty():
curses.setupterm()
# FIXME do nice block formatting, increasing column sizes as necessary
if curses.tigetnum("colors") > 2:
format = "%s%%(asctime)s%s %%(message)s" % (
TTY_VerboseFormatter._NAME_COLOR,
TTY_VerboseFormatter._COLOR_END,
)
if format is None:
format = "%(name)s - %(levelname)s - %(message)s"
# initialize this formatter
Formatter.__init__(self, format, TTY_VerboseFormatter._DATE_FORMAT)
示例2: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, coloured=False):
fmt = "%(asctime)s %(address)s %(levelname)s: %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
self.linefmt = " "
self._coloured = coloured
Formatter.__init__(self, fmt, datefmt)
示例3: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, pidlog=False):
pidlog = "[%(process)s] " if pidlog else ""
self._normal_fmt = ("%(asctime)s " + pidlog +
"[%(levelname)s %(name)s] %(message)s")
self._context_fmt = ("%(asctime)s " + pidlog + "[%(levelname)s "
"%(name)s] [%(context)s] %(message)s")
Formatter.__init__(self, self._normal_fmt)
示例4: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, prefix='', only_from=None):
"""
.. todo::
WRITEME
"""
Formatter.__init__(self)
self._info_fmt = prefix + "%(message)s"
self._fmt = prefix + "%(levelname)s (%(name)s): %(message)s"
self._only_from = only_from
示例5: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, formatter_for_level=dict(), default=Formatter()):
"""
Use the given formatter_for_level map of {level: formatter} to
format messages. If for a given level, a formatter does not exist in
the formatter_for_level dictionary, the default formatter specified
by 'default' is used instead.
"""
Formatter.__init__(self)
self.formatter_for_level = formatter_for_level
self.default = default
示例6: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, stream, *args, **kwds):
Formatter.__init__(self, *args, **kwds)
# Create a mapping of levels to format string which is prepared to
# contain the escape sequences.
term = TerminalController(stream)
self.color_fmt = {}
for levelno, colstr in self.colordef:
slist = [getattr(term, c) for c in colstr.split()] + ['%s', term.NORMAL]
self.color_fmt[levelno] = ''.join(slist)
示例7: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self,recordfields = [], datefmt=None, customjson=None):
"""__init__ overrides the default constructor to accept a formatter specific list of metadata fields
Args:
recordfields : A list of strings referring to metadata fields on the record object. It can be empty.
The list of fields will be added to the JSON record created by the formatter.
"""
Formatter.__init__(self,None,datefmt)
self.recordfields = recordfields
self.customjson = customjson
示例8: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__ (self, format, datefmt=None, log_colors=default_log_colors, reset=True, style='%'):
"""
:Parameters:
- format (str): The format string to use
- datefmt (str): A format string for the date
- log_colors (dict): A mapping of log level names to color names
- reset (bool): Implictly appends a reset code to all records unless set to False
- style ('%' or '{' or '$'): The format style to use. No meaning prior to Python 3.2.
The ``format``, ``datefmt`` and ``style`` args are passed on to the Formatter constructor.
"""
if version_info > (3, 2):
super(ColoredFormatter, self).__init__(format, datefmt, style=style)
elif version_info > (2, 7):
super(ColoredFormatter, self).__init__(format, datefmt)
else:
Formatter.__init__(self, format, datefmt)
self.log_colors = log_colors
self.reset = reset
示例9: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, display_date=True, datefmt=None):
Formatter.__init__(self, datefmt=datefmt)
self.display_date = display_date
示例10: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self):
Formatter.__init__(self)
示例11: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, fmt=None, datefmt=None, colorize=None):
Formatter.__init__(self, fmt, datefmt)
if colorize:
self.colorize = colorize
else:
self.colorize = lambda c, s: s
示例12: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self):
Formatter.__init__(
self,
'%(colour)s[%(asctime)s][%(level)-4s] %(message)s%(end)s',
'%Y-%m-%dT%H:%M:%S'
)
示例13: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, prefix="", only_from=None):
Formatter.__init__(self)
self._info_fmt = prefix + "%(message)s"
self._fmt = prefix + "%(levelname)s (%(name)s): %(message)s"
self._only_from = only_from
示例14: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, patern):
Formatter.__init__(self, patern)
示例15: __init__
# 需要导入模块: from logging import Formatter [as 别名]
# 或者: from logging.Formatter import __init__ [as 别名]
def __init__(self, fmt=None, datefmt=None):
Formatter.__init__(self, fmt=fmt, datefmt=datefmt)
self._fmt = fmt or self.DEFAULT_FMT
self.datefmt = datefmt or self.DEFAULT_DATEFMT