This commit is contained in:
cesar991 2016-09-28 12:54:43 +02:00
commit 29bf3dc1bd

View File

@ -19,7 +19,6 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
############################################################################### ###############################################################################
use strict; use strict;
use File::Basename; use File::Basename;
@ -188,7 +187,10 @@ sub parse_log (;$$) {
seek(LOGFILE, $Idx_pos, 0); seek(LOGFILE, $Idx_pos, 0);
# Parse log file # Parse log file
my @data; my %data;
# Matched line id
my $matched_line = 0;
if ( (defined($up_lines)) || (defined($bot_lines)) ){ if ( (defined($up_lines)) || (defined($bot_lines)) ){
# Detailed workmode # Detailed workmode
@ -210,8 +212,9 @@ sub parse_log (;$$) {
$flag = 1; $flag = 1;
# Push upper lines # Push upper lines
for (my $i = ($curr_line-$up_lines); $i<=$curr_line; $i++){ for (my $i = ($curr_line-$up_lines); $i<=$curr_line; $i++){
if ($i < 0) {next;}
if (defined ($lines[$i])) { if (defined ($lines[$i])) {
push (@data, $lines[$i]); push (@{$data{$matched_line}}, $lines[$i]);
} }
} }
@ -220,16 +223,17 @@ sub parse_log (;$$) {
# Push bottom lines # Push bottom lines
for (my $i = ($curr_line+$flag); $i<=($curr_line+$bot_lines); $i++){ for (my $i = ($curr_line+$flag); $i<=($curr_line+$bot_lines); $i++){
if (defined ($lines[$i])) { if (defined ($lines[$i])) {
push (@data, $lines[$i]); push (@{$data{$matched_line}}, $lines[$i]);
} }
} }
} }
$matched_line++;
} }
} }
else { # Standar workmode else { # Standar workmode
while ($line = <LOGFILE>) { while ($line = <LOGFILE>) {
if ($line =~ m/$Reg_exp/i) { if ($line =~ m/$Reg_exp/i) {
push @data, $line; push (@{$data{$matched_line++}}, $line);
} }
} }
} }
@ -240,7 +244,7 @@ sub parse_log (;$$) {
# Save the index file # Save the index file
save_idx(); save_idx();
return @data; return \%data;
} }
############################################################################### ###############################################################################
@ -262,11 +266,12 @@ sub print_summary() {
# SUB parse_log # SUB parse_log
# Print log data to stdout. # Print log data to stdout.
############################################################################### ###############################################################################
sub print_log (@) { sub print_log ($) {
my @data = @_; my $data = shift;
# No data # No data
if ($#data < 0) { my @kdata = keys (%{$data});
if ($#kdata < 0) {
print_summary() if ($summary_flag == 1); print_summary() if ($summary_flag == 1);
return; return;
} }
@ -276,8 +281,8 @@ sub print_log (@) {
my $output = "<log_module>\n"; my $output = "<log_module>\n";
$output .= "<source><![CDATA[" . $Module_name . "]]></source>\n"; $output .= "<source><![CDATA[" . $Module_name . "]]></source>\n";
$output .= "<data><![CDATA["; $output .= "<data><![CDATA[";
foreach my $line (@data) { foreach my $line (@kdata) {
$output .= $line; $output .= $data->{$line};
} }
$output .= "]]></data>"; $output .= "]]></data>";
$output .= "</log_module>\n"; $output .= "</log_module>\n";
@ -292,8 +297,12 @@ sub print_log (@) {
$output .= "<name><![CDATA[" . $Module_name . "]]></name>\n"; $output .= "<name><![CDATA[" . $Module_name . "]]></name>\n";
$output .= "<type><![CDATA[async_string]]></type>\n"; $output .= "<type><![CDATA[async_string]]></type>\n";
$output .= "<datalist>\n"; $output .= "<datalist>\n";
foreach my $line (@data) { foreach my $line (@kdata) {
$output .= "<data><value><![CDATA[$line]]></value></data>\n"; $output .= "<data><value><![CDATA[";
foreach my $content (@{$data->{$line}}) {
$output .= $content;
}
$output .= "]]></value></data>\n";
} }
$output .= "</datalist>\n"; $output .= "</datalist>\n";
$output .= "</module>\n"; $output .= "</module>\n";
@ -348,9 +357,9 @@ if (! -e $Idx_file) {
load_idx(); load_idx();
# Parse log file # Parse log file
my @data = parse_log($up_lines,$bot_lines); my $data = parse_log($up_lines,$bot_lines);
# Print output to stdout # Print output to stdout
print_log (@data); print_log ($data);
exit 0; exit 0;