@@ -147,6 +147,40 @@ This would produce a log entry like:
147147
148148See :ref: `context ` for full documentation on storing and managing context data.
149149
150+ .. _logging-per-call-context :
151+
152+ Per-Call Context Logging
153+ ------------------------
154+
155+ .. versionadded :: 4.8.0
156+
157+ By default, context values passed to ``log_message() `` are only used for placeholder
158+ interpolation and are not stored anywhere. You can enable structured context logging
159+ by setting ``$logContext = true `` in **app/Config/Logger.php **:
160+
161+ .. literalinclude :: logging/009.php
162+
163+ When enabled, any context key that is **not ** referenced as a ``{placeholder} `` in the
164+ message is passed to handlers as structured data. Keys that were interpolated into the
165+ message are stripped by default (since their values are already present in the message
166+ text), but you can keep them by setting ``$logContextUsedKeys = true ``.
167+
168+ .. literalinclude :: logging/007.php
169+
170+ **Throwable normalization **
171+
172+ Any ``Throwable `` instance (exception or error) found in the context is automatically
173+ normalized into a meaningful array instead of being serialized as an empty object:
174+
175+ .. literalinclude :: logging/008.php
176+
177+ The normalized array contains ``class ``, ``message ``, ``code ``, ``file ``, and ``line ``.
178+ To also include the full stack trace, set ``$logContextTrace = true ``.
179+
180+ .. note :: ``$logContext`` and ``$logGlobalContext`` are independent. You can enable either
181+ or both. When both are enabled, per-call context and global context are merged before
182+ being passed to handlers.
183+
150184Using Third-Party Loggers
151185=========================
152186
0 commit comments