LoggerAppenderMongoDB appends log events to a mongoDB instance.

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


This appender does not require a layout.


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).


Version Description
2.2.0 Added the timeout parameter.


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_ref ref="default" />
    'appenders' => array(
        'default' => array(
            'class' => 'LoggerAppenderMongoDB',
            'params' => array(
                'host' => 'mongodb://example.com',
                'username' => 'logger',
                'password' => 'secret',
    'rootLogger' => array(
        'appenders' => array('default'),