-
Notifications
You must be signed in to change notification settings - Fork 75
/
EMongoLogRoute.php
executable file
·49 lines (44 loc) · 995 Bytes
/
EMongoLogRoute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* EMongoLogRoute extends CLogRoute and provides logging
* into MongoDB.
* It is the mongodb equivalent of CDbLogRoute
*/
class EMongoLogRoute extends CLogRoute
{
/**
* @var string the connectionId of the EMongoClient component
*/
public $connectionId = 'mongodb';
/**
* Name of the collection the logs should be stored to.
* @var string
*/
public $logCollectionName = 'YiiLog';
/**
* Get a MongoCollection object
* @return MongoCollection - Instance of MongoCollection
*/
public function getMongoConnection()
{
return Yii::app()->{$this->connectionId}->{$this->logCollectionName};
}
/**
* Stores log messages into database.
* @param array $logs list of log messages
*/
public function processLogs($logs)
{
$collection = $this->getMongoConnection();
foreach($logs as $log){
$collection->insert(
array(
'level' => $log[1],
'category' => $log[2],
'logtime' => (int)$log[3],
'message' => $log[0],
)
);
}
}
}