1
1
Fork 0

friendica-6379 Monolog - logfile permission denied

This commit is contained in:
Philipp Holzer 2019-05-26 14:33:09 +02:00
parent ea218438d2
commit b56b56ccb6
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
3 changed files with 47 additions and 13 deletions

View file

@ -26,6 +26,7 @@ class LoggerFactory
{ {
/** /**
* A list of classes, which shouldn't get logged * A list of classes, which shouldn't get logged
*
* @var array * @var array
*/ */
private static $ignoreClassList = [ private static $ignoreClassList = [
@ -37,8 +38,8 @@ class LoggerFactory
/** /**
* Creates a new PSR-3 compliant logger instances * Creates a new PSR-3 compliant logger instances
* *
* @param string $channel The channel of the logger instance * @param string $channel The channel of the logger instance
* @param Configuration $config The config * @param Configuration $config The config
* @param Profiler $profiler The profiler of the app * @param Profiler $profiler The profiler of the app
* *
* @return LoggerInterface The PSR-3 compliant logger instance * @return LoggerInterface The PSR-3 compliant logger instance
@ -55,8 +56,8 @@ class LoggerFactory
} }
$introspection = new Introspection(self::$ignoreClassList); $introspection = new Introspection(self::$ignoreClassList);
$level = $config->get('system', 'loglevel'); $level = $config->get('system', 'loglevel');
$loglevel = self::mapLegacyConfigDebugLevel((string)$level); $loglevel = self::mapLegacyConfigDebugLevel((string)$level);
switch ($config->get('system', 'logger_config', 'stream')) { switch ($config->get('system', 'logger_config', 'stream')) {
case 'monolog': case 'monolog':
@ -71,7 +72,10 @@ class LoggerFactory
$stream = $config->get('system', 'logfile'); $stream = $config->get('system', 'logfile');
static::addStreamHandler($logger, $stream, $loglevel); // just add a stream in case it's either writable or not file
if (!is_file($stream) || is_writable($stream)) {
static::addStreamHandler($logger, $stream, $loglevel);
}
break; break;
case 'syslog': case 'syslog':
@ -81,7 +85,12 @@ class LoggerFactory
case 'stream': case 'stream':
default: default:
$stream = $config->get('system', 'logfile'); $stream = $config->get('system', 'logfile');
$logger = new StreamLogger($channel, $stream, $introspection, $loglevel); // just add a stream in case it's either writable or not file
if (!is_file($stream) || is_writable($stream)) {
$logger = new StreamLogger($channel, $stream, $introspection, $loglevel);
} else {
$logger = new VoidLogger();
}
break; break;
} }
@ -105,8 +114,8 @@ class LoggerFactory
* *
* It should never get filled during normal usage of Friendica * It should never get filled during normal usage of Friendica
* *
* @param string $channel The channel of the logger instance * @param string $channel The channel of the logger instance
* @param Configuration $config The config * @param Configuration $config The config
* @param Profiler $profiler The profiler of the app * @param Profiler $profiler The profiler of the app
* *
* @return LoggerInterface The PSR-3 compliant logger instance * @return LoggerInterface The PSR-3 compliant logger instance
@ -120,7 +129,8 @@ class LoggerFactory
$stream = $config->get('system', 'dlogfile'); $stream = $config->get('system', 'dlogfile');
$developerIp = $config->get('system', 'dlogip'); $developerIp = $config->get('system', 'dlogip');
if (!isset($developerIp) || !$debugging) { if ((!isset($developerIp) || !$debugging) &&
(!is_file($stream) || is_writable($stream))) {
$logger = new VoidLogger(); $logger = new VoidLogger();
Logger::setDevLogger($logger); Logger::setDevLogger($logger);
return $logger; return $logger;
@ -149,7 +159,7 @@ class LoggerFactory
break; break;
case 'syslog': case 'syslog':
$logger = new SyslogLogger($channel, $introspection, LogLevel::DEBUG); $logger = new SyslogLogger($channel, $introspection, LogLevel::DEBUG);
break; break;
case 'stream': case 'stream':
@ -172,6 +182,7 @@ class LoggerFactory
/** /**
* Mapping a legacy level to the PSR-3 compliant levels * Mapping a legacy level to the PSR-3 compliant levels
*
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
* *
* @param string $level the level to be mapped * @param string $level the level to be mapped
@ -208,9 +219,9 @@ class LoggerFactory
/** /**
* Adding a handler to a given logger instance * Adding a handler to a given logger instance
* *
* @param LoggerInterface $logger The logger instance * @param LoggerInterface $logger The logger instance
* @param mixed $stream The stream which handles the logger output * @param mixed $stream The stream which handles the logger output
* @param string $level The level, for which this handler at least should handle logging * @param string $level The level, for which this handler at least should handle logging
* *
* @return void * @return void
* *

View file

@ -22,6 +22,12 @@ class Settings extends BaseAdminModule
$debugging = !empty($_POST['debugging']); $debugging = !empty($_POST['debugging']);
$loglevel = defaults($_POST, 'loglevel', LogLevel::ERROR); $loglevel = defaults($_POST, 'loglevel', LogLevel::ERROR);
if (is_file($logfile) &&
!is_writeable($logfile)) {
notice(L10n::t('The logfile \'%s\' is not writable. No logging possible', $logfile));
return;
}
Config::set('system', 'logfile', $logfile); Config::set('system', 'logfile', $logfile);
Config::set('system', 'debugging', $debugging); Config::set('system', 'debugging', $debugging);
Config::set('system', 'loglevel', $loglevel); Config::set('system', 'loglevel', $loglevel);

View file

@ -74,6 +74,23 @@ class Summary extends BaseAdminModule
$well_known, $well_known, $a->getBaseURL() . '/help/Install'); $well_known, $well_known, $a->getBaseURL() . '/help/Install');
} }
// Check logfile permission
if (Config::get('system', 'debugging')) {
$stream = Config::get('system', 'logfile');
if (is_file($stream) &&
!is_writeable($stream)) {
$warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
}
$stream = Config::get('system', 'dlogfile');
if (is_file($stream) &&
!is_writeable($stream)) {
$warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
}
}
// check legacy basepath settings // check legacy basepath settings
$configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode()); $configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode());
$configCache = new Config\Cache\ConfigCache(); $configCache = new Config\Cache\ConfigCache();