Skip to content

Commit

Permalink
Merge branch 'feature/refactor-logger-implementation-5683'
Browse files Browse the repository at this point in the history
resolves #5683
  • Loading branch information
Johannes Meyer committed Feb 26, 2014
2 parents 872da0c + ec308ec commit c5faf9f
Show file tree
Hide file tree
Showing 38 changed files with 592 additions and 694 deletions.
6 changes: 1 addition & 5 deletions application/controllers/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@
// {{{ICINGA_LICENSE_HEADER}}}
// @codingStandardsIgnoreStart

use Icinga\Web\Form;
use Icinga\Web\Controller\ActionController;
use Icinga\Filter\Filter;
use Icinga\Filter\FilterAttribute;
use Icinga\Filter\Type\TextFilter;
use Icinga\Application\Logger;
use Icinga\Web\Url;
use Icinga\Logger\Logger;

/**
* Application wide interface for filtering
Expand Down
13 changes: 7 additions & 6 deletions application/controllers/StaticController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
// {{{ICINGA_LICENSE_HEADER}}}

use \Zend_Controller_Action_Exception as ActionException;
use \Icinga\Web\Controller\ActionController;
use \Icinga\Application\Icinga;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Application\Logger;
use Icinga\Web\Controller\ActionController;
use Icinga\Application\Icinga;
use Icinga\Logger\Logger;

/**
* Delivery static content to clients
Expand Down Expand Up @@ -104,7 +103,8 @@ public function javascriptAction()
if (!Icinga::app()->getModuleManager()->hasEnabled($module)) {
Logger::error(
'Non-existing frontend component "' . $module . '/' . $file
. '" was requested. The module "' . $module . '" does not exist or is not active.');
. '" was requested. The module "' . $module . '" does not exist or is not active.'
);
echo "/** Module not enabled **/";
return;
}
Expand All @@ -115,7 +115,8 @@ public function javascriptAction()
if (!file_exists($filePath)) {
Logger::error(
'Non-existing frontend component "' . $module . '/' . $file
. '" was requested, which would resolve to the the path: ' . $filePath);
. '" was requested, which would resolve to the the path: ' . $filePath
);
echo '/** Module has no js files **/';
return;
}
Expand Down
8 changes: 4 additions & 4 deletions application/forms/Config/Resource/EditResourceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
namespace Icinga\Form\Config\Resource;

use \Zend_Config;
use \Icinga\Web\Form;
use \Icinga\Web\Form\Decorator\HelpText;
use \Icinga\Application\Logger;
use Icinga\Web\Form;
use Icinga\Logger\Logger;
use Icinga\Web\Form\Decorator\HelpText;
use Icinga\Data\ResourceFactory;

/**
Expand Down Expand Up @@ -440,7 +440,7 @@ public function getConfig()
if ($key !== 'resource_type' && $key !== 'resource_all_name' && $key !== 'resource_all_name_old') {
$configKey = explode('_', $key, 3);
if (sizeof($configKey) < 3) {
Logger::warn('EditResourceForm: invalid form key "' . $key . '" was ignored.');
Logger::warning('EditResourceForm: invalid form key "' . $key . '" was ignored.');
continue;
}
$result[$configKey[2]] = $value;
Expand Down
32 changes: 22 additions & 10 deletions config/config.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,30 @@ moduleFolder = "@icingaweb_config_path@/enabledModules"
; modulePath = "/vagrant/modules:/usr/share/icingaweb/modules"

[logging]
; General log
enable = "1"
enable = true
; Writing to a Stream
type = "stream"
verbose = "1"
; Write data to the following file
target = "@icingaweb_log_path@/icingaweb.log"

; For development and debug purposes: Logs additional (non critical) events to a
; seperate log
debug.enable = "1"
debug.type = "stream"
debug.target = "@icingaweb_log_path@/icingaweb.debug.log"

; Write data to a PHP stream
;target = "php://output"

; Writing to the System Log
;type = "syslog"
; Prefix all syslog messages generated with the string "Icinga Web"
;application = "Icinga Web"
;facility = "LOG_USER"

level = 1
; The default level is WARNING, which means that only events of this level and
; above will be tracked. Level numbers descend in order of importance where
; ERROR (0) is the most important level and DEBUG (3) is the least important
; level:
;
; ERROR = 0 - Error: error conditions
; WARNING = 1 - Warning: warning conditions
; INFO = 2 - Informational: informational messages
; DEBUG = 3 - Debug: debug messages

; Use ini store to store preferences on local disk
[preferences]
Expand Down
55 changes: 39 additions & 16 deletions library/Icinga/Application/ApplicationBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@

namespace Icinga\Application;

use \DateTimeZone;
use \Exception;
use \Icinga\Application\Modules\Manager as ModuleManager;
use \Icinga\Application\Config;
use \Icinga\Exception\ConfigurationError;
use \Icinga\Util\DateTimeFactory;
use \Icinga\Util\Translator;
use \DateTimeZone;
use \Zend_Config;
use Icinga\Application\Modules\Manager as ModuleManager;
use Icinga\Application\Config;
use Icinga\Exception\ConfigurationError;
use Icinga\Util\DateTimeFactory;
use Icinga\Util\Translator;
use Icinga\Logger\Logger;

use Icinga\Data\ResourceFactory;

Expand Down Expand Up @@ -262,10 +264,6 @@ public static function start($configDir)
$application = new $class($configDir);
$application->bootstrap();

if (Logger::hasErrorsOccurred()) {
$application->stopApplication(Logger::getQueue());
}

return $application;
}

Expand Down Expand Up @@ -359,14 +357,33 @@ protected function loadEnabledModules()
try {
$this->moduleManager->loadEnabledModules();
} catch (Exception $e) {
Logger::fatal(
'Could not load modules. An exception was thrown during bootstrap: %s',
$e->getMessage()
);

}
return $this;
}

/**
* Setup default logging
*
* @return self
*/
protected function setupLogging()
{
Logger::create(
new Zend_Config(
array(
'enable' => true,
'level' => Logger::$ERROR,
'type' => 'syslog',
'facility' => 'LOG_USER',
'application' => 'Icinga Web'
)
)
);

return $this;
}

/**
* Load Configuration
*
Expand All @@ -391,7 +408,13 @@ protected function setupErrorHandling()
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
}
Logger::create($this->config->logging);

try {
Logger::create($this->config->logging);
} catch (ConfigurationError $e) {
Logger::error($e);
}

return $this;
}

Expand Down Expand Up @@ -438,7 +461,7 @@ protected function setupInternationalization()
try {
Translator::setupLocale($this->config->global->get('language', Translator::DEFAULT_LOCALE));
} catch (Exception $error) {
Logger::info($error->getMessage());
Logger::error($error);
}

$localeDir = $this->getApplicationDir('locale');
Expand Down
13 changes: 5 additions & 8 deletions library/Icinga/Application/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class Cli extends ApplicationBootstrap
protected function bootstrap()
{
$this->assertRunningOnCli();
$this->setupConfig()
->setupInternationalization()
->parseBasicParams()
$this->setupLogging()
->setupConfig()
->fixLoggingConfig()
->setupErrorHandling()
->setupInternationalization()
->parseBasicParams()
->setupResourceFactory()
->setupModuleManager();
}
Expand All @@ -74,13 +75,9 @@ protected function fixLoggingConfig()
{
$conf = & $this->getConfig()->logging;
if ($conf->type === 'stream') {
$conf->verbose = $this->verbose;
$conf->level = $this->verbose;
$conf->target = 'php://stderr';
}
if ($conf->debug && $conf->debug->type === 'stream') {
$conf->debug->target = 'php://stderr';
$conf->debug->enable = $this->debug;
}
return $this;
}

Expand Down
Loading

0 comments on commit c5faf9f

Please sign in to comment.