Esempio n. 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)
Esempio n. 2
0
File: Logs.py Progetto: pazdera/lnst
    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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
         )
Esempio n. 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
Esempio n. 8
0
    def __init__(self):
        """
        Construct this formatter.
        """

        Formatter.__init__(self, VerboseFileFormatter._FORMAT,
                           VerboseFileFormatter._DATE_FORMAT)
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 16
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
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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}'
Esempio n. 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)
Esempio n. 26
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
Esempio n. 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
        }
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 32
0
 def __init__(self, patern):
     Formatter.__init__(self, patern)
Esempio n. 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
Esempio n. 34
0
 def __init__(self):
     Formatter.__init__(self, u'%(levelname)s: %(message)s '
                              u'— %(module)s:%(lineno)d')
Esempio n. 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
Esempio n. 36
0
File: util.py Progetto: fl4p/tescan
 def __init__(self, fmt):
     Formatter.__init__(self, fmt)
Esempio n. 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)
Esempio n. 38
0
 def __init__(self):
     Formatter.__init__(self, u'%(levelname)s: %(message)s')
Esempio n. 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
Esempio n. 41
0
 def __init__(self):
     Formatter.__init__(self, u'%(levelname)s: %(message)s')
Esempio n. 42
0
 def __init__(self):
     Formatter.__init__(
         self, u'%(levelname)s: %(message)s '
         u'— %(module)s:%(lineno)d')
Esempio n. 43
0
 def __init__(self, **kwargs):
     Formatter.__init__(self, kwargs)
Esempio n. 44
0
 def __init__(self):
     Formatter.__init__(
         self,
         '%(colour)s[%(asctime)s][%(level)-4s] %(message)s%(end)s',
         '%Y-%m-%dT%H:%M:%S'
     )
Esempio n. 45
0
    def __init__(self):
        """
        Construct this formatter.
        """

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