## Class LoggerAppenderMongoDB

Description

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

- version: $Revision: 1346363 $
- link: Vladimir Gorej's original submission.
- link: Appender documentation
- link: MongoDB website.
- since: 2.1
- license: Apache License, Version 2.0

Located in /log4php/appenders/LoggerAppenderMongoDB.php (line 43)

    LoggerConfigurable
       |
       --LoggerAppender
          |
          --LoggerAppenderMongoDB

Class Constant Summary
DEFAULT_COLLECTION_NAME = 'logs'
DEFAULT_DB_NAME = 'log4php_mongodb'
DEFAULT_MONGO_HOST = 'localhost'
DEFAULT_MONGO_PORT = 27017
DEFAULT_MONGO_URL_PREFIX = 'mongodb://'
DEFAULT_TIMEOUT_VALUE = 3000
Variable Summary
MongoCollection $collection
mixed $collectionName
Mongo $connection
mixed $databaseName
mixed $host
mixed $password
mixed $port
mixed $timeout
mixed $userName
Method Summary
LoggerAppenderMongoDB __construct ([ $name = ''])
void activateOptions ()
void append (LoggerLoggingEvent $event)
void close ()
array format (LoggerLoggingEvent $event)
array formatThrowable (Exception $ex)
MongoCollection getCollection ()
string getCollectionName ()
Mongo getConnection ()
string getDatabaseName ()
string getHost ()
string getPassword ()
int getPort ()
int getTimeout ()
string getUserName ()
void setCollectionName (string $collectionName)
void setDatabaseName (string $databaseName)
void setHost (string $host)
void setPassword (string $password)
void setPort (int $port)
void setTimeout (int $timeout)
void setUserName (string $userName)
Variables
MongoCollection $collection (line 106)

The collection to which log is written.

- access: protected

mixed $collectionName (line 81)

Name of the collection within the given database.

- access: protected

Mongo $connection (line 100)

Connection to the MongoDB instance.

- access: protected

mixed $databaseName (line 78)

Name of the database to which to log.

- access: protected

mixed $host (line 72)

Server on which mongodb instance is located.

- access: protected

mixed $password (line 87)

Password used to connect to the database.

- access: protected

mixed $port (line 75)

Port on which the instance is bound.

- access: protected

mixed $timeout (line 90)

Timeout value used when connecting to the database (in milliseconds).

- access: protected

mixed $userName (line 84)

Username used to connect to the database.

- access: protected

#### Inherited Variables

Inherited from LoggerAppender

> LoggerAppender::$closed
> LoggerAppender::$filter
> LoggerAppender::$layout
> LoggerAppender::$name
> LoggerAppender::$requiresLayout
> LoggerAppender::$threshold

Methods
Constructor __construct (line 108)

- access: public

LoggerAppenderMongoDB __construct ([ $name = ''])

- $name

Redefinition of:

LoggerAppender::__construct()
  Default constructor.

activateOptions (line 123)

Setup db connection.

Based on defined options, this method connects to the database and creates a $collection.

- access: public

void activateOptions ()

Redefinition of:

LoggerAppender::activateOptions()
  Prepares the appender for logging.

append (line 151)

Appends a new event to the mongo database.

- access: public

void append (LoggerLoggingEvent $event)

- LoggerLoggingEvent $event

Redefinition of:

LoggerAppender::append()
  Forwards the logging event to the destination.

close (line 220)

Closes the connection to the logging database

- access: public

void close ()

Redefinition of:

LoggerAppender::close()
  Releases any resources allocated by the appender.

format (line 167)

Converts the logging event into an array which can be logged to mongodb.

- return: The array representation of the logging event.
- access: protected

array format (LoggerLoggingEvent $event)

- LoggerLoggingEvent $event

formatThrowable (line 203)

Converts an Exception into an array which can be logged to mongodb.

Supports innner exceptions (PHP >= 5.3)

- access: protected

array formatThrowable (Exception $ex)

- Exception $ex

getCollection (line 357)

Returns the active mongodb collection.

- access: public

MongoCollection getCollection ()
getCollectionName (line 294)

Returns the value of $collectionName parameter.

- access: public

string getCollectionName ()
getConnection (line 349)

Returns the mongodb connection.

- access: public

Mongo getConnection ()
getDatabaseName (line 278)

Returns the value of $databaseName parameter.

- access: public

string getDatabaseName ()
getHost (line 246)

Returns the value of $host parameter.

- access: public

string getHost ()
getPassword (line 326)

Returns the value of $password parameter.

- access: public

string getPassword ()
getPort (line 262)

Returns the value of $port parameter.

- access: public

int getPort ()
getTimeout (line 342)

Returns the value of $timeout parameter.

- access: public

int getTimeout ()
getUserName (line 310)

Returns the value of $userName parameter.

- access: public

string getUserName ()
setCollectionName (line 286)

Sets the value of $collectionName parameter.

- access: public

void setCollectionName (string $collectionName)

- string $collectionName

setDatabaseName (line 270)

Sets the value of $databaseName parameter.

- access: public

void setDatabaseName (string $databaseName)

- string $databaseName

setHost (line 235)

Sets the value of $host parameter.

- access: public

void setHost (string $host)

- string $host

setPassword (line 318)

Sets the value of $password parameter.

- access: public

void setPassword (string $password)

- string $password

setPort (line 254)

Sets the value of $port parameter.

- access: public

void setPort (int $port)

- int $port

setTimeout (line 334)

Sets the value of $timeout parameter.

- access: public

void setTimeout (int $timeout)

- int $timeout

setUserName (line 302)

Sets the value of $userName parameter.

- access: public

void setUserName (string $userName)

- string $userName

#### Inherited Methods

Inherited From LoggerAppender

> LoggerAppender::__construct()
> LoggerAppender::activateOptions()
> LoggerAppender::addFilter()
> LoggerAppender::append()
> LoggerAppender::clearFilters()
> LoggerAppender::close()
> LoggerAppender::doAppend()
> LoggerAppender::getDefaultLayout()
> LoggerAppender::getFilter()
> LoggerAppender::getFirstFilter()
> LoggerAppender::getLayout()
> LoggerAppender::getName()
> LoggerAppender::getThreshold()
> LoggerAppender::isAsSevereAsThreshold()
> LoggerAppender::requiresLayout()
> LoggerAppender::setLayout()
> LoggerAppender::setName()
> LoggerAppender::setThreshold()
> LoggerAppender::warn()
> LoggerAppender::__destruct()

Inherited From LoggerConfigurable

> LoggerConfigurable::setBoolean()
> LoggerConfigurable::setFileSize()
> LoggerConfigurable::setInteger()
> LoggerConfigurable::setLevel()
> LoggerConfigurable::setNumeric()
> LoggerConfigurable::setPositiveInteger()
> LoggerConfigurable::setString()
> LoggerConfigurable::warn()

Class Constants
DEFAULT_COLLECTION_NAME = 'logs' (line 62)

Default value for $collectionName

DEFAULT_DB_NAME = 'log4php_mongodb' (line 59)

Default value for $databaseName

DEFAULT_MONGO_HOST = 'localhost' (line 53)

Default value for $host, without a prefix.

DEFAULT_MONGO_PORT = 27017 (line 56)

Default value for $port

DEFAULT_MONGO_URL_PREFIX = 'mongodb://' (line 50)

Default prefix for the $host.

DEFAULT_TIMEOUT_VALUE = 3000 (line 65)

Default value for $timeout

Documentation generated on Wed, 12 Nov 2025 18:40:32 +0900 by phpDocumentor 1.4.4