Optimize display of last N lines of files

This commit is contained in:
Jamie Cameron
2010-01-11 13:28:51 -08:00
parent 2408056e2d
commit 3aee447b73
4 changed files with 24 additions and 10 deletions

View 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.

View File

@ -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";

View 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.

View File

@ -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";