| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfLoggingConfigHandler extends sfDefineEnvironmentConfigHandler |
|---|
| 20 |
{ |
|---|
| 21 |
protected |
|---|
| 22 |
$enabled = true, |
|---|
| 23 |
$loggers = array(); |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
* Executes this configuration handler. |
|---|
| 27 |
* |
|---|
| 28 |
* @param array An array of absolute filesystem path to a configuration file |
|---|
| 29 |
* |
|---|
| 30 |
* @return string Data to be written to a cache file |
|---|
| 31 |
*/ |
|---|
| 32 |
public function execute($configFiles) |
|---|
| 33 |
{ |
|---|
| 34 |
$data = parent::execute($configFiles); |
|---|
| 35 |
|
|---|
| 36 |
if ($this->enabled) |
|---|
| 37 |
{ |
|---|
| 38 |
$data .= "\n\$logger = sfLogger::getInstance();\n"; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
$data .= "\$logger->setLogLevel(constant('SF_LOG_'.strtoupper(sfConfig::get('sf_logging_level'))));\n"; |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
foreach ($this->loggers as $name => $keys) |
|---|
| 45 |
{ |
|---|
| 46 |
if (isset($keys['enabled']) && !$keys['enabled']) |
|---|
| 47 |
{ |
|---|
| 48 |
continue; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
if (!isset($keys['class'])) |
|---|
| 52 |
{ |
|---|
| 53 |
|
|---|
| 54 |
throw new sfParseException(sprintf('Configuration file "%s" specifies filter "%s" with missing class key', $configFiles[0], $name)); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
$condition = true; |
|---|
| 58 |
if (isset($keys['param']['condition'])) |
|---|
| 59 |
{ |
|---|
| 60 |
$condition = $this->replaceConstants($keys['param']['condition']); |
|---|
| 61 |
unset($keys['param']['condition']); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
if ($condition) |
|---|
| 65 |
{ |
|---|
| 66 |
|
|---|
| 67 |
$parameters = isset($keys['param']) ? var_export($keys['param'], true) : ''; |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
$data .= sprintf("\n\$log = new %s();\n\$log->initialize(%s);\n\$logger->registerLogger(\$log);\n", $keys['class'], $parameters); |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
return $data; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
protected function getValues($prefix, $category, $keys) |
|---|
| 79 |
{ |
|---|
| 80 |
if ('enabled' == $category) |
|---|
| 81 |
{ |
|---|
| 82 |
$this->enabled = $this->replaceConstants($keys); |
|---|
| 83 |
} |
|---|
| 84 |
else if ('loggers' == $category) |
|---|
| 85 |
{ |
|---|
| 86 |
$this->loggers = $this->replaceConstants($keys); |
|---|
| 87 |
|
|---|
| 88 |
return array(); |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
return parent::getValues($prefix, $category, $keys); |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|