Class yii\mongodb\log\MongoDbTarget

Inheritanceyii\mongodb\log\MongoDbTarget » yii\log\Target
Available since version2.0
Source Code https://github.com/yiisoft/yii2-mongodb/blob/master/src/log/MongoDbTarget.php

MongoDbTarget stores log messages in a MongoDB collection.

By default, MongoDbTarget stores the log messages in a MongoDB collection named 'log'. The collection can be changed by setting the $logCollection property.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$db yii\mongodb\Connection|string The MongoDB connection object or the application component ID of the MongoDB connection. yii\mongodb\log\MongoDbTarget
$logCollection string|array The name of the MongoDB collection that stores the session data. yii\mongodb\log\MongoDbTarget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
export() Stores log messages to MongoDB collection. yii\mongodb\log\MongoDbTarget
init() Initializes the MongoDbTarget component. yii\mongodb\log\MongoDbTarget

Property Details

$db public property

The MongoDB connection object or the application component ID of the MongoDB connection. After the MongoDbTarget object is created, if you want to change this property, you should only assign it with a MongoDB connection object.

public yii\mongodb\Connection|string $db 'mongodb'
$logCollection public property

The name of the MongoDB collection that stores the session data. Please refer to yii\mongodb\Connection::getCollection() on how to specify this parameter. This collection is better to be pre-created with fields 'id' and 'expire' indexed.

public string|array $logCollection 'log'

Method Details

export() public method

Stores log messages to MongoDB collection.

public void export ( )
init() public method

Initializes the MongoDbTarget component.

This method will initialize the $db property to make sure it refers to a valid MongoDB connection.

public void init ( )
throws \yii\base\InvalidConfigException

if $db is invalid.