Fall back to default log file if logfile config file not found, suppress writing errors, fixes issue #826

This commit is contained in:
Michael Gapczynski 2012-12-16 19:43:32 -05:00 committed by Tom Needham
parent 0229b070c9
commit 7980bccaab
1 changed files with 10 additions and 5 deletions

View File

@ -33,8 +33,11 @@ class OC_Log_Owncloud {
* Init class data * Init class data
*/ */
public static function init() { public static function init() {
$datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' ); $defaultLogFile = OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log';
self::$logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' ); self::$logFile = OC_Config::getValue("logfile", $defaultLogFile);
if (!file_exists(self::$logFile)) {
self::$logFile = $defaultLogFile;
}
} }
/** /**
@ -47,9 +50,11 @@ class OC_Log_Owncloud {
$minLevel=min(OC_Config::getValue( "loglevel", OC_Log::WARN ), OC_Log::ERROR); $minLevel=min(OC_Config::getValue( "loglevel", OC_Log::WARN ), OC_Log::ERROR);
if($level>=$minLevel) { if($level>=$minLevel) {
$entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=>time()); $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=>time());
$fh=fopen(self::$logFile, 'a'); $handle = @fopen(self::$logFile, 'a');
fwrite($fh, json_encode($entry)."\n"); if ($handle) {
fclose($fh); fwrite($handle, json_encode($entry)."\n");
fclose($handle);
}
} }
} }