mellea-logging

Guide Mellea logging with canonical fields and contextvars for thread safety.

1.8k|149|Updated Jul 31, 2025
One-click install
npx skills add https://github.com/generative-computing/mellea --skill mellea-logging
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mellea-logging
Source: https://github.com/generative-computing/mellea/tree/main/.agents/skills/mellea-logging
Command: npx skills add https://github.com/generative-computing/mellea --skill mellea-logging

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides guidance on best practices for logging in the Mellea codebase, ensuring consistency and clarity in log records.

Core Features & Use Cases

  • Logging Conventions: Defines canonical field names and reserved attribute constraints.
  • Context Injection: Shows how to use log_context for attaching identifiers and metadata.
  • Async/Thread Safety: Explains the use of contextvars.ContextVar for safe concurrent logging.
  • Use Case: When adding a new log call, reviewing a PR touching MelleaLogger, or debugging missing log fields.

Quick Start

Implement logging best practices by using MelleaLogger.get_logger() and log_context for structured logging.

Frequently Asked Questions about mellea-logging

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I ensure consistent logging practices in the Mellea codebase?

Consistent logging in the Mellea codebase requires using `MelleaLogger.get_logger()` alongside `log_context` for structured records, ensuring canonical field names and reliable async output.

What is context injection in async logging and how does it work?

Context injection in async logging attaches metadata to log records via `log_context`. It uses `contextvars.ContextVar` to maintain thread-safe contextual identifiers across concurrent operations.

How do I add structured logging with context to a new Mellea module?

To add structured logging, instantiate a logger using `MelleaLogger.get_logger()` and wrap your logic with `log_context` to attach identifiers, ensuring all emitted records contain required metadata.

Does Mellea logging support thread safety for concurrent applications?

Mellea logging supports thread safety by leveraging `contextvars.ContextVar` for context injection, preventing race conditions and ensuring isolated contextual metadata in concurrent async applications.

Why are my log fields missing when debugging a MelleaLogger implementation?

Missing log fields during MelleaLogger debugging often occur when `log_context` is not properly applied, violating canonical field name constraints and context injection best practices.