psr2 tidy up of logging code.

This commit is contained in:
steve.brazier 2014-02-27 14:23:51 +00:00
parent 5178c4c229
commit b60e278cf9
6 changed files with 22 additions and 21 deletions

View file

@ -16,7 +16,7 @@ class BuildDBLogHandler extends AbstractProcessingHandler
protected $logValue;
function __construct(
public function __construct(
Build $build,
$level = LogLevel::INFO,
$bubble = true
@ -35,4 +35,4 @@ class BuildDBLogHandler extends AbstractProcessingHandler
$this->logValue .= $message . PHP_EOL;
$this->build->setLog($this->logValue);
}
}
}

View file

@ -20,7 +20,7 @@ class BuildLogger implements LoggerAwareInterface
*/
protected $build;
function __construct(LoggerInterface $logger = null, Build $build)
public function __construct(LoggerInterface $logger, Build $build)
{
$this->logger = $logger;
$this->build = $build;
@ -93,4 +93,4 @@ class BuildLogger implements LoggerAwareInterface
{
$this->logger = $logger;
}
}
}

View file

@ -6,7 +6,7 @@ use PHPCI\Model\Build;
class LoggedBuildContextTidier
{
function __invoke()
public function __invoke()
{
return $this->tidyLoggedBuildContext(func_get_arg(0));
}
@ -29,4 +29,4 @@ class LoggedBuildContextTidier
}
return $logRecord;
}
}
}

View file

@ -6,9 +6,10 @@ namespace PHPCI\Logging;
use Monolog\Logger;
class LoggerConfig {
class LoggerConfig
{
const KEY_AlwaysLoaded = "_";
const KEY_ALWAYS_LOADED = "_";
private $config;
@ -23,8 +24,7 @@ class LoggerConfig {
{
if (file_exists($filePath)) {
$configArray = require($filePath);
}
else {
} else {
$configArray = array();
}
return new self($configArray);
@ -36,7 +36,8 @@ class LoggerConfig {
* array of LogHandlers.
* @param array $configArray
*/
function __construct(array $configArray = array()) {
public function __construct(array $configArray = array())
{
$this->config = $configArray;
}
@ -46,13 +47,15 @@ class LoggerConfig {
* @param $name
* @return Logger
*/
public function getFor($name) {
$handlers = $this->getHandlers(self::KEY_AlwaysLoaded);
public function getFor($name)
{
$handlers = $this->getHandlers(self::KEY_ALWAYS_LOADED);
$handlers = array_merge($handlers, $this->getHandlers($name));
return new Logger($name, $handlers);
}
protected function getHandlers($key) {
protected function getHandlers($key)
{
$handlers = array();
// They key is expected to either be an array or
@ -60,12 +63,10 @@ class LoggerConfig {
if (isset($this->config[$key])) {
if (is_callable($this->config[$key])) {
$handlers = call_user_func($this->config[$key]);
}
elseif(is_array($this->config[$key])) {
} elseif (is_array($this->config[$key])) {
$handlers = $this->config[$key];
}
}
return $handlers;
}
}
}

View file

@ -14,7 +14,7 @@ class OutputLogHandler extends AbstractProcessingHandler
*/
protected $output;
function __construct(
public function __construct(
OutputInterface $output,
$level = LogLevel::INFO,
$bubble = true
@ -30,4 +30,4 @@ class OutputLogHandler extends AbstractProcessingHandler
}
}
}

View file

@ -24,7 +24,7 @@ class LoggerConfigTest extends \PHPUnit_Framework_TestCase
{
$expectedHandler = new \Monolog\Handler\NullHandler();
$config = new LoggerConfig(array(
LoggerConfig::KEY_AlwaysLoaded => function() use ($expectedHandler) {
LoggerConfig::KEY_ALWAYS_LOADED => function() use ($expectedHandler) {
return array($expectedHandler);
}
));