@@ -21,13 +21,17 @@ Overview
21
21
--------
22
22
23
23
In this guide, you can learn how to use the {+library-short+} to
24
- set up and configure **logging**.
24
+ set up and configure **logging**. Logging allows you to receive
25
+ information about database operations, server connections, errors,
26
+ and other events that occur while your application runs.
25
27
26
28
The {+library-short+} supports `Psr\\Log\\LoggerInterface
27
29
<https://www.php-fig.org/psr/psr-3/#3-psrlogloggerinterface>`__, a PSR-3
28
- logger interface that allows your application to receive log messages.
30
+ logger interface that configures your application to receive log messages.
29
31
You can register one or more ``Psr\Log\LoggerInterface`` objects to
30
- send ``libmongoc`` and {+extension-short+} messages to the logger.
32
+ send messages to the logger. The {+library-short+} is built on top of
33
+ ``libmongoc`` and {+extension-short+}, so the logger receives event notifications
34
+ from both components.
31
35
32
36
Register a Logger
33
37
-----------------
@@ -37,25 +41,25 @@ create a logger class that implements the ``Psr\Log\LoggerInterface``
37
41
interface. Then, use the ``MongoDB\add_logger()`` function to register
38
42
your logger.
39
43
40
- To implement ``Psr\Log\LoggerInterface``, you can create a class that
41
- extends the ``Psr\Log\AbstractLogger`` class. ``AbstractLogger`` implements
42
- ``LoggerInterface`` and a generic ``log()`` method, which receives each type
43
- of log message.
44
-
45
- Each message includes the following information:
44
+ Each log message includes the following information:
46
45
47
46
- Log level: Indicates the severity of the message. To view a list of
48
47
possible levels, see `PSR\\Log\\LogLevel <https://www.php-fig.org/psr/psr-3/#5-psrlogloglevel>`__.
49
48
- Message: Describes the logged event.
50
49
- Domain string: Specifies the driver component that emitted the log message.
51
50
51
+ To implement ``Psr\Log\LoggerInterface``, you can create a class that
52
+ extends the ``Psr\Log\AbstractLogger`` class. ``AbstractLogger`` implements
53
+ ``LoggerInterface`` and a generic ``log()`` method, which receives log
54
+ messages at each severity level.
55
+
52
56
Example
53
57
~~~~~~~
54
58
55
59
This example performs the following actions:
56
60
57
61
- Creates a logger called ``MyLogger`` that extends the ``AbstractLogger`` class
58
- and prints the severity level, description, and domain of each event
62
+ and records the log level, description, and domain of each event
59
63
- Registers the logger
60
64
- Creates a client that connects to a CosmosDB cluster
61
65
- Prints each log message
@@ -114,15 +118,15 @@ This example performs the following actions:
114
118
115
119
The preceding output includes log messages with a ``debug`` severity level, which
116
120
describe normal driver activities. It also includes a message about the CosmosDB
117
- connection with an ``info`` severity level that describes a noteworthy but non-urgent
121
+ connection with an ``info`` level that describes a noteworthy but non-urgent
118
122
event.
119
123
120
124
Write Custom Log Messages
121
125
-------------------------
122
126
123
127
You can generate custom log messages by using the ``PsrLogAdapter::writeLog()``
124
128
function. This function allows you to write directly to the logger and
125
- can assist with application debugging. Pass the severity level, domain, and
129
+ can help with application monitoring and debugging. Pass the severity level, domain, and
126
130
description as parameters to ``writeLog()``.
127
131
128
132
The following example writes log messages that have ``warning`` and
@@ -132,8 +136,8 @@ The following example writes log messages that have ``warning`` and
132
136
:copyable:
133
137
134
138
.. input:: /includes/monitoring-logging/logging.php
135
- :start-after: start-register-logger
136
- :end-before: end-register-logger
139
+ :start-after: start-write-messages
140
+ :end-before: end-write-messages
137
141
:language: php
138
142
:dedent:
139
143
0 commit comments