# Class LoggerAppenderMongoDB

Appender for writing to MongoDB.

This class was originally contributed by Vladimir Gorej.

# Configurable parameters:

- host - Server on which mongodb instance is located.
- port - Port on which the instance is bound.
- databaseName - Name of the database to which to log.
- collectionName - Name of the target collection within the given database.
- username - Username used to connect to the database.
- password - Password used to connect to the database.
- timeout - For how long the driver should try to connect to the database (in milliseconds).

  LoggerConfigurable
  LoggerAppender
  LoggerAppenderMongoDB

Package: log4php\appenders
License: Apache License, Version 2.0
Version: $Revision: 1346363 $
Since: 2.1
Link: Appender documentation
Link: Vladimir Gorej's original submission.
Link: MongoDB website.
Located at appenders/LoggerAppenderMongoDB.php

Methods summary
`public` | # `__construct( string $name = '' )` Default constructor. Default constructor. #### Parameters $name `string` $name Appender name #### Overrides `LoggerAppender::__construct()`
`public` | # `activateOptions( )` Setup db connection. Based on defined options, this method connects to the database and creates a `LoggerAppenderMongoDB::$collection`. Setup db connection. Based on defined options, this method connects to the database and creates a `LoggerAppenderMongoDB::$collection`. #### Overrides `LoggerAppender::activateOptions()`
`public` | # `append( `LoggerLoggingEvent` $event )` Appends a new event to the mongo database. Appends a new event to the mongo database. #### Parameters $event ``LoggerLoggingEvent`` $event
`protected array` | # `format( `LoggerLoggingEvent` $event )` Converts the logging event into an array which can be logged to mongodb. Converts the logging event into an array which can be logged to mongodb. #### Parameters $event ``LoggerLoggingEvent`` $event #### Returns `array` The array representation of the logging event.
`protected array` | # `formatThrowable( Exception $ex )` Converts an Exception into an array which can be logged to mongodb. Converts an Exception into an array which can be logged to mongodb. Supports innner exceptions (PHP >= 5.3) #### Parameters $ex `Exception` $ex #### Returns `array`
`public` | # `close( )` Closes the connection to the logging database Closes the connection to the logging database #### Overrides `LoggerAppender::close()`
`public` | # `setHost( string $host )` Sets the value of `LoggerAppenderMongoDB::$host` parameter. Sets the value of `LoggerAppenderMongoDB::$host` parameter. #### Parameters $host `string` $host
`public string` | # `getHost( )` Returns the value of `LoggerAppenderMongoDB::$host` parameter. Returns the value of `LoggerAppenderMongoDB::$host` parameter. #### Returns `string`
`public` | # `setPort( integer $port )` Sets the value of `LoggerAppenderMongoDB::$port` parameter. Sets the value of `LoggerAppenderMongoDB::$port` parameter. #### Parameters $port `integer` $port
`public integer` | # `getPort( )` Returns the value of `LoggerAppenderMongoDB::$port` parameter. Returns the value of `LoggerAppenderMongoDB::$port` parameter. #### Returns `integer`
`public` | # `setDatabaseName( string $databaseName )` Sets the value of `LoggerAppenderMongoDB::$databaseName` parameter. Sets the value of `LoggerAppenderMongoDB::$databaseName` parameter. #### Parameters $databaseName `string` $databaseName
`public string` | # `getDatabaseName( )` Returns the value of `LoggerAppenderMongoDB::$databaseName` parameter. Returns the value of `LoggerAppenderMongoDB::$databaseName` parameter. #### Returns `string`
`public` | # `setCollectionName( string $collectionName )` Sets the value of `LoggerAppenderMongoDB::$collectionName` parameter. Sets the value of `LoggerAppenderMongoDB::$collectionName` parameter. #### Parameters $collectionName `string` $collectionName
`public string` | # `getCollectionName( )` Returns the value of `LoggerAppenderMongoDB::$collectionName` parameter. Returns the value of `LoggerAppenderMongoDB::$collectionName` parameter. #### Returns `string`
`public` | # `setUserName( string $userName )` Sets the value of `LoggerAppenderMongoDB::$userName` parameter. Sets the value of `LoggerAppenderMongoDB::$userName` parameter. #### Parameters $userName `string` $userName
`public string` | # `getUserName( )` Returns the value of `LoggerAppenderMongoDB::$userName` parameter. Returns the value of `LoggerAppenderMongoDB::$userName` parameter. #### Returns `string`
`public` | # `setPassword( string $password )` Sets the value of `LoggerAppenderMongoDB::$password` parameter. Sets the value of `LoggerAppenderMongoDB::$password` parameter. #### Parameters $password `string` $password
`public string` | # `getPassword( )` Returns the value of `LoggerAppenderMongoDB::$password` parameter. Returns the value of `LoggerAppenderMongoDB::$password` parameter. #### Returns `string`
`public` | # `setTimeout( integer $timeout )` Sets the value of `LoggerAppenderMongoDB::$timeout` parameter. Sets the value of `LoggerAppenderMongoDB::$timeout` parameter. #### Parameters $timeout `integer` $timeout
`public integer` | # `getTimeout( )` Returns the value of `LoggerAppenderMongoDB::$timeout` parameter. Returns the value of `LoggerAppenderMongoDB::$timeout` parameter. #### Returns `integer`
`public Mongo` | # `getConnection( )` Returns the mongodb connection. Returns the mongodb connection. #### Returns `Mongo`
`public MongoCollection` | # `getCollection( )` Returns the active mongodb collection. Returns the active mongodb collection. #### Returns `MongoCollection`

Methods inherited from LoggerAppender
`__destruct(), addFilter(), clearFilters(), doAppend(), getDefaultLayout(), getFilter(), getFirstFilter(), getLayout(), getName(), getThreshold(), isAsSevereAsThreshold(), requiresLayout(), setLayout(), setName(), setThreshold(), warn()`

Methods inherited from LoggerConfigurable
`setBoolean(), setFileSize(), setInteger(), setLevel(), setNumeric(), setPositiveInteger(), setString()`

Constants summary
`string` | `DEFAULT_MONGO_URL_PREFIX` | `'mongodb://'` | # Default prefix for the `LoggerAppenderMongoDB::$host`. Default prefix for the `LoggerAppenderMongoDB::$host`.
`string` | `DEFAULT_MONGO_HOST` | `'localhost'` | # Default value for `LoggerAppenderMongoDB::$host`, without a prefix. Default value for `LoggerAppenderMongoDB::$host`, without a prefix.
`integer` | `DEFAULT_MONGO_PORT` | `27017` | # Default value for `LoggerAppenderMongoDB::$port` Default value for `LoggerAppenderMongoDB::$port`
`string` | `DEFAULT_DB_NAME` | `'log4php_mongodb'` | # Default value for `LoggerAppenderMongoDB::$databaseName` Default value for `LoggerAppenderMongoDB::$databaseName`
`string` | `DEFAULT_COLLECTION_NAME` | `'logs'` | # Default value for `LoggerAppenderMongoDB::$collectionName` Default value for `LoggerAppenderMongoDB::$collectionName`
`integer` | `DEFAULT_TIMEOUT_VALUE` | `3000` | # Default value for `LoggerAppenderMongoDB::$timeout` Default value for `LoggerAppenderMongoDB::$timeout`

Properties summary
`protected mixed` | $host | `` | # Server on which mongodb instance is located. Server on which mongodb instance is located.
`protected mixed` | $port | `` | # Port on which the instance is bound. Port on which the instance is bound.
`protected mixed` | $databaseName | `` | # Name of the database to which to log. Name of the database to which to log.
`protected mixed` | $collectionName | `` | # Name of the collection within the given database. Name of the collection within the given database.
`protected mixed` | $userName | `` | # Username used to connect to the database. Username used to connect to the database.
`protected mixed` | $password | `` | # Password used to connect to the database. Password used to connect to the database.
`protected mixed` | $timeout | `` | # Timeout value used when connecting to the database (in milliseconds). Timeout value used when connecting to the database (in milliseconds).
`protected Mongo` | $connection | `` | # Connection to the MongoDB instance. Connection to the MongoDB instance.
`protected MongoCollection` | $collection | `` | # The collection to which log is written. The collection to which log is written.

Properties inherited from LoggerAppender
`$closed, $filter, $layout, $name, $requiresLayout, $threshold`