mirror of
https://github.com/friendica/friendica
synced 2024-12-23 18:40:16 +00:00
Add Fallback in case the logfile isn't accessible.
- Fixes https://github.com/friendica/friendica/issues/7756#issuecomment-544227862
This commit is contained in:
parent
2edccf9341
commit
0e84a843a4
2 changed files with 23 additions and 13 deletions
|
@ -53,9 +53,6 @@ class LoggerFactory
|
||||||
* @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
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
* @throws InternalServerErrorException
|
|
||||||
*/
|
*/
|
||||||
public function create( Database $database, Configuration $config, Profiler $profiler)
|
public function create( Database $database, Configuration $config, Profiler $profiler)
|
||||||
{
|
{
|
||||||
|
@ -84,12 +81,22 @@ class LoggerFactory
|
||||||
|
|
||||||
// just add a stream in case it's either writable or not file
|
// just add a stream in case it's either writable or not file
|
||||||
if (!is_file($stream) || is_writable($stream)) {
|
if (!is_file($stream) || is_writable($stream)) {
|
||||||
|
try {
|
||||||
static::addStreamHandler($logger, $stream, $loglevel);
|
static::addStreamHandler($logger, $stream, $loglevel);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// No Logger ..
|
||||||
|
$logger = new VoidLogger();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'syslog':
|
case 'syslog':
|
||||||
|
try {
|
||||||
$logger = new SyslogLogger($this->channel, $introspection, $loglevel);
|
$logger = new SyslogLogger($this->channel, $introspection, $loglevel);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// No logger ...
|
||||||
|
$logger = new VoidLogger();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'stream':
|
case 'stream':
|
||||||
|
@ -97,7 +104,12 @@ class LoggerFactory
|
||||||
$stream = $config->get('system', 'logfile');
|
$stream = $config->get('system', 'logfile');
|
||||||
// just add a stream in case it's either writable or not file
|
// just add a stream in case it's either writable or not file
|
||||||
if (!is_file($stream) || is_writable($stream)) {
|
if (!is_file($stream) || is_writable($stream)) {
|
||||||
|
try {
|
||||||
$logger = new StreamLogger($this->channel, $stream, $introspection, $loglevel);
|
$logger = new StreamLogger($this->channel, $stream, $introspection, $loglevel);
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
// No logger ...
|
||||||
|
$logger = new VoidLogger();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$logger = new VoidLogger();
|
$logger = new VoidLogger();
|
||||||
}
|
}
|
||||||
|
@ -210,10 +222,9 @@ class LoggerFactory
|
||||||
case "3":
|
case "3":
|
||||||
return LogLevel::INFO;
|
return LogLevel::INFO;
|
||||||
// legacy DATA
|
// legacy DATA
|
||||||
case "4":
|
|
||||||
return LogLevel::DEBUG;
|
|
||||||
// legacy ALL
|
|
||||||
case "5":
|
case "5":
|
||||||
|
// legacy ALL
|
||||||
|
case "4":
|
||||||
return LogLevel::DEBUG;
|
return LogLevel::DEBUG;
|
||||||
// default if nothing set
|
// default if nothing set
|
||||||
default:
|
default:
|
||||||
|
@ -230,7 +241,6 @@ class LoggerFactory
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @throws InternalServerErrorException if the logger is incompatible to the logger factory
|
|
||||||
* @throws \Exception in case of general failures
|
* @throws \Exception in case of general failures
|
||||||
*/
|
*/
|
||||||
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
|
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
|
||||||
|
@ -249,8 +259,6 @@ class LoggerFactory
|
||||||
$fileHandler->setFormatter($formatter);
|
$fileHandler->setFormatter($formatter);
|
||||||
|
|
||||||
$logger->pushHandler($fileHandler);
|
$logger->pushHandler($fileHandler);
|
||||||
} else {
|
|
||||||
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,8 @@ class StreamLogger extends AbstractLogger
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException(sprintf('The level "%s" is not valid.', $level));
|
throw new \InvalidArgumentException(sprintf('The level "%s" is not valid.', $level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->checkStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close()
|
public function close()
|
||||||
|
|
Loading…
Reference in a new issue