]> git.mxchange.org Git - friendica.git/commitdiff
Fixed log file issues on a freshly installed Friendica.
authorAbinoam P. Marques Jr <abinoam@gmail.com>
Sat, 18 Feb 2012 22:19:35 +0000 (14:19 -0800)
committerAbinoam P. Marques Jr <abinoam@gmail.com>
Sat, 18 Feb 2012 22:19:35 +0000 (14:19 -0800)
* Check to see if log file exists.
* After trying to open it, check to see if it went ok.
* So, check to see if the file size != 0 (fread error with size = 0)

mod/admin.php

index c79af8d5ba33b6e6f418361f2822f65c7e1fd61b..028ed8624d86e353f8fd7d99b00a64e366c3fc06 100755 (executable)
@@ -635,23 +635,36 @@ function admin_page_logs(&$a){
        $t = get_markup_template("admin_logs.tpl");
 
        $f = get_config('system','logfile');
-       $size = filesize($f);
-       if($size > 5000000 || $size < 0)
-               $size = 5000000;
 
        $data = '';
-       $fp = fopen($f,'r');
-       if($fp) {
-               $seek = fseek($fp,0-$size,SEEK_END);
-               if($seek === 0) {
-                       fgets($fp); // throw away the first partial line
-                       $data = escape_tags(fread($fp,$size));
-                       while(! feof($fp))
-                               $data .= escape_tags(fread($fp,4096));
-               }
-               fclose($fp);
-       }
 
+       if(!file_exists($f)) {
+               $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is 
+readable.");
+       }
+       else {
+               $fp = fopen($f, 'r');
+               if(!$fp) {
+                       $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
+               }
+               else {
+                       $fstat = fstat($fp);
+                       $size = $fstat['size'];
+                       if($size != 0)
+                       {
+                               if($size > 5000000 || $size < 0)
+                                       $size = 5000000;
+                               $seek = fseek($fp,0-$size,SEEK_END);
+                               if($seek === 0) {
+                                       fgets($fp); // throw away the first partial line
+                                       $data = escape_tags(fread($fp,$size));
+                                       while(! feof($fp))
+                                               $data .= escape_tags(fread($fp,4096));
+                               }
+                       }
+                       fclose($fp);
+               }
+       }                       
 
        return replace_macros($t, array(
                '$title' => t('Administration'),