Added a logger config key that is loaded for all commands. To allow a general purpose log.
This commit is contained in:
parent
6563c60ab3
commit
37c50bdb4c
|
@ -8,6 +8,8 @@ use Monolog\Logger;
|
|||
|
||||
class LoggerConfig {
|
||||
|
||||
const KEY_AlwaysLoaded = "_";
|
||||
|
||||
private $config;
|
||||
|
||||
/**
|
||||
|
@ -32,20 +34,25 @@ class LoggerConfig {
|
|||
* @return Logger
|
||||
*/
|
||||
public function GetFor($name) {
|
||||
$handlers = $this->getHandlers(self::KEY_AlwaysLoaded);
|
||||
$handlers = array_merge($handlers, $this->getHandlers($name));
|
||||
return new Logger($name, $handlers);
|
||||
}
|
||||
|
||||
protected function getHandlers($key) {
|
||||
$handlers = array();
|
||||
|
||||
// They key is expected to either be an array or
|
||||
// a callable function that returns an array
|
||||
if (isset($this->config[$name])) {
|
||||
if (is_callable($this->config[$name])) {
|
||||
$handlers = call_user_func($this->config[$name]);
|
||||
if (isset($this->config[$key])) {
|
||||
if (is_callable($this->config[$key])) {
|
||||
$handlers = call_user_func($this->config[$key]);
|
||||
}
|
||||
elseif(is_array($this->config[$name])) {
|
||||
$handlers = $this->config[$name];
|
||||
elseif(is_array($this->config[$key])) {
|
||||
$handlers = $this->config[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return new Logger($name, $handlers);
|
||||
return $handlers;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,16 @@
|
|||
<?php
|
||||
return array(
|
||||
/** Loggers attached to every command */
|
||||
"_" => function() {
|
||||
return array(
|
||||
new \Monolog\Handler\StreamHandler('c:\temp\errors.log', \Monolog\Logger::ERROR),
|
||||
);
|
||||
},
|
||||
|
||||
/** Loggers for the RunCommand */
|
||||
'RunCommand' => function() {
|
||||
return array(
|
||||
new \Monolog\Handler\StreamHandler('path/to/logs/errors', \Monolog\Logger::ERROR),
|
||||
new \Monolog\Handler\RotatingFileHandler('path/to/logs/everything',3, \Monolog\Logger::INFO),
|
||||
new \Monolog\Handler\RotatingFileHandler('c:\temp\everything',3, \Monolog\Logger::INFO),
|
||||
);
|
||||
}
|
||||
);
|
Loading…
Reference in a new issue