Skip to content

Commit

Permalink
Updated logger color mapping for DEBUG level and changed version to 2…
Browse files Browse the repository at this point in the history
….0.1; added comprehensive test log for enhanced logging validation
  • Loading branch information
sexfrance committed Nov 10, 2024
1 parent bf85881 commit 2182921
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 5 additions & 3 deletions logmagix/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ def _log(self, level: LogLevel, message: str, start: int = None, end: int = None
if not self._should_log(level):
return

# Map log levels to colors and display names
level_colors = {
LogLevel.DEBUG: self.BLUE,
LogLevel.DEBUG: self.YELLOW,
LogLevel.INFO: self.CYAN,
LogLevel.WARNING: self.YELLOW,
LogLevel.SUCCESS: self.GREEN,
Expand All @@ -122,7 +121,10 @@ def _log(self, level: LogLevel, message: str, start: int = None, end: int = None
}

color = level_colors.get(level, self.WHITE)
formatted_message = self.message3(f"{color}{level.name}", f"{color}{message}", start, end)
if level == LogLevel.DEBUG:
formatted_message = self.message3(f"{color}{level.name}", f"{self.GREEN}{message}", start, end)
else:
formatted_message = self.message3(f"{color}{level.name}", f"{color}{message}", start, end)

with self.log_lock:
print(formatted_message)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="logmagix",
version="2.0.0",
version="2.0.1",
packages=find_packages(),
install_requires=["colorama"],
author="Sexfrance",
Expand Down
18 changes: 18 additions & 0 deletions test.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
2024-11-10 10:43:16,424 - DEBUG - [TestLogger] [10:43:16] [INFO] -> Starting test suite
2024-11-10 10:43:16,424 - NOTSET - [TestLogger] [10:43:16] [DEBUG] -> Debug information
2024-11-10 10:43:16,424 - INFO - [TestLogger] [10:43:16] [WARNING] -> Warning message
2024-11-10 10:43:16,425 - WARNING - [TestLogger] [10:43:16] [SUCCESS] -> Success message
2024-11-10 10:43:16,425 - ERROR - [TestLogger] [10:43:16] [ERROR] -> Failure message
2024-11-10 10:43:16,425 - DEBUG - [TestLogger] [10:43:16] [INFO] -> Testing log level filtering...
2024-11-10 10:43:16,427 - INFO - [TestLogger] [10:43:16] [WARNING] -> This warning message should appear
2024-11-10 10:43:16,427 - WARNING - [TestLogger] [10:43:16] [SUCCESS] -> This success message should appear
2024-11-10 10:43:16,427 - ERROR - [TestLogger] [10:43:16] [ERROR] -> This error message should appear
2024-11-10 10:43:16,428 - DEBUG - [TestLogger] [10:43:16] [INFO] -> Testing batch logging...
2024-11-10 10:43:16,428 - DEBUG - [TestLogger] [10:43:16] [INFO] -> Batch message 1
2024-11-10 10:43:16,428 - WARNING - [TestLogger] [10:43:16] [SUCCESS] -> Batch success 1
2024-11-10 10:43:16,429 - INFO - [TestLogger] [10:43:16] [WARNING] -> Batch warning 1
2024-11-10 10:43:16,429 - ERROR - [TestLogger] [10:43:16] [ERROR] -> Batch failure 1
2024-11-10 10:43:16,929 - DEBUG - [TestLogger] [10:43:16] [INFO] -> Batch message 2
2024-11-10 10:43:16,929 - WARNING - [TestLogger] [10:43:16] [SUCCESS] -> Batch success 2
2024-11-10 10:43:16,929 - INFO - [TestLogger] [10:43:16] [WARNING] -> Batch warning 2
2024-11-10 10:43:16,929 - ERROR - [TestLogger] [10:43:16] [ERROR] -> Batch failure 2

0 comments on commit 2182921

Please sign in to comment.