2. mrdevtools - hilfsmittel

Hilfmittel zum entwickeln.

Module author: Michael Rippstein <info@anatas.ch>

2.1. mrdevtools.logtools erweiterungen zum modul logging

class mrdevtools.logtools.LogColorFormatter(*, fmt: Optional[str] = None, datefmt: Optional[str] = None, style: str = '%', color: bool = False)[source]

Bases: logging.Formatter

Formatter Class for colored logging output.

Parameters

Examples

colorama.init()

console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO)
console_formatter = LogColorFormatter(
  fmt="%(color_on)s[%(levelname)-8s]%(color_off)s %(message)s",
  color=True
)
console_handler.setFormatter(console_formatter)

logging.basicConfig(format="%(asctime)s [%(levelname)-8s] %(message)s",
                    level=logging.INFO,
                    handlers=[
                        logging.FileHandler("cpds.log"),
                        console_handler
                    ],
                    )

See also

logging

References

__init__(*, fmt: Optional[str] = None, datefmt: Optional[str] = None, style: str = '%', color: bool = False)None[source]

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.

format(record: logging.LogRecord)str[source]

Format the specified record as text.