]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fall back to default log file if logfile config file not found, suppress writing...
authorMichael Gapczynski <mtgap@owncloud.com>
Mon, 17 Dec 2012 00:43:32 +0000 (19:43 -0500)
committerTom Needham <needham.thomas@gmail.com>
Sat, 29 Dec 2012 19:30:31 +0000 (19:30 +0000)
lib/log/owncloud.php

index ec43208d833459d9467c6f8ab3e16251c00d9089..e53dd5fefcd129099d6ffc8d1177719379ee5151 100644 (file)
@@ -33,8 +33,11 @@ class OC_Log_Owncloud {
         * Init class data
         */
        public static function init() {
-               $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' );
-               self::$logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' );
+               $defaultLogFile = OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data').'/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);
                if($level>=$minLevel) {
                        $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=>time());
-                       $fh=fopen(self::$logFile, 'a');
-                       fwrite($fh, json_encode($entry)."\n");
-                       fclose($fh);
+                       $handle = @fopen(self::$logFile, 'a');
+                       if ($handle) {
+                               fwrite($handle, json_encode($entry)."\n");
+                               fclose($handle);
+                       }
                }
        }