Skip to content

Commit 6fb8bc0

Browse files
committed
Dulled the color of less important messages
1 parent 4617e67 commit 6fb8bc0

File tree

4 files changed

+108
-24
lines changed

4 files changed

+108
-24
lines changed

CHANGELOG.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to LocalLab will be documented in this file.
44

5+
## [0.5.3] - 2024-04-30
6+
7+
### Improved
8+
9+
- Implemented intelligent log coloring that uses subdued colors for routine logs
10+
- Added smart detection of important log messages to highlight critical information
11+
- Enhanced visual focus on banners and important messages by de-emphasizing routine logs
12+
- Added special handling for ngrok and uvicorn logs to make them even more subdued
13+
- Created a comprehensive pattern matching system to identify and highlight important logs
14+
- Improved overall readability by reducing visual noise from routine log messages
15+
- Completely redesigned the LocalLab ASCII art logo with a modern, aesthetically pleasing look
16+
- Created beautiful boxed status indicators for both INITIALIZING and RUNNING states
17+
- Enhanced visual hierarchy with prominent logo and clear status indicators
18+
- Added detailed bullet points in status boxes for better user guidance
19+
- Standardized the formatting of server details and ngrok tunnel information boxes
20+
- Improved overall visual consistency across all UI elements
21+
- Made server status much easier to distinguish at a glance
22+
523
## [0.5.2] - 2024-04-30
624

725
### Fixed
@@ -14,16 +32,6 @@ All notable changes to LocalLab will be documented in this file.
1432
- Added proper cleanup of existing handlers before adding new ones
1533
- Improved compatibility with different terminal environments
1634

17-
### Improved
18-
19-
- Completely redesigned the LocalLab ASCII art logo with a modern, aesthetically pleasing look
20-
- Created beautiful boxed status indicators for both INITIALIZING and RUNNING states
21-
- Enhanced visual hierarchy with prominent logo and clear status indicators
22-
- Added detailed bullet points in status boxes for better user guidance
23-
- Standardized the formatting of server details and ngrok tunnel information boxes
24-
- Improved overall visual consistency across all UI elements
25-
- Made server status much easier to distinguish at a glance
26-
2735
## [0.5.1] - 2024-04-21
2836

2937
### Added

locallab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
LocalLab - A lightweight AI inference server for running LLMs locally
33
"""
44

5-
__version__ = "0.5.2" # Updated to match setup.py
5+
__version__ = "0.5.3" # Updated to match setup.py
66

77
# Only import what's necessary initially, lazy-load the rest
88
from .logger import get_logger

locallab/logger/__init__.py

Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import sys
77
import os
8+
import re
89
from colorama import Fore, Style, init as colorama_init
910

1011
# Initialize colorama with autoreset
@@ -48,20 +49,95 @@ def supports_color():
4849
# Use color only if supported
4950
USE_COLOR = supports_color()
5051

52+
# Define subdued colors for less important logs
53+
class Colors:
54+
# Bright colors for important messages
55+
BRIGHT_CYAN = Fore.CYAN
56+
BRIGHT_GREEN = Fore.GREEN
57+
BRIGHT_YELLOW = Fore.YELLOW
58+
BRIGHT_RED = Fore.RED
59+
60+
# Subdued colors for regular logs
61+
SUBDUED_DEBUG = Fore.BLUE + Style.DIM # Dimmed blue for debug
62+
SUBDUED_INFO = Fore.WHITE + Style.DIM # Dimmed white for info
63+
SUBDUED_WARNING = Fore.YELLOW + Style.DIM # Dimmed yellow for warnings
64+
SUBDUED_ERROR = Fore.RED + Style.DIM # Dimmed red for errors
65+
66+
# Reset
67+
RESET = Style.RESET_ALL
68+
69+
# Patterns for important log messages that should stand out
70+
IMPORTANT_PATTERNS = [
71+
# Server status messages
72+
r'Server status changed to',
73+
r'SERVER (READY|STARTING)',
74+
r'Starting server on port',
75+
r'Server startup',
76+
r'Application startup complete',
77+
78+
# Model-related messages
79+
r'Model loaded',
80+
r'Loading model',
81+
r'Model configuration',
82+
83+
# Error and warning messages
84+
r'Error',
85+
r'Exception',
86+
r'Failed',
87+
r'CRITICAL',
88+
r'WARNING',
89+
90+
# Ngrok-related messages
91+
r'NGROK TUNNEL ACTIVE',
92+
r'Ngrok tunnel established',
93+
94+
# Other important messages
95+
r'FastAPI application startup',
96+
r'HuggingFace token',
97+
r'SERVER READY',
98+
r'INITIALIZING'
99+
]
100+
101+
# Compiled regex patterns for performance
102+
IMPORTANT_REGEX = [re.compile(pattern, re.IGNORECASE) for pattern in IMPORTANT_PATTERNS]
103+
51104
# Define formatters
52-
class ColoredFormatter(logging.Formatter):
53-
"""Formatter that adds colors to log messages"""
54-
FORMATS = {
55-
logging.DEBUG: f'{Fore.CYAN}%(asctime)s - %(name)s - %(levelname)s - %(message)s{Style.RESET_ALL}',
56-
logging.INFO: f'{Fore.GREEN}%(asctime)s - %(name)s - %(levelname)s - %(message)s{Style.RESET_ALL}',
57-
logging.WARNING: f'{Fore.YELLOW}%(asctime)s - %(name)s - %(levelname)s - %(message)s{Style.RESET_ALL}',
58-
logging.ERROR: f'{Fore.RED}%(asctime)s - %(name)s - %(levelname)s - %(message)s{Style.RESET_ALL}',
59-
logging.CRITICAL: f'{Fore.RED}{Style.BRIGHT}%(asctime)s - %(name)s - %(levelname)s - %(message)s{Style.RESET_ALL}'
60-
}
105+
class SubduedColoredFormatter(logging.Formatter):
106+
"""Formatter that adds subdued colors to regular logs and bright colors to important logs"""
61107

62108
def format(self, record):
63-
log_format = self.FORMATS.get(record.levelno)
64-
formatter = logging.Formatter(log_format)
109+
# Check if this is an important message that should stand out
110+
is_important = False
111+
112+
# Check message content against important patterns
113+
if hasattr(record, 'msg') and isinstance(record.msg, str):
114+
for pattern in IMPORTANT_REGEX:
115+
if pattern.search(record.msg):
116+
is_important = True
117+
break
118+
119+
# Special case for certain types of logs - make them very subdued
120+
is_ngrok_log = hasattr(record, 'name') and record.name.startswith('pyngrok')
121+
is_uvicorn_log = hasattr(record, 'name') and record.name.startswith('uvicorn')
122+
123+
# Determine the appropriate color based on log level and importance
124+
if is_ngrok_log or is_uvicorn_log:
125+
# Make ngrok and uvicorn logs very subdued (dark gray)
126+
color = Fore.BLACK + Style.BRIGHT # This creates a dark gray color on most terminals
127+
elif record.levelno == logging.DEBUG:
128+
color = Colors.BRIGHT_CYAN if is_important else Colors.SUBDUED_DEBUG
129+
elif record.levelno == logging.INFO:
130+
color = Colors.BRIGHT_GREEN if is_important else Colors.SUBDUED_INFO
131+
elif record.levelno == logging.WARNING:
132+
color = Colors.BRIGHT_YELLOW if is_important else Colors.SUBDUED_WARNING
133+
elif record.levelno >= logging.ERROR: # ERROR and CRITICAL
134+
color = Colors.BRIGHT_RED # Always use bright red for errors
135+
else:
136+
color = Colors.SUBDUED_INFO # Default
137+
138+
# Format with the appropriate color
139+
formatted_message = f'{color}%(asctime)s - %(name)s - %(levelname)s - %(message)s{Colors.RESET}'
140+
formatter = logging.Formatter(formatted_message)
65141
return formatter.format(record)
66142

67143
# Plain formatter without colors
@@ -86,7 +162,7 @@ def configure_root_logger():
86162
handler = logging.StreamHandler(sys.stdout)
87163

88164
if USE_COLOR:
89-
handler.setFormatter(ColoredFormatter())
165+
handler.setFormatter(SubduedColoredFormatter())
90166
else:
91167
handler.setFormatter(plain_formatter)
92168

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
setup(
4949
name="locallab",
50-
version="0.5.2",
50+
version="0.5.3",
5151
packages=find_packages(include=["locallab", "locallab.*"]),
5252
install_requires=install_requires,
5353
extras_require={

0 commit comments

Comments
 (0)