salvob
salvob

Reputation: 1370

Logging python change log level text

with the library

import logging

when I use the method .error(text) or .warning(text), the logger writes the log level as INFO, WARNING, ERROR, etc.

I was wondering if there is a way to change the WARNING string, for example, to WARN (and change ERROR as ERR, instead).

TLDR; I want to change the Text logging level for the message ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL') in whatever I like... Is there a way to do that?

Upvotes: 4

Views: 727

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148965

That comes out of the box in the logging module, with the addLevelName function:

logging.addLevelName(logging.WARNING, "WARN")
logging.addLevelName(logging.ERROR, "ERR")

Those name will be used by all the formatters.

Upvotes: 5

Related Questions