skills/logging-python/SKILL.md
Configure structured logging with structlog for Python FastAPI applications. Covers processor pipelines, context variables, correlation IDs, log levels, sensitive data filtering, and JSON formatting. Use when: setting up structlog, configuring log output, adding context vars, filtering sensitive data, or troubleshooting logging issues in Python.
npx skillsauth add congiuluc/my-awesome-copilot logging-pythonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
bind() and event kwargs.structlog.contextvars for per-request context.| Level | Use When | Examples |
|-------|----------|---------|
| debug | Developer diagnostics | Cache hit/miss, config loaded, request parsed |
| info | Normal operations | Request started, user logged in, order created |
| warning | Expected but notable | Not found, validation failed, slow query |
| error | Unexpected failures | Unhandled exceptions, external service down |
| critical | App cannot continue | Database unreachable, startup failure |
import structlog
logger = structlog.get_logger()
# ✅ Good — structured with key-value pairs
logger.info("order_created", order_id=order_id, user_id=user_id)
# ✅ Good — with bound context
log = logger.bind(order_id=order_id)
log.info("processing_order")
log.info("order_shipped", tracking="ABC123")
# ❌ Bad — f-string formatting destroys structure
logger.info(f"Order {order_id} created for user {user_id}")
import structlog
import logging
def configure_logging(json_output: bool = False) -> None:
"""Configure structlog with appropriate processors."""
shared_processors: list[structlog.types.Processor] = [
structlog.contextvars.merge_contextvars,
structlog.stdlib.add_log_level,
structlog.stdlib.add_logger_name,
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.UnicodeDecoder(),
_filter_sensitive_keys,
]
if json_output:
shared_processors.append(structlog.processors.JSONRenderer())
else:
shared_processors.append(structlog.dev.ConsoleRenderer())
structlog.configure(
processors=shared_processors,
wrapper_class=structlog.stdlib.BoundLogger,
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
cache_logger_on_first_use=True,
)
logging.basicConfig(format="%(message)s", level=logging.INFO)
import uuid
from contextvars import ContextVar
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.requests import Request
from starlette.responses import Response
import structlog
correlation_id_var: ContextVar[str] = ContextVar("correlation_id", default="")
class CorrelationIdMiddleware(BaseHTTPMiddleware):
async def dispatch(
self, request: Request, call_next: RequestResponseEndpoint
) -> Response:
correlation_id = request.headers.get(
"X-Correlation-ID", str(uuid.uuid4())
)
correlation_id_var.set(correlation_id)
structlog.contextvars.bind_contextvars(correlation_id=correlation_id)
response = await call_next(request)
response.headers["X-Correlation-ID"] = correlation_id
structlog.contextvars.unbind_contextvars("correlation_id")
return response
_SENSITIVE_KEYS = {"password", "token", "secret", "api_key", "authorization", "credit_card"}
def _filter_sensitive_keys(
logger: structlog.types.WrappedLogger,
method_name: str,
event_dict: structlog.types.EventDict,
) -> structlog.types.EventDict:
for key in list(event_dict.keys()):
if key.lower() in _SENSITIVE_KEYS:
event_dict[key] = "***REDACTED***"
return event_dict
tools
Build VS Code extensions with TypeScript. Covers extension anatomy, activation events, commands, tree views, webview panels, language features, testing, and publishing. Use when: creating a new VS Code extension, adding commands/views/providers, building webview UIs, implementing language server features, testing extensions, or packaging for the marketplace.
development
Track implementations, features, bugs, and releases in a versioning document. Use when: adding a commit, completing a feature, fixing a bug, or preparing a release. Automatically updates CHANGELOG.md following Keep a Changelog format and Semantic Versioning.
development
Write frontend tests using Vitest and React Testing Library. Use when: testing React components, hooks, user interactions, form submissions, accessibility assertions, or mocking API services.
development
Write Angular frontend tests using Jasmine, Karma, and Angular TestBed. Use when: testing Angular components, services, pipes, directives, user interactions, form submissions, accessibility assertions, or mocking HTTP services.