forge.log¶
Structured JSON logging with automatic trace context propagation.
forge.log ¶
Structured logging module — JSON and human-readable log output with context propagation.
Provides a module-aware logger factory, automatic trace ID propagation via contextvars, and configurable output formats for development and production environments.
Classes¶
DevFormatter ¶
Bases: Formatter
Colorized human-readable log output for development.
Format::
[2026-06-28 12:00:00] module.name INFO message here
Source code in src/forge/log/formatters.py
JSONFormatter ¶
Bases: Formatter
Outputs structured JSON log lines for production use.
Every record produces: timestamp, level, module,
message, and optionally trace_id (if one is active).
Extra fields bound via LogContext are included at the top level.
Circular references are replaced with "<circular>" and strings
longer than 10 000 characters are truncated.
Source code in src/forge/log/formatters.py
LogContext ¶
Async-safe context manager that binds extra fields to log entries.
Usage::
with LogContext(request_id="abc-123", user="alice"):
logger.info("processing request")
# → log entry includes request_id="abc-123", user="alice"
Source code in src/forge/log/context.py
LogContextFilter ¶
Bases: Filter
Logging filter that injects LogContext fields into every record.
Attach this filter to the root logger or handler to automatically propagate contextvars-based extra fields to all log entries::
root_logger.addFilter(LogContextFilter())
Source code in src/forge/log/context.py
LogModule ¶
Bases: ForgeModule
Source code in src/forge/log/module.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
LoggerProxy ¶
Wraps a standard logging.Logger to support direct keyword arguments.
Example::
logger = log.get("module")
logger.info("user logged in", user_id=123, ip="127.0.0.1")
# → keyword arguments are merged into the structured extra fields.
Source code in src/forge/log/proxy.py
Functions:¶
get ¶
Get a module logger wrapped in LoggerProxy.
Delegates to the active runtime's LogModule if initialized, otherwise returns a default LoggerProxy.