Skip to content

Commit 66fd4ae

Browse files
committed
Some doc fixing
1 parent c60b9f9 commit 66fd4ae

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Model
7474
Libraries
7575
=========
7676

77+
- **Context**: This new feature allows you to easily set and retrieve normal or hidden contextual data for the current request. See :ref:`Context <context>` for details.
78+
7779
Helpers and Functions
7880
=====================
7981

user_guide_src/source/general/context.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
.. _context:
2+
13
###################
24
Context
35
###################
46

7+
.. versionadded:: 4.8.0
8+
59
.. contents::
610
:local:
711
:depth: 2
@@ -19,9 +23,9 @@ The Context class is particularly useful for:
1923
- Adding contextual information to your logs automatically
2024
- Storing sensitive data that should not appear in logs
2125

22-
******************
23-
Accessing Context
24-
******************
26+
***********************
27+
Accessing Context Class
28+
***********************
2529

2630
You can access the Context service anywhere in your application using the ``service()`` function:
2731

@@ -123,7 +127,9 @@ To remove all context data:
123127
Hidden Context Data
124128
*********************
125129

126-
The Context class provides a separate storage area for sensitive data that should not be included in logs. This is useful for storing API keys, passwords, tokens, or other sensitive information that you need to access during the request but don't want to expose in log files.
130+
The Context class provides a separate storage area for sensitive data that should not be included in logs.
131+
This is useful for storing API keys, passwords, tokens, or other sensitive information that you need to access
132+
during the request but don't want to expose in log files.
127133

128134
Setting Hidden Data
129135
===================
@@ -172,18 +178,21 @@ To clear both regular and hidden data:
172178

173179
.. literalinclude:: context/022.php
174180

175-
.. important:: Regular data and hidden data are stored separately. A key can exist in both regular and hidden storage with different values. Use ``get()`` for regular data and ``getHidden()`` for hidden data.
181+
.. important:: Regular data and hidden data are stored separately. A key can exist in both regular and hidden storage
182+
with different values. Use ``get()`` for regular data and ``getHidden()`` for hidden data.
176183

177184
***********************************
178185
Integration with Logging
179186
***********************************
180187

181-
The Context class integrates seamlessly with CodeIgniter's logging system. When enabled, context data is automatically appended to log messages, providing additional information for debugging and monitoring.
188+
The Context class integrates seamlessly with CodeIgniter's logging system. When enabled, context data is automatically
189+
appended to log messages, providing additional information for debugging and monitoring.
182190

183191
Enabling Global Context Logging
184192
================================
185193

186-
To enable automatic logging of context data, set the ``$logGlobalContext`` property to ``true`` in your **app/Config/Logger.php** file:
194+
To enable automatic logging of context data, set the ``$logGlobalContext`` property to ``true`` in your
195+
**app/Config/Logger.php** file:
187196

188197
.. literalinclude:: context/023.php
189198

@@ -197,7 +206,8 @@ This would produce a log entry like:
197206
198207
ERROR - 2026-02-18 --> Payment processing failed {"user_id":123,"transaction_id":"txn_12345"}
199208
200-
.. note:: Hidden data set with ``setHidden()`` is **never** included in logs, even when ``$logGlobalContext`` is enabled. This ensures sensitive information like API keys or tokens remain secure.
209+
.. note:: Hidden data set with ``setHidden()`` is **never** included in logs, even when ``$logGlobalContext`` is enabled.
210+
This ensures sensitive information like API keys or tokens remain secure.
201211

202212
***************
203213
Important Notes

user_guide_src/source/general/logging.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,35 @@ Several core placeholders exist that will be automatically expanded for you base
118118
| {env:foo} | The value of 'foo' in $_ENV |
119119
+----------------+---------------------------------------------------+
120120

121+
.. _logging-global-context:
122+
123+
Global Context Logging
124+
----------------------
125+
126+
.. versionadded:: 4.8.0
127+
128+
You can automatically append context data to all log messages by enabling the ``$logGlobalContext``
129+
property in **app/Config/Logger.php**:
130+
131+
.. literalinclude:: context/023.php
132+
133+
When enabled, all regular context data (set via the :ref:`Context class <context>`) is automatically
134+
appended to every log message as a JSON string:
135+
136+
.. literalinclude:: context/024.php
137+
138+
This would produce a log entry like:
139+
140+
.. code-block:: text
141+
142+
ERROR - 2026-02-18 --> Payment processing failed {"user_id":123,"transaction_id":"txn_12345"}
143+
144+
.. note:: Hidden data set with ``setHidden()`` is **never** included in log output, even when
145+
``$logGlobalContext`` is enabled. This protects sensitive information such as API keys
146+
and tokens from appearing in log files.
147+
148+
See :ref:`context` for full documentation on storing and managing context data.
149+
121150
Using Third-Party Loggers
122151
=========================
123152

0 commit comments

Comments
 (0)