first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import sys
|
||||
import logging
|
||||
import os
|
||||
from src.constants import LOG_FORMAT, LOG_TIMESTAMP_FORMAT, ENV_LAUNCHER_LOG_LEVEL
|
||||
|
||||
COLORS = {
|
||||
"DEBUG": "\033[34m", # blue
|
||||
"INFO": "\033[32m", # green
|
||||
"WARNING": "\033[33m", # yellow
|
||||
"ERROR": "\033[31m", # red
|
||||
"CRITICAL": "\033[31m", # red
|
||||
}
|
||||
|
||||
RESET = "\033[0m"
|
||||
|
||||
|
||||
class ColorFormatter(logging.Formatter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.use_colors = os.getenv("NO_COLOR") is None
|
||||
|
||||
# When started by launcher, log level and timestamp are handled by launcher.
|
||||
self.short_form = not sys.stdout.isatty()
|
||||
|
||||
def format(self, record):
|
||||
if self.short_form:
|
||||
return record.getMessage()
|
||||
|
||||
formatted = super().format(record)
|
||||
|
||||
if not self.use_colors:
|
||||
return formatted
|
||||
|
||||
parts = formatted.split("\t")
|
||||
|
||||
if len(parts) >= 3:
|
||||
timestamp = parts[0]
|
||||
level = parts[1]
|
||||
message = " ".join(parts[2:])
|
||||
|
||||
level_color = COLORS.get(record.levelname, "")
|
||||
if level_color:
|
||||
level = level_color + level + RESET
|
||||
message = level_color + message + RESET
|
||||
|
||||
formatted = f"{timestamp} {level} {message}"
|
||||
|
||||
return formatted
|
||||
|
||||
|
||||
def setup_logging():
|
||||
logger = logging.getLogger()
|
||||
|
||||
log_level_str = os.getenv(ENV_LAUNCHER_LOG_LEVEL, "INFO").upper()
|
||||
log_level = getattr(logging, log_level_str, logging.INFO)
|
||||
logger.setLevel(log_level)
|
||||
|
||||
stream_handler = logging.StreamHandler(sys.stdout)
|
||||
stream_handler.setFormatter(ColorFormatter(LOG_FORMAT, LOG_TIMESTAMP_FORMAT))
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
# Hardcoded to INFO as websocket logs are too verbose
|
||||
logging.getLogger("websockets.client").setLevel(logging.INFO)
|
||||
logging.getLogger("websockets.server").setLevel(logging.INFO)
|
||||
logging.getLogger("websockets").setLevel(logging.INFO)
|
||||
Reference in New Issue
Block a user