ColourizedFormatter
faststream.log.formatter.ColourizedFormatter #
ColourizedFormatter(
fmt: Optional[str] = None,
datefmt: Optional[str] = None,
style: Literal["%", "{", "$"] = "%",
use_colors: Optional[bool] = None,
)
Bases: Formatter
A class to format log messages with colorized level names.
METHOD | DESCRIPTION |
---|---|
__init__ | Initialize the formatter with specified format strings. |
color_level_name | Colorize the level name based on the log level. |
formatMessage | Format the log record message with colorized level name. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
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, :meth:str.format
({}
) formatting or :class:string.Template
formatting in your format string.
Source code in faststream/log/formatter.py
level_name_colors class-attribute
instance-attribute
#
level_name_colors: DefaultDict[
str, Callable[[str], str]
] = defaultdict(
lambda: str,
**{
str(logging.DEBUG): lambda: click.style(
str(level_name), fg="cyan"
),
str(logging.INFO): lambda: click.style(
str(level_name), fg="green"
),
str(logging.WARNING): lambda: click.style(
str(level_name), fg="yellow"
),
str(logging.ERROR): lambda: click.style(
str(level_name), fg="red"
),
str(logging.CRITICAL): lambda: click.style(
str(level_name), fg="bright_red"
),
}
)
color_level_name #
Returns the colored level name.
PARAMETER | DESCRIPTION |
---|---|
level_name | The name of the level. TYPE: |
level_no | The number of the level. TYPE: |
RETURNS | DESCRIPTION |
---|---|
str | The colored level name. |
RAISES | DESCRIPTION |
---|---|
KeyError | If the level number is not found in the level name colors dictionary. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/log/formatter.py
formatMessage #
Formats the log message.
PARAMETER | DESCRIPTION |
---|---|
record | The log record to format. TYPE: |
RETURNS | DESCRIPTION |
---|---|
str | The formatted log message. TYPE: |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)