Update logging with console output format changes
"console_format_type" with "normal", "condensed", "minimal" options This sets the format of the console output, controlling the amount of detail shown. normal show log title, file, function and line number condensed show file and line number only minimal shows only timestamp, log level and message Default is normal "console_iso_precision" with "seconds", "milliseconds", "microseconds" options This sets the precision of the ISO timestamp in console logs. Default is milliseconds The timestamp output is now ISO8601 formatatted with time zone.
This commit is contained in:
@@ -11,6 +11,12 @@ from corelibs.logging_handling.log import (
|
||||
Log,
|
||||
LogParent,
|
||||
LogSettings,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_FORMAT_TYPE_CONDENSED,
|
||||
CONSOLE_FORMAT_TYPE_MINIMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
CONSOLE_ISO_TIME_SECONDS,
|
||||
CONSOLE_ISO_TIME_MICROSECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -33,6 +39,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
@@ -99,6 +107,143 @@ class TestLogSettingsParsing:
|
||||
assert log.log_settings["console_enabled"] == Log.DEFAULT_LOG_SETTINGS["console_enabled"]
|
||||
assert log.log_settings["per_run_log"] == Log.DEFAULT_LOG_SETTINGS["per_run_log"]
|
||||
|
||||
def test_parse_console_format_type_normal(self, tmp_log_path: Path):
|
||||
"""Test parsing with console_format_type set to normal"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
assert log.log_settings["console_format_type"] == CONSOLE_FORMAT_TYPE_NORMAL
|
||||
|
||||
def test_parse_console_format_type_condensed(self, tmp_log_path: Path):
|
||||
"""Test parsing with console_format_type set to condensed"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_CONDENSED,
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
assert log.log_settings["console_format_type"] == CONSOLE_FORMAT_TYPE_CONDENSED
|
||||
|
||||
def test_parse_console_format_type_minimal(self, tmp_log_path: Path):
|
||||
"""Test parsing with console_format_type set to minimal"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_MINIMAL,
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
assert log.log_settings["console_format_type"] == CONSOLE_FORMAT_TYPE_MINIMAL
|
||||
|
||||
def test_parse_console_format_type_invalid(self, tmp_log_path: Path):
|
||||
"""Test parsing with invalid console_format_type falls back to default"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_format_type": "invalid_format",
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
# Should fall back to default
|
||||
assert log.log_settings["console_format_type"] == Log.DEFAULT_LOG_SETTINGS["console_format_type"]
|
||||
|
||||
def test_parse_console_iso_precision_seconds(self, tmp_log_path: Path):
|
||||
"""Test parsing with console_iso_precision set to seconds"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_SECONDS,
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
assert log.log_settings["console_iso_precision"] == CONSOLE_ISO_TIME_SECONDS
|
||||
|
||||
def test_parse_console_iso_precision_milliseconds(self, tmp_log_path: Path):
|
||||
"""Test parsing with console_iso_precision set to milliseconds"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
assert log.log_settings["console_iso_precision"] == CONSOLE_ISO_TIME_MILLISECONDS
|
||||
|
||||
def test_parse_console_iso_precision_microseconds(self, tmp_log_path: Path):
|
||||
"""Test parsing with console_iso_precision set to microseconds"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MICROSECONDS,
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
assert log.log_settings["console_iso_precision"] == CONSOLE_ISO_TIME_MICROSECONDS
|
||||
|
||||
def test_parse_console_iso_precision_invalid(self, tmp_log_path: Path):
|
||||
"""Test parsing with invalid console_iso_precision falls back to default"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_iso_precision": "invalid_precision",
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
# Should fall back to default
|
||||
assert log.log_settings["console_iso_precision"] == Log.DEFAULT_LOG_SETTINGS["console_iso_precision"]
|
||||
|
||||
def test_parse_both_console_settings_valid(self, tmp_log_path: Path):
|
||||
"""Test parsing with both console_format_type and console_iso_precision set"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_CONDENSED,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MICROSECONDS,
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
assert log.log_settings["console_format_type"] == CONSOLE_FORMAT_TYPE_CONDENSED
|
||||
assert log.log_settings["console_iso_precision"] == CONSOLE_ISO_TIME_MICROSECONDS
|
||||
|
||||
def test_parse_both_console_settings_invalid(self, tmp_log_path: Path):
|
||||
"""Test parsing with both console settings invalid falls back to defaults"""
|
||||
settings: dict[str, Any] = {
|
||||
"console_format_type": "invalid_format",
|
||||
"console_iso_precision": "invalid_precision",
|
||||
}
|
||||
log = Log(
|
||||
log_path=tmp_log_path,
|
||||
log_name="test",
|
||||
log_settings=settings # type: ignore
|
||||
)
|
||||
|
||||
# Should fall back to defaults
|
||||
assert log.log_settings["console_format_type"] == Log.DEFAULT_LOG_SETTINGS["console_format_type"]
|
||||
assert log.log_settings["console_iso_precision"] == Log.DEFAULT_LOG_SETTINGS["console_iso_precision"]
|
||||
|
||||
|
||||
# MARK: Test Spacer Constants
|
||||
class TestSpacerConstants:
|
||||
@@ -160,6 +305,8 @@ class TestParametrized:
|
||||
("per_run_log", True, "not_bool"),
|
||||
("console_enabled", False, 123),
|
||||
("console_color_output_enabled", True, None),
|
||||
("console_format_type", CONSOLE_FORMAT_TYPE_NORMAL, "invalid_format"),
|
||||
("console_iso_precision", CONSOLE_ISO_TIME_MILLISECONDS, "invalid_precision"),
|
||||
("add_start_info", False, []),
|
||||
("add_end_info", True, {}),
|
||||
])
|
||||
|
||||
@@ -13,6 +13,8 @@ from corelibs.logging_handling.log import (
|
||||
LogParent,
|
||||
LogSettings,
|
||||
CustomConsoleFormatter,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -35,6 +37,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
@@ -169,6 +173,8 @@ class TestLogInitialization:
|
||||
"per_run_log": False,
|
||||
"console_enabled": False,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
@@ -190,6 +196,8 @@ class TestLogInitialization:
|
||||
"per_run_log": True,
|
||||
"console_enabled": False,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
@@ -256,6 +264,8 @@ class TestLogInitialization:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": True,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
|
||||
@@ -11,6 +11,8 @@ from corelibs.logging_handling.log import (
|
||||
Log,
|
||||
LogSettings,
|
||||
CustomConsoleFormatter,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -33,6 +35,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
|
||||
@@ -11,6 +11,8 @@ from corelibs.logging_handling.log import (
|
||||
Log,
|
||||
LogSettings,
|
||||
CustomHandlerFilter,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -33,6 +35,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
|
||||
@@ -11,6 +11,8 @@ from corelibs.logging_handling.log import (
|
||||
Log,
|
||||
LogParent,
|
||||
LogSettings,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -33,6 +35,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
@@ -61,6 +65,8 @@ class TestHandlerManagement:
|
||||
"per_run_log": False,
|
||||
"console_enabled": False,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
|
||||
@@ -10,6 +10,8 @@ from corelibs.logging_handling.log import (
|
||||
Log,
|
||||
Logger,
|
||||
LogSettings,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -32,6 +34,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
|
||||
@@ -10,6 +10,8 @@ import pytest
|
||||
from corelibs.logging_handling.log import (
|
||||
Log,
|
||||
LogSettings,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -32,6 +34,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
@@ -88,6 +92,8 @@ class TestEdgeCases:
|
||||
"per_run_log": False,
|
||||
"console_enabled": False,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": True, # Enable end info
|
||||
"log_queue": None,
|
||||
|
||||
@@ -12,6 +12,8 @@ import pytest
|
||||
from corelibs.logging_handling.log import (
|
||||
Log,
|
||||
LogSettings,
|
||||
CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
)
|
||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||
|
||||
@@ -34,6 +36,8 @@ def basic_log_settings() -> LogSettings:
|
||||
"per_run_log": False,
|
||||
"console_enabled": True,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": None,
|
||||
@@ -68,6 +72,8 @@ class TestQueueListener:
|
||||
"per_run_log": False,
|
||||
"console_enabled": False,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": mock_queue, # type: ignore
|
||||
@@ -103,6 +109,8 @@ class TestQueueListener:
|
||||
"per_run_log": False,
|
||||
"console_enabled": False,
|
||||
"console_color_output_enabled": False,
|
||||
"console_format_type": CONSOLE_FORMAT_TYPE_NORMAL,
|
||||
"console_iso_precision": CONSOLE_ISO_TIME_MILLISECONDS,
|
||||
"add_start_info": False,
|
||||
"add_end_info": False,
|
||||
"log_queue": mock_queue, # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user