|
| 1 | +===================== |
| 2 | +MongoDB\\add_logger() |
| 3 | +===================== |
| 4 | + |
| 5 | +.. versionadded:: 1.17 |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +Definition |
| 16 | +---------- |
| 17 | + |
| 18 | +.. phpmethod:: MongoDB\\add_logger() |
| 19 | + |
| 20 | + Registers a PSR logger to receive log messages from the driver. |
| 21 | + |
| 22 | + .. code-block:: php |
| 23 | + |
| 24 | + function add_logger(Psr\Log\LoggerInterface $logger): void |
| 25 | + |
| 26 | + This method has the following parameters: |
| 27 | + |
| 28 | + .. include:: /includes/apiargs/function-add_logger-param.rst |
| 29 | + |
| 30 | +Behavior |
| 31 | +-------- |
| 32 | + |
| 33 | +This function allows the application to register one or more |
| 34 | +`Psr\\Log\\LoggerInterface <https://www.php-fig.org/psr/psr-3/#3-psrlogloggerinterface>`__ |
| 35 | +objects to receive log messages from libmongoc and the driver. Each registered |
| 36 | +logger will receive messages for *all* clients. |
| 37 | + |
| 38 | +Messages originating from the extension will have their log level translated to |
| 39 | +an equivalent `PSR log level <https://www.php-fig.org/psr/psr-3/#5-psrlogloglevel>`__. |
| 40 | +For performance reasons, trace-level messages from the extension are *not* |
| 41 | +forwarded to PSR loggers. The extension's |
| 42 | +:php:`mongodb.debug <manual/en/mongodb.configuration.php#ini.mongodb.debug>` INI |
| 43 | +configuration must be used to collect trace-level logs. |
| 44 | + |
| 45 | +Log messages also include a domain string that identifies the driver component |
| 46 | +that emitted the log message. This value is provided to the PSR logger via the |
| 47 | +{{domain}} key of the context array. |
| 48 | + |
| 49 | +Errors/Exceptions |
| 50 | +----------------- |
| 51 | + |
| 52 | +.. include:: /includes/extracts/error-invalidargumentexception.rst |
| 53 | + |
| 54 | +See Also |
| 55 | +-------- |
| 56 | + |
| 57 | +- :phpmethod:`MongoDB\\remove_logger()` |
| 58 | +- `PSR-3: Logger Interface <https://www.php-fig.org/psr/psr-3/>`__ |
| 59 | +- `libmongoc: Logging <https://mongoc.org/libmongoc/current/logging.html>`__ |
0 commit comments