Bug fixes to reduce logging-related crashes
* Provide a method for plugins to report failure to initialise * Check plugins initialised properly before adding to list of logging backends * Check the logger is available before trying to log a message (might cause bugs if errors are logged very early in initialisation)
This commit is contained in:
@@ -18,6 +18,9 @@ class SihnonFramework_Log_Plugin_FlatFile extends SihnonFramework_Log_PluginBase
|
||||
$this->filename = $filename;
|
||||
$this->format = $format;
|
||||
|
||||
// Verify the given log file can be written to
|
||||
$this->verifyLogfile();
|
||||
|
||||
$this->fp = fopen($this->filename, 'a');
|
||||
}
|
||||
|
||||
@@ -32,6 +35,26 @@ class SihnonFramework_Log_Plugin_FlatFile extends SihnonFramework_Log_PluginBase
|
||||
return new self($instance, $filename, $format);
|
||||
}
|
||||
|
||||
protected function verifyLogfile() {
|
||||
// Check that the file exists, or can be created
|
||||
$file_ok = false;
|
||||
|
||||
if (preg_match('#php://(stderr|stdout)#', $this->filename)) {
|
||||
$file_ok = true;
|
||||
} else if (file_exists($this->filename) && is_writable($this->filename)) {
|
||||
$file_ok = true;
|
||||
} else {
|
||||
$directory = dirname($this->filename);
|
||||
if (file_exists($directory) && is_writeable($directory)) {
|
||||
$file_ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$file_ok) {
|
||||
throw new SihnonFramework_Exception_LogFileNotWriteable($this->filename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a new entry in the storage backend used by this logging plugin
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user