autoLog, add request tags with ctx.log, and pass a custom logger only when logs need to leave stdout.
Quick Start
Enable automatic proxy logging where you declare the proxy.autoLog: true records proxied tool call start, success, and failure entries with safe context such as operation, subject, upstream server, tool, downstream transport, session id, credential source metadata, and policy outcome when available.
JSON Stdout
UsejsonConsoleLogger() when your process manager or log collector expects newline-delimited JSON on stdout.
level, message, timestamp, context, and metadata. Redaction stays enabled by default.
Add Request Tags
ctx.log is available in middleware, server routes, tool routes, operation routes, and lifecycle events. Use tags for stable fields that should be attached to every later log entry in the request.
traceId, tenantId, subject, server, and tool over free-form labels.
Use Metadata For Event Detail
Metadata should describe one log entry. Keep it structured and bounded so log queries remain predictable.Logging Levels
Use levels consistently so alerts and dashboards stay predictable.debug: noisy diagnostics for local development.info: normal operations such as successful calls and routing decisions.warn: recoverable problems, degraded behavior, and policy denies.error: failed operations that need attention.fatal: unrecoverable runtime failures.
Customize Auto Logs
Use the object form when you want to keep automatic logging but tune levels.autoLog: false or omit it when another layer already records the same lifecycle and duplicate logs would make operations harder to read.
Use A Custom Logger
Pass a logger tofentaris(...) when stdout is not the right destination.
context and metadata to the indexed fields your telemetry system expects.
Entry Shape
Custom drivers receive this shape:context comes from the logger and child loggers created by Fentaris. metadata comes from tags, annotations, and the metadata passed to each log call. Tags are stored as metadata keys prefixed with tag..
Redaction
Redaction is enabled by default. Fentaris redacts common sensitive keys such as tokens, secrets, passwords, authorization values, API keys, and credentials. It also redacts common token-shaped string values.Redis Driver
UseRedisLoggerDriver when you want Fentaris to append structured log entries to a Redis list.
Lifecycle Logs
Lifecycle events are the best place for outcome-specific logs because Fentaris has already measured the operation and knows whether it succeeded.Error Handling
When middleware catches an error, log a stable message and return a safe denial or failure response.Best Practices
- Enable
autoLogbefore adding custom entries. - Add
traceId,tenantId, andsubjecttags in middleware. - Use stable event names such as
tool.successorgithub.create_issue.completed. - Put dimensions in metadata instead of interpolating them into messages.
- Keep metric labels and log tags bounded.
- Use
warnfor policy denies and degraded behavior. - Use
errorfor failed upstream calls and runtime failures. - Forward the complete structured entry to external logging systems.