Optimize display of last N lines of files
authorJamie Cameron <jcameron@webmin.com>
Mon, 11 Jan 2010 21:28:51 +0000 (13:28 -0800)
committerJamie Cameron <jcameron@webmin.com>
Mon, 11 Jan 2010 21:28:51 +0000 (13:28 -0800)
syslog-ng/CHANGELOG
syslog-ng/view_log.cgi
syslog/CHANGELOG
syslog/save_log.cgi

index 1934a13..4d21a64 100644 (file)
@@ -2,3 +2,5 @@
 First version of this module.
 ---- Changes since 1.270 ----
 Error logs from Webmin and Usermin, and kernel messages are now viewable in this module.
+---- Changes since 1.500 ----
+Speed up the un-filtered display of the last N lines of a log file, by just running tail on it directly.
index 8e791d0..cd94f36 100755 (executable)
@@ -64,11 +64,13 @@ if ($filter ne "") {
 else {
        # Not filtering .. so cat the most recent non-empty file
        if ($cmd) {
-               $catter = $cmd;
+                # Getting output from a command
+                $fullcmd = $cmd." | ".$tailcmd;
                }
-       else {
+       elsif ($config{'compressed'}) {
+               # Find the first non-empty file, newest first
                $catter = "cat ".quotemeta($file);
-               if (!-s $file && $config{'compressed'}) {
+               if (!-s $file) {
                        foreach $l (&all_log_files($file)) {
                                next if (!-s $l);
                                $c = &catter_command($l);
@@ -78,10 +80,14 @@ else {
                                        }
                                }
                        }
+               $fullcmd = $catter." | ".$tailcmd;
+               }
+       else {
+               # Just run tail on the file
+               $fullcmd = $tailcmd." ".quotemeta($file);
                }
        $got = &foreign_call("proc", "safe_process_exec",
-               $catter." | $tailcmd", 
-               0, 0, STDOUT, undef, 1, 0, undef, 1);
+               $fullcmd, 0, 0, STDOUT, undef, 1, 0, undef, 1);
        }
 print "<i>$text{'view_empty'}</i>\n" if (!$got);
 print "</pre>\n";
index 1fba4f3..b3a628c 100644 (file)
@@ -16,3 +16,5 @@ Added support for rsyslogd, as seen by default on Debian 5.0.
 Rsyslog format tags in the config file are now recogized and preserved, rather than being included in the log filename.
 ---- Changes since 1.490 ----
 Added support for rsyslog IncludeConfig directives, which are used to split the config into multiple files, as seen on Ubuntu 9.
+---- Changes since 1.500 ----
+Speed up the un-filtered display of the last N lines of a log file, by just running tail on it directly.
index 3cc4dc5..5d2e017 100755 (executable)
@@ -97,12 +97,12 @@ elsif ($in{'view'}) {
                # Not filtering .. so cat the most recent non-empty file
                if ($cmd) {
                        # Getting output from a command
-                       $catter = $cmd;
+                       $fullcmd = $cmd." | ".$tailcmd;
                        }
-               else {
+               elsif ($config{'compressed'}) {
                        # Find the first non-empty file, newest first
                        $catter = "cat ".quotemeta($file);
-                       if (!-s $file && $config{'compressed'}) {
+                       if (!-s $file) {
                                foreach $l (reverse(&all_log_files($file))) {
                                        next if (!-s $l);
                                        $c = &catter_command($l);
@@ -112,10 +112,14 @@ elsif ($in{'view'}) {
                                                }
                                        }
                                }
+                       $fullcmd = $catter." | ".$tailcmd;
+                       }
+               else {
+                       # Just run tail on the file
+                       $fullcmd = $tailcmd." ".quotemeta($file);
                        }
                $got = &foreign_call("proc", "safe_process_exec",
-                       $catter." | $tailcmd", 
-                       0, 0, STDOUT, undef, 1, 0, undef, 1);
+                       $fullcmd, 0, 0, STDOUT, undef, 1, 0, undef, 1);
                }
        print "<i>$text{'view_empty'}</i>\n" if (!$got);
        print "</pre>\n";