textmate_grammar.utils.logger#

Module Contents#

Classes#

LogFormatter

A custom log formatter that formats log records with color-coded messages.

Logger

The logger object for the grammar parsers.

Functions#

track_depth

Simple decorator to track recusion depth.

Data#

API#

textmate_grammar.utils.logger.MAX_LENGTH = 79#
textmate_grammar.utils.logger.track_depth(func)#

Simple decorator to track recusion depth.

class textmate_grammar.utils.logger.LogFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)#

Bases: logging.Formatter

A custom log formatter that formats log records with color-coded messages.

Initialization

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

green = '\x1b[32;32m'#
grey = '\x1b[38;20m'#
yellow = '\x1b[33;20m'#
red = '\x1b[31;20m'#
bold_red = '\x1b[31;1m'#
reset = '\x1b[0m'#
format_string = '%(name)s:%(message)s'#
FORMATS = None#
format(record)#

Formats the log record with the color-coded format based on the log level.

Parameters:

record – The log record to be formatted.

Returns:

The formatted log message.

class textmate_grammar.utils.logger.Logger(**kwargs)#

The logger object for the grammar parsers.

Initialization

long_msg_div = '\x1b[1;32m ... \x1b[0m'#
configure(parser: textmate_grammar.parser.GrammarParser, height: int, width: int, **kwargs) None#

Configures the logger to a specific grammar and content length

format_message(message: str, parser: Optional[textmate_grammar.parser.GrammarParser] = None, position: tuple[int, int] | None = None, depth: int = 0) str#

Formats a logging message to the defined format.

Parameters:
  • message – The logging message to be formatted.

  • parser – The GrammarParser object associated with the message. Defaults to None.

  • position – The position tuple (line, column) associated with the message. Defaults to None.

  • depth – The depth of the message in the logging hierarchy. Defaults to 0.

Returns:

The formatted logging message.

debug(*args, **kwargs) None#
info(*args, **kwargs) None#
warning(*args, **kwargs) None#
error(*args, **kwargs) None#
critical(*args, **kwargs) None#
textmate_grammar.utils.logger.LOGGER = 'Logger(...)'#