| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
class sfWebDebugLogger |
|---|
| 19 |
{ |
|---|
| 20 |
protected |
|---|
| 21 |
$webDebug = null; |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
* Initializes the web debug logger. |
|---|
| 25 |
* |
|---|
| 26 |
* @param array Logger options |
|---|
| 27 |
*/ |
|---|
| 28 |
public function initialize($options = array()) |
|---|
| 29 |
{ |
|---|
| 30 |
if (!sfConfig::get('sf_web_debug')) |
|---|
| 31 |
{ |
|---|
| 32 |
return; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
$this->webDebug = sfWebDebug::getInstance(); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
* Logs a message. |
|---|
| 40 |
* |
|---|
| 41 |
* @param string Message |
|---|
| 42 |
* @param string Message priority |
|---|
| 43 |
* @param string Message priority name |
|---|
| 44 |
*/ |
|---|
| 45 |
public function log($message, $priority, $priorityName) |
|---|
| 46 |
{ |
|---|
| 47 |
if (!sfConfig::get('sf_web_debug')) |
|---|
| 48 |
{ |
|---|
| 49 |
return; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
$debug_stack = array(); |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
if (function_exists('xdebug_get_function_stack') && !isset($_GET['XDEBUG_SESSION_START']) && !isset($_COOKIE['XDEBUG_SESSION'])) |
|---|
| 57 |
{ |
|---|
| 58 |
foreach (xdebug_get_function_stack() as $i => $stack) |
|---|
| 59 |
{ |
|---|
| 60 |
if ( |
|---|
| 61 |
(isset($stack['function']) && !in_array($stack['function'], array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug', 'log'))) |
|---|
| 62 |
|| !isset($stack['function']) |
|---|
| 63 |
) |
|---|
| 64 |
{ |
|---|
| 65 |
$tmp = ''; |
|---|
| 66 |
if (isset($stack['function'])) |
|---|
| 67 |
{ |
|---|
| 68 |
$tmp .= 'in "'.$stack['function'].'" '; |
|---|
| 69 |
} |
|---|
| 70 |
$tmp .= 'from "'.$stack['file'].'" line '.$stack['line']; |
|---|
| 71 |
$debug_stack[] = $tmp; |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
$type = 'sfOther'; |
|---|
| 78 |
if (preg_match('/^\s*{([^}]+)}\s*(.+?)$/', $message, $matches)) |
|---|
| 79 |
{ |
|---|
| 80 |
$type = $matches[1]; |
|---|
| 81 |
$message = $matches[2]; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$logEntry = array( |
|---|
| 86 |
'priority' => $priority, |
|---|
| 87 |
'priorityString' => $priorityName, |
|---|
| 88 |
'time' => time(), |
|---|
| 89 |
'message' => $message, |
|---|
| 90 |
'type' => $type, |
|---|
| 91 |
'debugStack' => $debug_stack, |
|---|
| 92 |
); |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
$this->webDebug->log($logEntry); |
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|