Exemple #1
0
 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)
Exemple #2
0
    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)
Exemple #3
0
    def __init__(self, coloured=False):
        fmt = "%(asctime)s %(address)s %(netns)s %(levelname)s: %(message)s"
        datefmt = "%Y-%m-%d %H:%M:%S"
        self.linefmt = "    "
        self._coloured = coloured

        Formatter.__init__(self, fmt, datefmt)
Exemple #4
0
 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)
Exemple #5
0
    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)
Exemple #6
0
 def __init__(self, *args, **kwargs):
     Formatter.__init__(self, *args, **kwargs)
     white_on_red = b'\x1b[37;1;41m'
     self.colormap = colormap = dict(
         DEBUG=b'\x1b[34m',  # blue
         INFO=b'\x1b[32m',  # green
         WARNING=b'\x1b[33;1m',  # yellow bold
         NOTE=b'\x1b[36;1m',  # cyan bold
         ERROR=b'\x1b[31;1m',  # red bold
         EXCEPT=b'\x1b[31;1m',  # red bold
         CRITICAL=white_on_red,
         FATAL=white_on_red,
         NOTSET=b'\x1b[0m',  # reset
     )
     self.icomap = icomap = dict(
         DEBUG='•',
         INFO='✓',
         WARNING='âš ',
         NOTE='★',
         ERROR='✗',
         EXCEPT='💣',
         CRITICAL='💀',
         FATAL='💀',
         NOTSET='•',
     )
     # "render" levels
     for levelname in colormap.keys():
         if levelname == 'NOTSET':
             continue
         colormap[levelname] = '%s%s %s%s' % (
             colormap.get(levelname, '').decode('ascii'),  # to str
             icomap[levelname],
             levelname,
             colormap['NOTSET'].decode('ascii'),  # to str
         )
Exemple #7
0
    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
Exemple #8
0
    def __init__(self):
        """
        Construct this formatter.
        """

        Formatter.__init__(self, VerboseFileFormatter._FORMAT,
                           VerboseFileFormatter._DATE_FORMAT)
Exemple #9
0
    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)
Exemple #10
0
    def __init__(self, fmt=None, datefmt=None, style="%", validate=True, sep="T", timespec="auto", aslocal=False):
        # type: (Optional[str], None, str, bool, str, str, bool) -> None

        Formatter.__init__(self, fmt, datefmt, style, validate)
        assert datefmt is None
        self.sep = sep
        self.timespec = timespec
        self.aslocal = aslocal
Exemple #11
0
    def __init__(self, msg, use_color=True):
        """
        Init method of 'ColoredFormatter' class.
        :param msg: The getting message.
        :param use_color: The message will be colored if it is True else it won't be colored.
        """

        Formatter.__init__(self, msg)
        self.use_color = use_color
Exemple #12
0
    def __init__(self,
                 fmt='[%(asctime)s][%(name)s]:  %(message)s',
                 datefmt='%H:%M:%S',
                 reset='\x1b[0m'):
        """ Better format defaults. Reset code can be overridden if necessary."""

        Formatter.__init__(self, fmt=fmt, datefmt=datefmt)
        self.reset = reset
        self.colormap = color_map
Exemple #13
0
    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
Exemple #14
0
    def __init__(self, stream=None):
        """
        Construct this formatter.
        """

        # construct the format string
        format = "%(message)s"

        # initialize this formatter
        Formatter.__init__(self, format, TTY_ConciseFormatter._DATE_FORMAT)
Exemple #15
0
    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)
 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
Exemple #17
0
    def __init__(self, stream=None):
        """
        Construct this formatter.
        """

        # construct the format string
        format = "%(message)s"

        # initialize this formatter
        Formatter.__init__(self, format, TTY_ConciseFormatter._DATE_FORMAT)
Exemple #18
0
    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
Exemple #19
0
 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
Exemple #20
0
    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
Exemple #21
0
 def __init__(self):
     Formatter.__init__(
         self,
         fmt=TRACED_LOG_FORMAT,
         datefmt=DATE_FORMAT,
     )
     self.control_formmater = Formatter(SERVICE_LOG_FORMAT,
                                        datefmt=DATE_FORMAT)
     self.trace_formatter = Formatter(TRACED_LOG_FORMAT,
                                      datefmt=DATE_FORMAT)
Exemple #22
0
    def __init__(self, format=None, datefmt=None, colorize=False, colors=None):
        Formatter.__init__(self, fmt=format, datefmt=datefmt)
        cremepath = dirname(__file__)[:-len(join('creme', 'creme_core'))]

        self.prefixes = [
            ('', cremepath),
            *(('python-packages', path) for path in syspath),
        ]

        self.colorize = 'colored' in format
        self.colors = {**self._COLORS}

        if colors is not None:
            for key, color in colors.items():
                self.colors[getLevelName(key)] = color
Exemple #23
0
    def __init__(self, fmt=None, datefmt=None, colorfmt=None, style="%"):
        if sys.version_info > (3, 2):
            super(BaseColorFormatter, self).__init__(
                fmt=fmt, datefmt=datefmt, style=style)
        elif sys.version_info > (2, 7):
            super(BaseColorFormatter, self).__init__(fmt, datefmt)
        else:
            Formatter.__init__(self, fmt, datefmt)

        self.style = style
        if sys.version_info > (3, 2):
            if self.style not in logging._STYLES:
                raise ValueError('Style must be one of: %s' % ','.join(
                        logging._STYLES.keys()))

        self.colorfmt = colorfmt
Exemple #24
0
 def __init__(self, fmt=None, datefmt=DATEFORMAT, style='{', usecolor=True):
     if PY2:
         if fmt is None:
             fmt, style = '{message}', '{'
         if style not in '%{':
             raise ValueError('Style must be one of: `%`, `{`')
         self._style = style
         Formatter.__init__(self, ensure_unicode(fmt), datefmt)
     else:
         Formatter.__init__(self, fmt, datefmt, style)
     self._usecolor = usecolor
     if self._usecolor:
         if 'start' not in self._fmt:
             self._fmt = '{start}' + self._fmt
         if 'reset' not in self._fmt:
             self._fmt += '{reset}'
Exemple #25
0
    def __init__(self, fmt=None, datefmt=None, cmd=None):
        ''' Initialise the `PfxFormatter`.

        Parameters:
        * `fmt`: format template,
          default from `DEFAULT_PFX_FORMAT` `{DEFAULT_PFX_FORMAT!r}`.
          Passed through to `Formatter.__init__`.
        * `datefmt`:
          Passed through to `Formatter.__init__`.
        * `cmd`: the "command prefix" made available to format strings.
          If not set, `cs.pfx.cmd` is presented.
    '''
        if fmt is None:
            fmt = DEFAULT_PFX_FORMAT
        self.cmd = cmd
        Formatter.__init__(self, fmt=fmt, datefmt=datefmt)
	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
Exemple #27
0
    def __init__(self, fmt, **kwargs):
        if (kwargs["style"] != "$"):
            # Only Templates support partial substitution, which this formatter needs. Templates use $ style syntax:
            raise ValueError(
                "Only style='$' is supported because this formatter uses String Templates"
            )

        Formatter.__init__(self, fmt, **kwargs)
        # To try and keep performant we don't want to over-complicate our format() with Python logic, so the easiest
        # way is just to create a pool of different formatters per log level:
        tFmt = Template(fmt)
        self.formatters = {
            level: Formatter(
                tFmt.safe_substitute({
                    "levelname":
                    color(LEVELS[level]["name"],
                          fg=LEVELS[level].get("fg"),
                          bg=LEVELS[level].get("bg"))
                }), **kwargs)
            for level in LEVELS
        }
Exemple #28
0
 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
Exemple #29
0
 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
Exemple #30
0
 def __init__(self, use_color: bool = True, datefmt: str = None):
     msg = formatter_message(use_color)
     Formatter.__init__(self, msg, datefmt=datefmt)
     self.use_color = use_color
Exemple #31
0
 def __init__(self, *args, **kwargs):
     """Initialize formatter."""
     Formatter.__init__(self, *args, **kwargs)
     standard_formatters = re.compile(r'\((.+?)\)', re.IGNORECASE)
     self._fields = standard_formatters.findall(self._fmt)
 def __init__(self, patern):
     Formatter.__init__(self, patern)
Exemple #33
0
 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
Exemple #34
0
 def __init__(self):
     Formatter.__init__(self, u'%(levelname)s: %(message)s '
                              u'— %(module)s:%(lineno)d')
Exemple #35
0
 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
Exemple #36
0
 def __init__(self, fmt):
     Formatter.__init__(self, fmt)
Exemple #37
0
 def __init__(self, patern):
     Formatter.__init__(self, patern)
     self.colored_log = "{prefix}{{color}}m{{msg}}{suffix}".format(
         prefix=self.COLOR_PREFIX, suffix=self.COLOR_SUFFIX)
Exemple #38
0
 def __init__(self):
     Formatter.__init__(self, u'%(levelname)s: %(message)s')
Exemple #39
0
 def __init__(self, display_date=True, datefmt=None):
     Formatter.__init__(self, datefmt=datefmt)
     self.display_date = display_date
 def __init__(self, app, template_name=None, template_string=None):
     Formatter.__init__(self)
     self.app = app
     self.template_name = template_name
     self.template_string = template_string
     self._template = None
Exemple #41
0
 def __init__(self):
     Formatter.__init__(self, u'%(levelname)s: %(message)s')
Exemple #42
0
 def __init__(self):
     Formatter.__init__(
         self, u'%(levelname)s: %(message)s '
         u'— %(module)s:%(lineno)d')
Exemple #43
0
 def __init__(self, **kwargs):
     Formatter.__init__(self, kwargs)
Exemple #44
0
 def __init__(self):
     Formatter.__init__(
         self,
         '%(colour)s[%(asctime)s][%(level)-4s] %(message)s%(end)s',
         '%Y-%m-%dT%H:%M:%S'
     )
Exemple #45
0
    def __init__(self):
        """
        Construct this formatter.
        """

        Formatter.__init__(self, VerboseFileFormatter._FORMAT, VerboseFileFormatter._DATE_FORMAT)
Exemple #46
0
 def __init__(self, *args, **kwargs):
     """Initialize formatter."""
     Formatter.__init__(self, *args, **kwargs)
     self._fields = _FIELDS.findall(self._fmt)
Exemple #47
0
 def __init__(self):
     Formatter.__init__(self)
Exemple #48
0
 def __init__(self, patern):
     Formatter.__init__(self, patern)
Exemple #49
0
 def __init__(self, fmt=None, datefmt=None):
     Formatter.__init__(self, fmt, datefmt)
     self.library_abspath = get_library_abspath()