This repository has been archived by the owner. It is now read-only.
An sfLogger implementation using MongoDB server.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



The sfMongoDBLogger uses a MongoDB to log messages. It utilizes several features of the mongo extension and MongoDB itself.


There are several configuration options available.

Server configuration

The basic configuration items to initialize a working MongoDB connection.

  • host, defaults to configured PHP host
  • port, defaults to configured PHP port

These two options are required in order to get the logger working:

  • database
  • collection

Authentication configuration

If you want to connect to the MongoDB as an authenticated user, you can put the information in these items. To disable this feature, configure it with false (default).

  • username
  • password

MongoDB write options

By default the write operations on MongoDB are not synchronous. This implies that not all data sent to the server will actually be written to the persistent, in case something bad happens. However there are options to force the server to actually persist the data before returning the result state.

The option save takes three keys. (see

  • safe
  • fsync
  • timeout

Each of these options default to the extensions default settings, but can be overwritten on a per logger basis. This way you can add an error logger with synchronous write operations while having a debug logger without.

MongoDB create collection options

By default MongoDB creates a collection on-the-fly where needed. If you want to create a collection with different parameters than the default ones, e.g. a capped collection, you can specify these options using the create option.

This option takes these keys. (see

  • capped
  • size
  • max

Example Configuration

    class: sfMongoDBLogger
      level: debug
      # The MongoDB server
      host: <?php echo Mongo::DEFAULT_HOST . "\n" ?>
      port: <?php echo Mongo::DEFAULT_PORT . "\n" ?>
      database: ~
      collection: ~
      # Authentication information
      username: false
      password: false
      # Options passed when inserting a new document
        safe: false
        fsync: false
        timeout: <?php echo MongoCursor::$timeout . "\n" ?>

      # Options to create the collection.
        capped: false
        size: 0
        max: 0




Notify method: filter

Default notifiers: sfMongoDBLogger

This event passes the document (associative array: message, priority) to be inserted into MongoDB for further modification.

The following listeners are bundled and can be connected to this event.

  • sfMongoDBLoggerListener::addTimestamp
  • sfMongoDBLoggerListener::convertLogPriority