Added to the console so that external logging definitions are pulled in from a loggerconfig.php file if the file exists.
This commit is contained in:
parent
35b3db13d8
commit
0fc91f053a
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,4 +8,5 @@ config.php
|
|||
.buildpath
|
||||
.htaccess
|
||||
PHPCI/config.yml
|
||||
cache
|
||||
cache
|
||||
/loggerconfig.php
|
51
PHPCI/Helper/LoggerConfig.php
Normal file
51
PHPCI/Helper/LoggerConfig.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace PHPCI\Helper;
|
||||
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
class LoggerConfig {
|
||||
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* The file specified is expected to return an array. Where each key
|
||||
* is the name of a logger. The value of each key should be an array or
|
||||
* a function that returns an array of LogHandlers.
|
||||
* @param $logConfigFilePath
|
||||
*/
|
||||
function __construct($logConfigFilePath) {
|
||||
if (file_exists($logConfigFilePath)) {
|
||||
$this->config = require_once($logConfigFilePath);
|
||||
}
|
||||
else {
|
||||
$this->config = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of Monolog with all configured handlers
|
||||
* added. The Monolog instance will be given $name.
|
||||
* @param $name
|
||||
* @return Logger
|
||||
*/
|
||||
public function GetFor($name) {
|
||||
$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]);
|
||||
}
|
||||
elseif(is_array($this->config[$name])) {
|
||||
$handlers = $this->config[$name];
|
||||
}
|
||||
}
|
||||
|
||||
return new Logger($name, $handlers);
|
||||
}
|
||||
|
||||
}
|
6
console
6
console
|
@ -19,10 +19,14 @@ use PHPCI\Command\InstallCommand;
|
|||
use PHPCI\Command\DaemonCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$loggerConfig = new \PHPCI\Helper\LoggerConfig(__DIR__ . "/loggerconfig.php");
|
||||
|
||||
$application = new Application();
|
||||
$application->add(new RunCommand);
|
||||
|
||||
$application->add(new RunCommand($loggerConfig->GetFor('RunCommand')));
|
||||
$application->add(new InstallCommand);
|
||||
$application->add(new UpdateCommand);
|
||||
$application->add(new GenerateCommand);
|
||||
$application->add(new DaemonCommand);
|
||||
|
||||
$application->run();
|
||||
|
|
9
loggerconfig.php.example
Normal file
9
loggerconfig.php.example
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
return array(
|
||||
'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),
|
||||
);
|
||||
}
|
||||
);
|
Loading…
Reference in a new issue