LoggerAppenderMongoDB

LoggerAppenderMongoDB appends log events to a mongoDB instance.

MongoDB is a scalable, high-performance, open source, document-oriented database.

Layout

This appender does not require a layout.

Parameters

The following parameters are available:

Parameter Type Required Default Description
host string No mongodb://localhost Server on which mongodb instance is located.
port integer No 27017 Port on which the instance is bound.
databaseName string No log4php_mongodb Name of the database to which to log.
collectionName string No logs Name of the target collection within the given database.
username string No - Username used to connect to the database.
password string No - Password used to connect to the database.
timeout integer No 3000 For how long the driver should try to connect to the database (in milliseconds).

Changelog

Version Description
2.2.0 Added the timeout parameter.

Examples

This example shows how to configure LoggerAppenderMongoDB to log to a remote database.

  • XML
  • PHP
<configuration xmlns="http://logging.apache.org/log4php/">
    <appender name="default" class="LoggerAppenderMongoDB">
        <param name="host" value="mongodb://example.com" />
        <param name="username" value="logger" />
        <param name="password" value="secret" />
    </appender>
    <root>
        <appender_ref ref="default" />
    </root>
</configuration>
array(
    'appenders' => array(
        'default' => array(
            'class' => 'LoggerAppenderMongoDB',
            'params' => array(
                'host' => 'mongodb://example.com',
                'username' => 'logger',
                'password' => 'secret',
            ),
        ),
    ),
    'rootLogger' => array(
        'appenders' => array('default'),
    ),
);