2017 © Pedro PelĂĄez
 

library mongodb_logger

A PSR/3 log producer for MongoDB

image

fgm/mongodb_logger

A PSR/3 log producer for MongoDB

  • Sunday, July 3, 2016
  • by FGM
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

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., (*1)

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)., (*2)

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

  • https://jira.mongodb.org/browse/PHPLIB-30 : won't fix
  • https://jira.mongodb.org/browse/PHPLIB-38 : won't fix
  • https://github.com/mongodb/mongo-c-driver/pull/80 : closed

(c) 2015 Ouest Systèmes Informatiques, (*4)

Licensed under the General Public License version 2 or later., (*5)

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, (*6)

     https://github.com/FGM/mongodb_logger.git
     cd mongodb_logger
  • run composer install to fetch dependencies, (*7)

  • that's it: you can now run the demo in the package itself, (*8)

    `php loguser.php`.

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, (*9)

    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, (*10)

  • install dependencies, (*11)

    composer install
  • copy the loguser.php file to your project directory, (*12)

    cp vendor/fgm/mongodb_logger/loguser.php .
  • that's it: you can now run the demo as a separate application, (*13)

    php loguser.php

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., (*14)

    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., (*15)

    $context = $emitter->createContext();
  • pass the context you just built when connecting to MongoDB., (*16)

    $client = new \MongoClient($server, $options, ['context' => $context]);
  • that'it. All your operations are now ready to be logged., (*17)

Trademarks

  • MongoDB is a registered trademark of MongoDB, Inc. http://mongodb.org/
  • OSInet is a trademark of Ouest Systèmes Informatiques http://www.osinet.fr/

The Versions

03/07 2016

dev-master

9999999-dev

A PSR/3 log producer for MongoDB

  Sources   Download

GPL-2.0+

The Requires