-
Notifications
You must be signed in to change notification settings - Fork 1
/
OohLaLogger.php
57 lines (49 loc) · 1.69 KB
/
OohLaLogger.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
/**
* OohLaLogger setup for yii logging
*
* @author: Kevin Shamoun <[email protected]>
* @license GPLv2
*
* @copyright Copyright © 2008-2011 Operation Solutions LLC
To configure please setup main.php config file:
Setup in main.php config file:
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
// change the class location to suit your setup
'class'=>'common.extensions.OohLaLogger',
// for levels see: http://www.yiiframework.com/doc/guide/1.1/en/topics.logging
'levels'=>'info,error,warning',
// if you have YII_DEBUG set to true and this set to true it will skip logging
'skip_if_yiidebug_on' => true,
// Put your api key here
'oohLaLogApiKey' => 'YOUR_API_KEY_HERE'
),
)
),
*/
class OohLaLogger extends CLogRoute
{
public $skip_if_yiidebug_on = true;
public $oohLaLogApiKey = false;
protected function processLogs($logs)
{
if(YII_DEBUG AND $this->skip_if_yiidebug_on === true)
return;
// if set to false then don't log
if ($this->oohLaLogApiKey === FALSE)
return;
$url = 'http://api.oohlalog.com:80/api/logging/save.json?apiKey='.$this->oohLaLogApiKey;
$text=array();
foreach($logs as $log){
$m = explode ( 'Stack trace:', $log[0] ,2 );
$text = array('level'=> $log[1], 'category' => $log[2], 'timestamp'=> floor(microtime(true)*1000), 'hostName'=> gethostname(),'message'=> addcslashes($m[0],"'") ,'details'=> ( isset($m[1])? $m[1]: ''));
$payload = json_encode(array('logs' => array($text)),JSON_HEX_APOS );
$cmd = "curl -X POST -H 'Content-Type: application/json' -d '".$payload."' "."'".$url."' > /dev/null 2>&1 &";
exec($cmd, $output, $exit);
}
}
}
?>