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.FormatterFormatter Class for colored logging output.
- Parameters
fmt – see:
logging.Formatterdatefmt – see:
logging.Formatterstyle – see:
logging.Formattercolor – True colored output
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
References
https://gist.github.com/fonic/7e5ab76d951a2ab2d5f526a7db3e2004
https://stackoverflow.com/questions/13733552/logger-configuration-to-log-to-file-and-print-to-stdout
- __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 orstring.Templateformatting in your format string.Changed in version 3.2: Added the
styleparameter.
- format(record: logging.LogRecord) → str[source]¶
Format the specified record as text.