mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 00:07:22 +00:00
24 lines
688 B
Python
24 lines
688 B
Python
import logging
|
|
|
|
|
|
class OneLineFormatter(logging.Formatter):
|
|
def format(self, record): # pragma: no cover
|
|
result = super(OneLineFormatter, self).format(record)
|
|
return result.replace("\n", "\\n")
|
|
|
|
|
|
def init_logger_with_one_line_formatter(logger):
|
|
if not logger: # pragma: no cover
|
|
return
|
|
|
|
for handler in logger.handlers:
|
|
if handler.formatter:
|
|
fmt = handler.formatter._fmt
|
|
|
|
if fmt:
|
|
fmt = fmt.replace(" %(levelname)s", " [%(levelname)s]")
|
|
|
|
handler.formatter = OneLineFormatter(fmt, handler.formatter.datefmt)
|
|
else: # pragma: no cover
|
|
handler.formatter = OneLineFormatter()
|