Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Valid subsections within a version are:

Things to be included in the next release go here.

### Fixed

- Updated the logging configuration function to properly display the correct timestamp precision when using colored console logging.

---

## v3.1.6 (2025-03-11)
Expand Down
12 changes: 11 additions & 1 deletion src/tm_devices/helpers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@


class _CustomFormatterWithMicroseconds(logging.Formatter): # pragma: no cover
"""A formatter that includes microsecond precision in the timestamp."""

converter = datetime.fromtimestamp # pyright: ignore[reportAssignmentType]

def formatTime(self, record: logging.LogRecord, datefmt: str | None = None) -> str: # noqa: N802
Expand All @@ -50,9 +52,17 @@ def formatTime(self, record: logging.LogRecord, datefmt: str | None = None) -> s
return s


class _CustomFormatterWithColorAndMicroseconds(
colorlog.ColoredFormatter, _CustomFormatterWithMicroseconds
): # pragma: no cover
"""A formatter that includes color and microsecond precision in the timestamp."""


class _CustomFormatterWithPackageNameAndMicroseconds(
_CustomFormatterWithMicroseconds
): # pragma: no cover
"""A formatter that includes the package name and microsecond precision in the timestamp."""

def format(self, record: logging.LogRecord) -> str:
# Add the package name to the log record
record.package_name = record.name.split(".", maxsplit=1)[0]
Expand Down Expand Up @@ -182,7 +192,7 @@ def configure_logging( # pylint: disable=too-many-locals
if log_console_level != LoggingLevels.NONE:
if log_colored_output:
console_handler = colorlog.StreamHandler(stream=sys.stdout)
console_formatter = colorlog.ColoredFormatter(
console_formatter = _CustomFormatterWithColorAndMicroseconds(
"%(log_color)s" + logging_console_format_string,
log_colors=colorlog.default_log_colors,
)
Expand Down
Loading