StdoutWriter: Rename to StderrWriter

This commit is contained in:
Johannes Meyer 2016-01-21 11:47:11 +01:00
parent 9240d1b4e0
commit 424557f194
4 changed files with 69 additions and 45 deletions

View File

@ -55,7 +55,7 @@ class Cli extends ApplicationBootstrap
Logger::create( Logger::create(
new ConfigObject( new ConfigObject(
array( array(
'log' => 'stdout' 'log' => 'stderr'
) )
) )
); );
@ -69,7 +69,7 @@ class Cli extends ApplicationBootstrap
protected function setupLogger() protected function setupLogger()
{ {
$config = new ConfigObject(); $config = new ConfigObject();
$config->log = $this->params->shift('log', 'stdout'); $config->log = $this->params->shift('log', 'stderr');
if ($config->log === 'file') { if ($config->log === 'file') {
$config->file = $this->params->shiftRequired('log-path'); $config->file = $this->params->shiftRequired('log-path');
} elseif ($config->log === 'syslog') { } elseif ($config->log === 'syslog') {

View File

@ -0,0 +1,61 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Application\Logger\Writer;
use Icinga\Cli\Screen;
use Icinga\Application\Logger;
use Icinga\Application\Logger\LogWriter;
/**
* Class to write log messages to STDERR
*/
class StderrWriter extends LogWriter
{
/**
* The current Screen in use
*
* @var Screen
*/
protected $screen;
/**
* Return the current Screen
*
* @return Screen
*/
protected function screen()
{
if ($this->screen === null) {
$this->screen = Screen::instance();
}
return $this->screen;
}
/**
* Log a message with the given severity
*
* @param int $severity The severity to use
* @param string $message The message to log
*/
public function log($severity, $message)
{
switch ($severity) {
case Logger::ERROR:
$color = 'red';
break;
case Logger::WARNING:
$color = 'yellow';
break;
case Logger::INFO:
$color = 'green';
break;
case Logger::DEBUG:
$color = 'blue';
break;
}
file_put_contents('php://stderr', $this->screen()->colorize($message, $color) . "\n");
}
}

View File

@ -1,50 +1,13 @@
<?php <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ /* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Application\Logger\Writer; namespace Icinga\Application\Logger\Writer;
use Icinga\Cli\Screen;
use Icinga\Application\Logger;
use Icinga\Application\Logger\LogWriter;
use Zend_Config;
/** /**
* Class to write log messages to STDOUT * Deprecated, compat only.
*
* Use Icinga\Application\Logger\Writer\StderrWriter instead.
*/ */
class StdoutWriter extends LogWriter class StdoutWriter extends StderrWriter
{ {
protected $screen;
protected function screen()
{
if ($this->screen === null) {
$this->screen = Screen::instance();
}
return $this->screen;
}
/**
* Log a message with the given severity
*
* @param int $severity The severity to use
* @param string $message The message to log
*/
public function log($severity, $message)
{
$color = 'black';
switch ($severity) {
case Logger::ERROR:
$color = 'red';
break;
case Logger::WARNING:
$color = 'yellow';
break;
case Logger::INFO:
$color = 'green';
break;
case Logger::DEBUG:
$color = 'blue';
break;
}
file_put_contents('php://stderr', $this->screen()->colorize($message, $color) . "\n");
}
} }

View File

@ -50,7 +50,7 @@ class Documentation
$d .= ' ' . $module . "\n"; $d .= ' ' . $module . "\n";
} }
$d .= "\nGlobal options:\n\n" $d .= "\nGlobal options:\n\n"
. " --log [t] Log to <t>, either stdout, file or syslog (default: stdout)\n" . " --log [t] Log to <t>, either stderr, file or syslog (default: stderr)\n"
. " --log-path <f> Which file to log into in case of --log file\n" . " --log-path <f> Which file to log into in case of --log file\n"
. " --verbose Be verbose\n" . " --verbose Be verbose\n"
. " --debug Show debug output\n" . " --debug Show debug output\n"