Merge branch 'bugfix/rebuild-application-log-logic-7060'
Don't work on this branch for this issue because the application log logic has nothing to do with #7060. (Work on application log related improvements will continue on another branch.)
This commit is contained in:
commit
3125f5d3c4
|
@ -4,9 +4,11 @@
|
|||
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\Writer\FileWriter;
|
||||
use Icinga\Protocol\File\Reader as FileReader;
|
||||
|
||||
/**
|
||||
* Class ListController
|
||||
|
@ -37,15 +39,16 @@ class ListController extends Controller
|
|||
public function applicationlogAction()
|
||||
{
|
||||
$this->addTitleTab('application log');
|
||||
$config_ini = IcingaConfig::app()->toArray();
|
||||
if (!in_array('logging', $config_ini) || (
|
||||
in_array('type', $config_ini['logging']) &&
|
||||
$config_ini['logging']['type'] === 'file' &&
|
||||
in_array('target', $config_ini['logging']) &&
|
||||
file_exists($config_ini['logging']['target'])
|
||||
)
|
||||
) {
|
||||
$resource = ResourceFactory::create('logfile');
|
||||
|
||||
$loggerWriter = Logger::getInstance()->getWriter();
|
||||
if ($loggerWriter instanceof FileWriter) {
|
||||
$resource = new FileReader(new Zend_Config(array(
|
||||
'filename' => $loggerWriter->getPath(),
|
||||
'fields' => '/^(?<datetime>[0-9]{4}(-[0-9]{2}){2}' // date
|
||||
. 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time
|
||||
. ' - (?<loglevel>[A-Za-z]+)' // loglevel
|
||||
. ' - (?<message>.*)$/' // message
|
||||
)));
|
||||
$this->view->logData = $resource->select()->order('DESC')->paginate();
|
||||
} else {
|
||||
$this->view->logData = null;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
</div>
|
||||
|
||||
<div class="content">
|
||||
<?php if ($this->logData !== null): ?>
|
||||
<table class="action">
|
||||
<tbody>
|
||||
<?php foreach ($this->logData as $value): ?>
|
||||
|
@ -21,4 +22,5 @@
|
|||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
|
|
@ -23,7 +23,7 @@ class Logger
|
|||
/**
|
||||
* The log writer to use
|
||||
*
|
||||
* @var LogWriter
|
||||
* @var \Icinga\Logger\LogWriter
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
|
@ -52,7 +52,7 @@ class Logger
|
|||
$this->verbosity = $config->level;
|
||||
|
||||
if ($config->enable) {
|
||||
$this->writer = $this->getWriter($config);
|
||||
$this->writer = $this->createWriter($config);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,11 +71,10 @@ class Logger
|
|||
*
|
||||
* @param Zend_Config $config The configuration to initialize the writer with
|
||||
*
|
||||
* @return LogWriter The requested log writer
|
||||
*
|
||||
* @throws ConfigurationError In case the requested writer cannot be found
|
||||
* @return \Icinga\Logger\LogWriter The requested log writer
|
||||
* @throws ConfigurationError If the requested writer cannot be found
|
||||
*/
|
||||
protected function getWriter(Zend_Config $config)
|
||||
protected function createWriter(Zend_Config $config)
|
||||
{
|
||||
$class = 'Icinga\\Logger\\Writer\\' . ucfirst(strtolower($config->type)) . 'Writer';
|
||||
if (!class_exists($class)) {
|
||||
|
@ -194,4 +193,24 @@ class Logger
|
|||
static::$instance->log(static::formatMessage(func_get_args()), static::$DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log writer to use
|
||||
*
|
||||
* @return \Icinga\Logger\LogWriter
|
||||
*/
|
||||
public function getWriter()
|
||||
{
|
||||
return $this->writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this' instance
|
||||
*
|
||||
* @return Logger
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
return static::$instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,4 +103,12 @@ class FileWriter extends LogWriter
|
|||
$file->fwrite($text);
|
||||
$file->fflush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ class Reader extends FilterIterator
|
|||
if ($matched === false) {
|
||||
throw new FileReaderException('Failed parsing regular expression!');
|
||||
} else if ($matched === 1) {
|
||||
foreach ($data as $key) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
@ -137,30 +137,32 @@ class Reader extends FilterIterator
|
|||
*/
|
||||
public function fetchPairs(Query $query)
|
||||
{
|
||||
$skipLines = $query->getOffset();
|
||||
$readLines = $query->getLimit();
|
||||
if ($skipLines === null) {
|
||||
$skipLines = 0;
|
||||
$skip = $query->getOffset();
|
||||
$read = $query->getLimit();
|
||||
if ($skip === null) {
|
||||
$skip = 0;
|
||||
}
|
||||
$lines = array();
|
||||
if ($query->sortDesc()) {
|
||||
$count = $this->count($query);
|
||||
if ($count <= $skipLines) {
|
||||
if ($count <= $skip) {
|
||||
return $lines;
|
||||
} else if ($count < ($skipLines + $readLines)) {
|
||||
$readLines = $count - $skipLines;
|
||||
$skipLines = 0;
|
||||
} else if ($count < ($skip + $read)) {
|
||||
$read = $count - $skip;
|
||||
$skip = 0;
|
||||
} else {
|
||||
$skipLines = $count - ($skipLines + $readLines);
|
||||
$skip = $count - ($skip + $read);
|
||||
}
|
||||
}
|
||||
foreach ($this as $index => $line) {
|
||||
if ($index >= $skipLines) {
|
||||
if ($index >= $skipLines + $readLines) {
|
||||
$index = 0;
|
||||
foreach ($this as $line) {
|
||||
if ($index >= $skip) {
|
||||
if ($index >= $skip + $read) {
|
||||
break;
|
||||
}
|
||||
$lines[] = $line;
|
||||
}
|
||||
++$index;
|
||||
}
|
||||
if ($query->sortDesc()) {
|
||||
$lines = array_reverse($lines);
|
||||
|
|
Loading…
Reference in New Issue