Skip to content
Open
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
14 changes: 11 additions & 3 deletions llama_stack/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# Default log level
DEFAULT_LOG_LEVEL = logging.INFO
DEFAULT_TELEMETRY_LEVEL = logging.WARN

# Predefined categories
CATEGORIES = [
Expand All @@ -35,8 +36,10 @@
"openai_responses",
]

# Initialize category levels with default level
_category_levels: dict[str, int] = dict.fromkeys(CATEGORIES, DEFAULT_LOG_LEVEL)
# Initialize category levels with default level, except for telemetry which gets WARN
_category_levels: dict[str, int] = {
category: DEFAULT_TELEMETRY_LEVEL if category == "telemetry" else DEFAULT_LOG_LEVEL for category in CATEGORIES
}


def config_to_category_levels(category: str, level: str):
Expand Down Expand Up @@ -99,6 +102,7 @@ def parse_environment_config(env_config: str) -> dict[str, int]:
Returns:
Dict[str, int]: A dictionary mapping categories to their log levels.
"""

category_levels = {}
delimiter = ","
for pair in env_config.split(delimiter):
Expand Down Expand Up @@ -193,6 +197,7 @@ def filter(self, record):
"filename": log_file,
"mode": "a",
"encoding": "utf-8",
"filters": ["category_filter"],
}

logging_config = {
Expand All @@ -213,7 +218,9 @@ def filter(self, record):
"loggers": {
category: {
"handlers": list(handlers.keys()), # Apply all handlers
"level": category_levels.get(category, DEFAULT_LOG_LEVEL),
"level": category_levels.get(
category, (DEFAULT_LOG_LEVEL if category != "telemetry" else DEFAULT_TELEMETRY_LEVEL)
),
"propagate": False, # Disable propagation to root logger
}
for category in CATEGORIES
Expand All @@ -237,6 +244,7 @@ def get_logger(
"""
Returns a logger with the specified name and category.
If no category is provided, defaults to 'uncategorized'.
Note: telemetry category defaults to WARN as the default level

Parameters:
name (str): The name of the logger (e.g., module or filename).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def __init__(self, print_attributes: bool = False):
self.print_attributes = print_attributes

def on_start(self, span: ReadableSpan, parent_context=None) -> None:
if span.attributes and span.attributes.get("__autotraced__"):
return

timestamp = datetime.fromtimestamp(span.start_time / 1e9, tz=UTC).strftime("%H:%M:%S.%f")[:-3]
logger.info(f"[dim]{timestamp}[/dim] [bold magenta][START][/bold magenta] [dim]{span.name}[/dim]")

Expand Down
Loading