-
Notifications
You must be signed in to change notification settings - Fork 12
/
LogRoute.php
executable file
·57 lines (50 loc) · 1.05 KB
/
LogRoute.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
50
51
52
53
54
55
56
57
<?php
namespace sammaye\mongoyii;
use Yii;
use CLogRoute;
/**
* EMongoLogRoute extends CLogRoute and provides logging
* into MongoDB.
* It is the mongodb equivalent of CDbLogRoute
*/
class LogRoute 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}
->selectDatabase()
->{$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->insertOne(
array(
'level' => $log[1],
'category' => $log[2],
'logtime' => (int)$log[3],
'message' => $log[0],
)
);
}
}
}