Make IcingaWeb using the new log wrapper

refs #5683
This commit is contained in:
Johannes Meyer 2014-02-26 11:19:52 +01:00
parent 05cb0cb87a
commit 3555e66018
28 changed files with 104 additions and 89 deletions

View File

@ -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

View File

@ -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
@ -104,7 +103,8 @@ class StaticController extends ActionController
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;
}
@ -115,7 +115,8 @@ class StaticController extends ActionController
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;
}

View File

@ -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;
/**
@ -440,7 +440,7 @@ class EditResourceForm extends Form
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;

View File

@ -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;
@ -262,10 +264,6 @@ abstract class ApplicationBootstrap
$application = new $class($configDir);
$application->bootstrap();
if (Logger::hasErrorsOccurred()) {
$application->stopApplication(Logger::getQueue());
}
return $application;
}
@ -359,14 +357,33 @@ abstract class ApplicationBootstrap
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
*
@ -391,7 +408,13 @@ abstract class ApplicationBootstrap
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;
}
@ -438,7 +461,7 @@ abstract class ApplicationBootstrap
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');

View File

@ -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();
}
@ -74,13 +75,9 @@ class Cli extends ApplicationBootstrap
{
$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;
}

View File

@ -31,7 +31,7 @@ namespace Icinga\Application\Modules;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Data\DataArray\Datasource as ArrayDatasource;
use Icinga\Data\DataArray\Query as ArrayQuery;
use Icinga\Exception\ConfigurationError;
@ -161,7 +161,7 @@ class Manager
$link = $this->enableDir . '/' . $file;
if (! is_link($link)) {
Logger::warn(
Logger::warning(
'Found invalid module in enabledModule directory "%s": "%s" is not a symlink',
$this->enableDir,
$link
@ -171,7 +171,7 @@ class Manager
$dir = realpath($link);
if (!file_exists($dir) || !is_dir($dir)) {
Logger::warn(
Logger::warning(
'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"',
$this->enableDir,
$link,
@ -517,7 +517,7 @@ class Manager
{
foreach ($this->modulePaths as $basedir) {
if (!file_exists($basedir)) {
Logger::warn('Module path "%s" does not exist.', $basedir);
Logger::warning('Module path "%s" does not exist.', $basedir);
continue;
}
$fh = opendir($basedir);
@ -532,7 +532,7 @@ class Manager
if (! array_key_exists($name, $this->installedBaseDirs)) {
$this->installedBaseDirs[$name] = $basedir . '/' . $name;
} else {
Logger::warn(
Logger::warning(
'Module "%s" already exists in installation path "%s" and is ignored.',
$basedir . '/' . $name,
$this->installedBaseDirs[$name]

View File

@ -34,7 +34,7 @@ use Zend_Controller_Router_Route as Route;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Util\Translator;
use Icinga\Web\Hook;
@ -185,7 +185,7 @@ class Module
try {
$this->launchRunScript();
} catch (Exception $e) {
Logger::warn(
Logger::warning(
'Launching the run script %s for module %s failed with the following exception: %s',
$this->runScript,
$this->name,

View File

@ -37,7 +37,7 @@ use \Zend_View_Helper_PaginationControl;
use \Zend_Controller_Action_HelperBroker;
use \Zend_Controller_Router_Route;
use \Zend_Controller_Front;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Authentication\Manager as AuthenticationManager;
use Icinga\Exception\ConfigurationError;
use Icinga\User\Preferences;
@ -114,7 +114,8 @@ class Web extends ApplicationBootstrap
*/
protected function bootstrap()
{
return $this->setupConfig()
return $this->setupLogging()
->setupConfig()
->setupErrorHandling()
->setupResourceFactory()
->setupSession()
@ -260,7 +261,7 @@ class Web extends ApplicationBootstrap
$path = Config::resolvePath($this->getConfig()->preferences->configPath);
if (is_dir($path) === false) {
Logger::warn(
Logger::warning(
'Path for preferences not found (IniStore, "%s"). Using default one: "%s"',
$this->getConfig()->preferences->configPath,
$this->getConfigDir('preferences')
@ -278,7 +279,7 @@ class Web extends ApplicationBootstrap
);
$preferences->attach($preferenceStore);
} catch (Exception $e) {
Logger::warn(
Logger::warning(
'Could not create create preferences provider, preferences will be discarded: '
. '"%s"',
$e->getMessage()
@ -290,7 +291,7 @@ class Web extends ApplicationBootstrap
try {
$initialPreferences = $preferenceStore->load();
} catch (Exception $e) {
Logger::warn(
Logger::warning(
'%s::%s: Could not load preferences from provider. '
. 'An exception during bootstrap was thrown: %s',
__CLASS__,

View File

@ -39,7 +39,7 @@ use \Icinga\User;
use \Icinga\Authentication\UserBackend;
use \Icinga\Authentication\Credential;
use \Icinga\Authentication;
use \Icinga\Application\Logger;
use \Icinga\Logger\Logger;
use \Icinga\Exception\ProgrammingError;
use \Icinga\Exception\ConfigurationError;

View File

@ -34,7 +34,7 @@ use \Zend_Config;
use Icinga\User;
use Icinga\Web\Session;
use Icinga\Data\ResourceFactory;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Exception\ConfigurationError;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Authentication\Backend\DbUserBackend;
@ -168,7 +168,7 @@ class Manager
$name = $backendConfig->name;
// TODO: implement support for groups (#4624) and remove OR-Clause
if ((!$target || strtolower($target) != "user") && !$backendConfig->class) {
Logger::warn('AuthManager: Backend "%s" has no target configuration. (e.g. target=user|group)', $name);
Logger::warning('AuthManager: Backend "%s" has no target configuration. (e.g. target=user|group)', $name);
return null;
}
try {
@ -188,10 +188,10 @@ class Manager
case 'ldap':
return new LdapUserBackend($backendConfig);
default:
Logger::warn('AuthManager: Resource type ' . $backendConfig->type . ' not available.');
Logger::warning('AuthManager: Resource type ' . $backendConfig->type . ' not available.');
}
} catch (Exception $e) {
Logger::warn('AuthManager: Not able to create backend. Exception was thrown: %s', $e->getMessage());
Logger::warning('AuthManager: Not able to create backend. Exception was thrown: %s', $e->getMessage());
}
return null;
}
@ -288,7 +288,6 @@ class Manager
}
if ($authErrors >= count($this->userBackends)) {
Logger::fatal('AuthManager: No working backend found, unable to authenticate any user');
throw new ConfigurationError(
'No working backend found. Unable to authenticate any user.' .
"\nPlease examine the logs for more information."

View File

@ -2,7 +2,7 @@
namespace Icinga\Data;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Exception;
use Icinga\Filter\Filterable;
use Icinga\Filter\Query\Node;

View File

@ -29,7 +29,7 @@
namespace Icinga\Protocol\Commandpipe\Transport;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
/**
* CommandPipe Transport class that writes to a file accessible by the filesystem

View File

@ -31,7 +31,7 @@ namespace Icinga\Protocol\Commandpipe\Transport;
use \RuntimeException;
use \Zend_Config;
use \Icinga\Application\Logger;
use \Icinga\Logger\Logger;
/**
* Command pipe transport class that uses ssh for connecting to a remote filesystem with the icinga.cmd pipe

View File

@ -31,7 +31,7 @@ namespace Icinga\Protocol\Ldap;
use Icinga\Application\Platform;
use Icinga\Application\Config;
use Icinga\Application\Logger as Log;
use Icinga\Logger\Logger;
use \Zend_Config;
/**
@ -273,14 +273,14 @@ class Connection
$r = @ldap_bind($ds, $username, $password);
if ($r) {
log::debug(
Logger::debug(
'Successfully tested LDAP credentials (%s / %s)',
$username,
'***'
);
return true;
} else {
log::debug(
Logger::debug(
'Testing LDAP credentials (%s / %s) failed: %s',
$username,
'***',
@ -321,9 +321,9 @@ class Connection
if ($use_tls) {
if ($cap->starttls) {
if (@ldap_start_tls($ds)) {
Log::debug('LDAP STARTTLS succeeded');
Logger::debug('LDAP STARTTLS succeeded');
} else {
Log::debug('LDAP STARTTLS failed: %s', ldap_error($ds));
Logger::debug('LDAP STARTTLS failed: %s', ldap_error($ds));
throw new \Exception(
sprintf(
'LDAP STARTTLS failed: %s',
@ -352,7 +352,7 @@ class Connection
// TODO: remove this -> FORCING v3 for now
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
Log::warn('No LDAPv3 support detected');
Logger::warn('No LDAPv3 support detected');
}
// Not setting this results in "Operations error" on AD when using the

View File

@ -29,7 +29,7 @@
namespace Icinga\Protocol\Statusdat;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Data\DatasourceInterface;
use Icinga\Exception\ConfigurationError;
@ -147,7 +147,7 @@ class Reader implements IReader, DatasourceInterface
$maxCacheLifetime = intval($this->config->get('cache_path', self::DEFAULT_CACHE_LIFETIME));
$cachingEnabled = true;
if (!is_writeable($cachePath)) {
Logger::warn(
Logger::warning(
'Can\'t cache Status.dat backend; make sure cachepath %s is writable by the web user. '
. 'Caching is now disabled',
$cachePath

View File

@ -29,7 +29,7 @@
namespace Icinga\Session;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use \Icinga\Exception\ConfigurationError;
/**
@ -95,7 +95,7 @@ class PhpSession extends Session
foreach ($options as $sessionVar => $value) {
if (ini_set("session." . $sessionVar, $value) === false) {
Logger::warn(
Logger::warning(
'Could not set php.ini setting %s = %s. This might affect your sessions behaviour.',
$sessionVar,
$value

View File

@ -29,9 +29,8 @@
namespace Icinga\User\Preferences;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Protocol\Ldap\Exception;
use \SplObserver;
use \SplSubject;
use \Icinga\User;
use \Icinga\User\Preferences;

View File

@ -39,7 +39,7 @@ use Icinga\Application\Benchmark;
use Icinga\Util\Translator;
use Icinga\Web\Widget\Tabs;
use Icinga\Web\Url;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Web\Request;
use Icinga\File\Pdf;

View File

@ -30,7 +30,7 @@
namespace Icinga\Web;
use \stdClass;
use \Icinga\Application\Logger as Log;
use \Icinga\Logger\Logger;
use \Icinga\Exception\ProgrammingError;
/**
@ -110,7 +110,7 @@ class Hook
$obj = new $class();
} catch (\Exception $e) {
// TODO: Persist unloading for "some time" or "current session"
Log::debug(
Logger::debug(
'Hook "%s" (%s) failed, will be unloaded: %s',
$name,
$class,
@ -155,7 +155,7 @@ class Hook
try {
$instance = new $class();
} catch (\Exception $e) {
Log::debug(
Logger::debug(
'Hook "%s" (%s) (%s) failed, will be unloaded: %s',
$name,
$key,

View File

@ -31,7 +31,7 @@ namespace Icinga\Web;
use Icinga\Exception\ProgrammingError;
use Icinga\Application\Platform;
use Icinga\Application\Logger as Log;
use Icinga\Logger\Logger;
use Icinga\Web\Session;
/**
@ -90,13 +90,13 @@ class Notification
switch ($type) {
case 'info':
case 'success':
Log::info($msg);
Logger::info($msg);
break;
case 'warning':
Log::warn($msg);
Logger::warn($msg);
break;
case 'error':
Log::error($msg);
Logger::error($msg);
break;
}
return;

View File

@ -31,7 +31,7 @@ namespace Icinga\Web\Widget;
use \Icinga\Application\Icinga;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Application\Logger;
use \Icinga\Logger\Logger;
use \Icinga\Exception\ConfigurationError;
use \Icinga\Web\Widget\Widget;
use \Icinga\Web\Widget\Dashboard\Pane;

View File

@ -29,7 +29,7 @@
namespace Icinga\Web\Widget\Tabextension;
use \Icinga\Application\Logger;
use \Icinga\Logger\Logger;
use \Icinga\Web\Widget\Tab;
use \Icinga\Web\Widget\Tabs;
use \Icinga\Web\Url;

View File

@ -29,7 +29,7 @@
use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Web\Form;
use Icinga\Web\Controller\ActionController;
use Icinga\Chart\SVGRenderer;

View File

@ -30,7 +30,7 @@
use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Module\Monitoring\DataView\HostStatus;
use Icinga\Module\Monitoring\DataView\ServiceStatus;
use Icinga\Module\Monitoring\Form\Command\DisableNotificationWithExpireForm;

View File

@ -29,7 +29,7 @@
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Data\Db\Query;
use Icinga\Application\Benchmark;
use Icinga\Exception\ProgrammingError;
@ -211,7 +211,7 @@ abstract class IdoQuery extends Query
} elseif ($this->hasAliasName($columnOrAlias)) {
$columnOrAlias = $this->aliasToColumnName($columnOrAlias);
} else {
Logger::info('Can\'t order by column '.$columnOrAlias);
Logger::info('Can\'t order by column ' . $columnOrAlias);
return $this;
}
return parent::order($columnOrAlias, $dir);

View File

@ -29,7 +29,7 @@
namespace Icinga\Module\Monitoring\Backend\Statusdat\Query;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Data\Optional;
use Icinga\Data\The;
use Icinga\Filter\Query\Node;

View File

@ -30,7 +30,7 @@
namespace Icinga\Module\Monitoring\Filter;
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Logger\Logger;
use Icinga\Filter\Domain;
use Icinga\Filter\FilterAttribute;
use Icinga\Filter\Query\Node;

View File

@ -34,7 +34,6 @@ use Icinga\Filter\Query\Tree;
use Icinga\Filter\Query\Node;
use Icinga\Web\Request;
use Icinga\Web\Url;
use Icinga\Application\Logger;
/**
* Converter class that allows to create Query Trees from an request query and vice versa