Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear/erase console line before logging by default #1

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading