-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggerExtController.php
103 lines (89 loc) · 3.91 KB
/
LoggerExtController.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
class LoggerExtController extends CController
{
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$actionId = $controllerId = $moduleId = "";
$actionId = $action->getId();
$controller = $action->getController();
if ($controller) $controllerId = $controller->getId();
$module = $controller->getModule();
if ($module) $moduleId = $module->getId();
$logModules = Yii::app()->logext->modules;
$logControllers = Yii::app()->logext->controllers;
if ($module) {
if ( isset($logModules[$moduleId]) ) {
$logControllers = $logModules[$moduleId];
}
else if ( isset($logModules['*']) ) {
$logControllers = $logModules['*'];
}
}
$logController = array();
if (isset($logControllers[$controllerId]) ) {
$logController = $logControllers[$controllerId];
}
else if (isset($logControllers['*'])) {
$logController = $logControllers['*'];
}
$logFile = "application.log";
if ( isset($logController['logFilePattern']) ) {
$pattern = $logController['logFilePattern'];
$logFile = $pattern;
if (
isset($logController['logFileUseParam']) &&
$logController['logFileUseParam'] &&
isset($logController['params']) &&
isset($logController['paramPattern']) &&
isset($logController['joinCharacter'])
) {
$params = explode(',', $logController['params']);
$joinCharacter = $logController['joinCharacter'];
$paramPattern = $logController['paramPattern'];
$pp = array();
foreach($params as $key) {
if (isset($_POST[trim($key)])) {
$v = $_POST[trim($key)];
}
elseif (isset($_GET[trim($key)])) {
$v = $_GET[trim($key)];
}
else $v = NULL;
if (!is_null($v))
$pp[] = str_replace(array('%n', '%v'), array(trim($key), $v), $paramPattern);
}
$logFile = str_replace('%p', join($joinCharacter, $pp), $pattern);
}
$find = array('%m', '%c', '%a');
$replace = array($moduleId, $controllerId, $actionId);
$logFile = str_replace($find, $replace, $logFile);
}
$logPath = "";
if ( isset($logController['logPathPattern'])) {
$logPath = $logController['logPathPattern'];
$find = array('%m', '%c', '%a');
$replace = array($moduleId, $controllerId, $actionId);
$logPath = str_replace($find, $replace, $logPath);
$find = array('<', '>', '*', '?', '"', '|');
$logPath = trim(str_replace($find, '', $logPath));
if (PHP_OS == 'WINNT')
$find = '/';
else $find = '\\';
$logPath = trim(str_replace($find, '', $logPath));
}
$route = Yii::app()->logext->route;
if ($route['class'] == 'FileDailyLogRoute') {
$route['logFile'] = $logFile;
$route=Yii::createComponent($route);
$route->init();
if ($logPath!="") {
$route->logPath = $route->logPath.'/'.$logPath;
}
Yii::app()->log->setRoutes(array('controller'=>$route));
}
return true;
}
return false;
}
}