PHPackages                             fgm/mongodb\_logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. fgm/mongodb\_logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

fgm/mongodb\_logger
===================

A PSR/3 log producer for MongoDB

091PHP

Since Aug 28Pushed 3y ago1 watchersCompare

[ Source](https://github.com/fgm/mongodb_logger)[ Packagist](https://packagist.org/packages/fgm/mongodb_logger)[ RSS](/packages/fgm-mongodb-logger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Logging MongoDB operations in PHP applications
==============================================

[](#logging-mongodb-operations-in-php-applications)

This is an OSInet logger for MongoDB: it enables your PHP application to dump the low-level operations performed by the `mongo` extension communicating with your `mongod` or `mongos` instance.

It does *not* provide a PSR-3 logging destination, but a way to gather information from your MongoDB-using code, and pushing it to your choice of PSR-3 logger (e.g Monolog in general PHP code, or `mongodb_watchdog` in Drupal 6/7/8).

This code **requires** the legacy `mongo` extension: these features have been removed from the newer `mongodb` (phongo) extension:

-  : won't fix
-  : won't fix
- [mongodb/mongo-c-driver#80](https://github.com/mongodb/mongo-c-driver/pull/80) : closed

(c) 2015 Ouest Systèmes Informatiques

Licensed under the General Public License version 2 or later.

Running the demo on its own
---------------------------

[](#running-the-demo-on-its-own)

- ensure you have a development MongoDB instance without any important data available on `localhost:27017`. Any data in the instance could be lost.
- clone the repository

    ```
       https://github.com/FGM/mongodb_logger.git
       cd mongodb_logger

    ```
- run `composer install` to fetch dependencies
- that's it: you can now run the demo in the package itself

    ```
      `php loguser.php`.

    ```

Running the demo code as your application
-----------------------------------------

[](#running-the-demo-code-as-your-application)

- ensure you have a development MongoDB instance without any important data available on `localhost:27017`. Any data in the instance could be lost.
- create a composer file

    ```
      mkdir my_demo
      cd my_demo
      composer init

    ```
- answer the usual Composer questions, when Composer asks for requirements, request `fgm/mongodb_logger`, do not specify a version
- install dependencies

    ```
      composer install

    ```
- copy the `loguser.php` file to your project directory

    ```
      cp vendor/fgm/mongodb_logger/loguser.php .

    ```
- that's it: you can now run the demo as a separate application

    ```
      php loguser.php

    ```

Using the logging callbacks in your package
-------------------------------------------

[](#using-the-logging-callbacks-in-your-package)

- add the package to your Composer list of dependencies.
- instantiate the `Logger\Emitter` as your code needs it. A DIC may help.

    ```
      use FGM\MongoDBLogger\Logger\Emitter;
      use Psr\Log\LogLevel;

      // Build an emitter.
      $emitter = new Emitter();

      // Inject your own PSR-3 logger.
      $emitter->setLogger($logger);

      // You can choose your log level.
      $emitter->setLogLevel(LogLevel::DEBUG);

    ```
- use the emitter to create the mongodb:// context for your app.

    ```
      $context = $emitter->createContext();

    ```
- pass the context you just built when connecting to MongoDB.

    ```
      $client = new \MongoClient($server, $options, ['context' => $context]);

    ```
- that'it. All your operations are now ready to be logged.

Trademarks
----------

[](#trademarks)

- MongoDB is a registered trademark of MongoDB, Inc.
- OSInet is a trademark of Ouest Systèmes Informatiques

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/71aaa3a88679f828a7bc64acf1a235d392f38a97f5fe25dd6849813ef9306e33?d=identicon)[FGM](/maintainers/FGM)

---

Top Contributors

[![fgm](https://avatars.githubusercontent.com/u/143311?v=4)](https://github.com/fgm "fgm (6 commits)")

### Embed Badge

![Health badge](/badges/fgm-mongodb-logger/health.svg)

```
[![Health](https://phpackages.com/badges/fgm-mongodb-logger/health.svg)](https://phpackages.com/packages/fgm-mongodb-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
