Skip to content

Commit a5cdb31

Browse files
committed
feedback
1 parent 7decdd4 commit a5cdb31

File tree

2 files changed

+34
-71
lines changed

2 files changed

+34
-71
lines changed

source/monitoring-logging.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ Monitoring and Logging
1818
- :ref:`Cluster Monitoring <php-cluster-monitoring>`: Monitor changes
1919
in your cluster configuration
2020
- :ref:`Logging <php-logging>`: Configure logging to receive messages
21-
about {+library-short+} events
21+
about {+library-short+} events
22+
- :ref:`Change Streams <php-change-streams>`: Monitor data changes in
23+
your application

source/monitoring-logging/logging.txt

Lines changed: 31 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,100 +26,62 @@ information about database operations, server connections, errors,
2626
and other events that occur while your application runs.
2727

2828
The {+library-short+} supports `Psr\\Log\\LoggerInterface
29-
<https://www.php-fig.org/psr/psr-3/#3-psrlogloggerinterface>`__, a PSR-3
29+
<https://www.php-fig.org/psr/psr-3>`__, a PSR-3
3030
logger interface that configures your application to receive log messages.
3131
You can register one or more ``Psr\Log\LoggerInterface`` objects to
3232
send messages to the logger. The {+library-short+} is built on top of
33-
``libmongoc`` and the {+extension-short+}, so the logger receives event notifications
33+
the MongoDB C driver and the {+extension-short+}, so the logger receives event notifications
3434
from both components.
3535

36-
Register a Logger
36+
Configure Logging
3737
-----------------
3838

3939
To configure your application to receive messages about driver events,
4040
create a logger class that implements the ``Psr\Log\LoggerInterface``
4141
interface. Then, use the ``MongoDB\add_logger()`` function to register
4242
your logger.
4343

44-
Each log message includes the following information:
44+
After registering a logger, the {+library-short+} generates log messages
45+
as array values that resemble the following sample message:
4546

46-
- Log level: Indicates the severity of the message. To view a list of
47-
possible levels, see `PSR\\Log\\LogLevel <https://www.php-fig.org/psr/psr-3/#5-psrlogloglevel>`__.
48-
- Message: Describes the logged event.
49-
- Domain string: Specifies the driver component that emitted the log message.
47+
.. code-block:: php
48+
:copyable: false
49+
50+
[0] => Array
51+
(
52+
[0] => debug
53+
[1] => Created client with hash: ...
54+
[2] => PHONGO
55+
)
56+
57+
The sample log message includes the following information:
58+
59+
- Log level: Indicates the severity of the message. The ``debug`` level corresponds to
60+
standard driver activities. To view a list of possible levels, see `PSR\\Log\\LogLevel <https://www.php-fig.org/psr/psr-3/#5-psrlogloglevel>`__.
61+
- Message: Describes the logged event, which signals the creation of a new client.
62+
- Domain string: Specifies the driver component that emitted the log message. The
63+
``PHONGO`` domain indicates that the {+extension-short+} generated the event.
64+
65+
Example
66+
~~~~~~~
5067

5168
To implement ``Psr\Log\LoggerInterface``, you can create a class that
5269
extends the ``Psr\Log\AbstractLogger`` class. ``AbstractLogger`` implements
5370
``LoggerInterface`` and a generic ``log()`` method, which receives log
5471
messages at each severity level.
5572

56-
Example
57-
~~~~~~~
58-
5973
This example performs the following actions:
6074

6175
- Creates a logger called ``MyLogger`` that extends the ``AbstractLogger`` class
6276
and records the log level, description, and domain of each event
6377
- Registers the logger
64-
- Creates a client that connects to a CosmosDB cluster
6578
- Prints each log message
6679

67-
.. io-code-block::
68-
:copyable:
69-
70-
.. input:: /includes/monitoring-logging/logging.php
71-
:start-after: start-register-logger
72-
:end-before: end-register-logger
73-
:language: php
74-
:dedent:
75-
76-
.. output::
77-
:visible: false
78-
79-
Array
80-
(
81-
[0] => Array
82-
(
83-
[0] => debug
84-
[1] => Connection string: 'mongodb://a.mongo.cosmos.azure.com:19555/'
85-
[2] => PHONGO
86-
)
87-
[1] => Array
88-
(
89-
[0] => debug
90-
[1] => Creating Manager, phongo-1.21.0[stable] - mongoc-1.30.1(bundled), libbson-1.30.1(bundled), php-8.4.4
91-
[2] => PHONGO
92-
)
93-
[2] => Array
94-
(
95-
[0] => debug
96-
[1] => Setting driver handshake data: { name: 'ext-mongodb:PHP / PHPLIB ', version: '1.21.0 / 1.21.1 ', platform: 'PHP 8.4.4 ' }
97-
[2] => PHONGO
98-
)
99-
[3] => Array
100-
(
101-
[0] => info
102-
[1] => You appear to be connected to a CosmosDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/cosmosdb
103-
[2] => mongoc
104-
)
105-
[4] => Array
106-
(
107-
[0] => debug
108-
[1] => Created client with hash: a:4:{s:3:"pid";i:61731;s:3:"uri";s:41:"mongodb://a.mongo.cosmos.azure.com:19555/";s:7:"options";a:0:{}s:13:"driverOptions";a:1:{s:6:"driver";a:2:{s:4:"name";s:6:"PHPLIB";s:7:"version";s:6:"1.21.1";}}}
109-
[2] => PHONGO
110-
)
111-
[5] => Array
112-
(
113-
[0] => debug
114-
[1] => Stored persistent client with hash: a:4:{s:3:"pid";i:61731;s:3:"uri";s:41:"mongodb://a.mongo.cosmos.azure.com:19555/";s:7:"options";a:0:{}s:13:"driverOptions";a:1:{s:6:"driver";a:2:{s:4:"name";s:6:"PHPLIB";s:7:"version";s:6:"1.21.1";}}}
115-
[2] => PHONGO
116-
)
117-
)
118-
119-
The preceding output includes log messages with a ``debug`` severity level, which
120-
describe normal driver activities. It also includes a message about the CosmosDB
121-
connection with an ``info`` level that describes a noteworthy but non-urgent
122-
event.
80+
.. literalinclude:: /includes/monitoring-logging/logging.php
81+
:language: php
82+
:start-after: start-register-logger
83+
:end-before: end-register-logger
84+
:dedent:
12385

12486
Write Custom Log Messages
12587
-------------------------
@@ -189,7 +151,6 @@ following API documentation:
189151

190152
- :phpmethod:`MongoDB\add_logger()`
191153
- :phpmethod:`MongoDB\remove_logger()`
192-
193-
To learn more about C driver logging behavior, see `Logging
154+
To learn more about how the underlying C driver generates log messages, see `Logging
194155
<https://mongoc.org/libmongoc/current/logging.html>`__ in the ``libmongoc``
195156
API documentation.

0 commit comments

Comments
 (0)