Skip to content

Commit

Permalink
Merge pull request #1 from DLR-KI/enhacement/clearline
Browse files Browse the repository at this point in the history
clear/erase console line before logging by default
  • Loading branch information
BeFranke authored Jul 30, 2024
2 parents 80e566b + 2fd7caf commit 3b0a3a8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dlr/ki/logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_default_logging_dict(log_filepath: Optional[str] = None, ensure_log_dir:
"formatters": {
"console_formatter": {
"class": "dlr.ki.logging.formatter.colored_console.ColoredConsoleFormatter",
"format": "[%(levelcolor)s%(levelname)-8s%(colorreset)s] %(ansi.fg.grey)s[%(name)s][%(filename)s:%(lineno)d]%(ansi.fx.reset)s %(message)s" # noqa: E501
"format": "%(clearline)s[%(levelcolor)s%(levelname)-8s%(colorreset)s] %(ansi.fg.grey)s[%(name)s][%(filename)s:%(lineno)d]%(ansi.fx.reset)s %(message)s" # noqa: E501
},
"file_formatter": {
"class": "dlr.ki.logging.formatter.term_escape_code.TermEscapeCodeFormatter",
Expand Down
2 changes: 2 additions & 0 deletions dlr/ki/logging/formatter/colored_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ansi.colour.base import Graphic as AnsiGraphic
import ansi.color as ansi
from ansi.cursor import erase_line
from copy import copy
from logging import Formatter # type: ignore [attr-defined]
from typing import Dict
Expand Down Expand Up @@ -50,5 +51,6 @@ def format(self, record):
ColoredConsoleFormatter.MAPPING["DEBUG"]
)
colored_record.colorreset = ansi.fx.reset
colored_record.clearline = erase_line() + "\r"
colored_record.__dict__.update(self.ansi_dict)
return super().format(colored_record)
2 changes: 1 addition & 1 deletion examples/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ keys=consoleFormatter,fileFormatter

[formatter_consoleFormatter]
class=dlr.ki.logging.formatter.colored_console.ColoredConsoleFormatter
format=[%(levelcolor)s%(levelname)-8s%(colorreset)s] %(ansi.fg.grey)s[%(name)s][%(filename)s:%(lineno)d]%(ansi.fx.reset)s %(message)s
format=%(clearline)s[%(levelcolor)s%(levelname)-8s%(colorreset)s] %(ansi.fg.grey)s[%(name)s][%(filename)s:%(lineno)d]%(ansi.fx.reset)s %(message)s

[formatter_fileFormatter]
class=dlr.ki.logging.formatter.term_escape_code.TermEscapeCodeFormatter
Expand Down
2 changes: 1 addition & 1 deletion examples/logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ handlers:
formatters:
console_formatter:
class: dlr.ki.logging.formatter.colored_console.ColoredConsoleFormatter
format: '[%(levelcolor)s%(levelname)-8s%(colorreset)s] %(ansi.fg.grey)s[%(name)s][%(filename)s:%(lineno)d]%(ansi.fx.reset)s %(message)s'
format: '%(clearline)s[%(levelcolor)s%(levelname)-8s%(colorreset)s] %(ansi.fg.grey)s[%(name)s][%(filename)s:%(lineno)d]%(ansi.fx.reset)s %(message)s'
file_formatter:
class: dlr.ki.logging.formatter.term_escape_code.TermEscapeCodeFormatter
format: '%(asctime)s [%(levelname)-8s] [%(name)s][%(filename)s:%(lineno)d] %(message)s'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "dlr-logging" # Required
#
# For a discussion on single-sourcing the version, see
# https://packaging.python.org/guides/single-sourcing-package-version/
version = "0.0.4.dev0" # Required
version = "0.0.5.dev0" # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down

0 comments on commit 3b0a3a8

Please sign in to comment.