This is an automated email from the ASF dual-hosted git repository. mseidel pushed a commit to branch AOO42X in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit e73d4c7eb4e89a2180424c5141a15b0ad2d206c4 Author: Matthias Seidel <[email protected]> AuthorDate: Mon Feb 4 23:14:21 2019 +0000 Removed whitespace, fixed typo git-svn-id: https://svn.apache.org/repos/asf/openoffice/trunk@1852958 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit 8344c66800cbdb48d898915ffe7fee06739fd549) --- main/solenv/bin/modules/installer/logger.pm | 576 ++++++++++++++-------------- 1 file changed, 287 insertions(+), 289 deletions(-) diff --git a/main/solenv/bin/modules/installer/logger.pm b/main/solenv/bin/modules/installer/logger.pm index 7219ad4..c4116c5 100644 --- a/main/solenv/bin/modules/installer/logger.pm +++ b/main/solenv/bin/modules/installer/logger.pm @@ -1,5 +1,5 @@ #************************************************************** -# +# # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -7,16 +7,16 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# +# http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -# +# #************************************************************** @@ -37,91 +37,91 @@ sub Die ($); =head1 NAME - installer::logger + installer::logger - Logging for the installer modules. + Logging for the installer modules. =cut =head1 DESCRIPTION - This module is in a transition state from a set of loosly connected functions to a single class. + This module is in a transition state from a set of loosely connected functions to a single class. - There are three globaly available logger objects: + There are three globally available logger objects: =over =item $Lang - is language specific and writes messages to a log file. + is language specific and writes messages to a log file. =cut =item $Glob - is independent of the current language. Its messages are prepended to each $Lang logger. + is independent of the current language. Its messages are prepended to each $Lang logger. =cut =item $Info - is for output to the console. + is for output to the console. =cut =back =cut - + our $Global = installer::logger->new("glob", - 'is_save_lines' => 1, - 'is_print_to_console' => 0, - 'is_show_relative_time' => 1); + 'is_save_lines' => 1, + 'is_print_to_console' => 0, + 'is_show_relative_time' => 1); our $Lang = installer::logger->new("lang", - 'is_print_to_console' => 0, - 'is_show_relative_time' => 1, - 'is_show_log_id' => 1 - ); + 'is_print_to_console' => 0, + 'is_show_relative_time' => 1, + 'is_show_log_id' => 1 + ); our $Info = installer::logger->new("info", - 'is_show_relative_time' => 0, - 'is_show_process_id' => 0, - 'is_show_log_id' => 0 - ); + 'is_show_relative_time' => 0, + 'is_show_process_id' => 0, + 'is_show_log_id' => 0 + ); =head2 SetupSimpleLogging ($filename) - Setup logging so that $Global, $Lang and $Info all print to the console. - If $filename is given then logging also goes to that file. - + Setup logging so that $Global, $Lang and $Info all print to the console. + If $filename is given then logging also goes to that file. + =cut sub SetupSimpleLogging (;$) { - my ($log_filename) = @_; - - $Info = installer::logger->new("info", - 'is_print_to_console' => 1, - 'is_show_relative_time' => 1, - ); - $Global = installer::logger->new("glob", - 'is_print_to_console' => 0, - 'is_show_relative_time' => 1, - 'forward' => [$Info] - ); - $Lang = installer::logger->new("lang", - 'is_print_to_console' => 0, - 'is_show_relative_time' => 1, - 'forward' => [$Info] - ); - if (defined $log_filename) - { - $Info->set_filename($log_filename); - } - $Info->{'is_print_to_console'} = 1; - $installer::globals::quiet = 0; - starttime(); + my ($log_filename) = @_; + + $Info = installer::logger->new("info", + 'is_print_to_console' => 1, + 'is_show_relative_time' => 1, + ); + $Global = installer::logger->new("glob", + 'is_print_to_console' => 0, + 'is_show_relative_time' => 1, + 'forward' => [$Info] + ); + $Lang = installer::logger->new("lang", + 'is_print_to_console' => 0, + 'is_show_relative_time' => 1, + 'forward' => [$Info] + ); + if (defined $log_filename) + { + $Info->set_filename($log_filename); + } + $Info->{'is_print_to_console'} = 1; + $installer::globals::quiet = 0; + starttime(); } @@ -129,68 +129,68 @@ sub SetupSimpleLogging (;$) =head2 new($class, $id, @arguments) - Create a new instance of the logger class. - @arguments lets you override default values. + Create a new instance of the logger class. + @arguments lets you override default values. =cut sub new ($$@) { - my ($class, $id, @arguments) = @_; - - my $self = { - 'id' => $id, - 'filename' => "", - # When set then lines are printed to this file. - 'file' => undef, - # When true then lines are printed to the console. - 'is_print_to_console' => 1, - 'is_save_lines' => 0, - # A container of printed lines. Lines are added only when 'is_save_lines' is true. - 'lines' => [], - # Another logger to which all prints are forwarded. - 'forward' => [], - # A filter function that for example can recoginze build errors. - 'filter' => undef, - # Show relative time - 'is_show_relative_time' => 0, - # Show log id (mostly for debugging the logger) - 'is_show_log_id' => 0, - # Show the process id, useful on the console when doing a multiprocessor build. - 'is_show_process_id' => 0, - # Current indentation - 'indentation' => "", - }; - while (scalar @arguments >= 2) - { - my $key = shift @arguments; - my $value = shift @arguments; - $self->{$key} = $value; - } - - bless($self, $class); - - return $self; + my ($class, $id, @arguments) = @_; + + my $self = { + 'id' => $id, + 'filename' => "", + # When set then lines are printed to this file. + 'file' => undef, + # When true then lines are printed to the console. + 'is_print_to_console' => 1, + 'is_save_lines' => 0, + # A container of printed lines. Lines are added only when 'is_save_lines' is true. + 'lines' => [], + # Another logger to which all prints are forwarded. + 'forward' => [], + # A filter function that for example can recognize build errors. + 'filter' => undef, + # Show relative time + 'is_show_relative_time' => 0, + # Show log id (mostly for debugging the logger). + 'is_show_log_id' => 0, + # Show the process id, useful on the console when doing a multiprocessor build. + 'is_show_process_id' => 0, + # Current indentation. + 'indentation' => "", + }; + while (scalar @arguments >= 2) + { + my $key = shift @arguments; + my $value = shift @arguments; + $self->{$key} = $value; + } + + bless($self, $class); + + return $self; } =head2 printf($self, $message, @arguments) - Identical in syntax and semantics to the usual perl (s)printf. + Identical in syntax and semantics to the usual perl (s)printf. =cut sub printf ($$@) { - my ($self, $format, @arguments) = @_; + my ($self, $format, @arguments) = @_; - if ($format =~ /\%\{/) - { - printf(">%s<\n", $format); - PrintStackTrace(); - } - my $message = sprintf($format, @arguments); - $self->print($message, 0); + if ($format =~ /\%\{/) + { + printf(">%s<\n", $format); + PrintStackTrace(); + } + my $message = sprintf($format, @arguments); + $self->print($message, 0); } @@ -198,29 +198,29 @@ sub printf ($$@) =head2 print ($self, $message, [optional] $force) - Print the given message. - If the optional $force parameter is given and it evaluates to true then the message - is printed even when the golbal $installer::globals::quiet is true. + Print the given message. + If the optional $force parameter is given and it evaluates to true then the message + is printed even when the global $installer::globals::quiet is true. =cut sub print ($$;$) { - my ($self, $message, $force) = @_; + my ($self, $message, $force) = @_; - Die "newline at start of line" if ($message =~ /^\n.+/); + Die "newline at start of line" if ($message =~ /^\n.+/); - $force = 0 unless defined $force; + $force = 0 unless defined $force; - my $relative_time = tv_interval($StartTime, [gettimeofday()]); - foreach my $target ($self, @{$self->{'forward'}}) - { - $target->process_line( - $relative_time, - $self->{'id'}, - $PID, - $message, - $force); - } + my $relative_time = tv_interval($StartTime, [gettimeofday()]); + foreach my $target ($self, @{$self->{'forward'}}) + { + $target->process_line( + $relative_time, + $self->{'id'}, + $PID, + $message, + $force); + } } @@ -228,55 +228,55 @@ sub print ($$;$) =head2 process_line ($self, $relative_time, $log_id, $pid, $message, $force) - Internal function that decides whether to - a) write to a log file - b) print to the console - c) store in an array for later use - the preformatted message. + Internal function that decides whether to + a) write to a log file + b) print to the console + c) store in an array for later use + the preformatted message. =cut sub process_line ($$$$$$) { - my ($self, $relative_time, $log_id, $pid, $message, $force) = @_; - - # Apply the line filter. - if (defined $self->{'filter'}) - { - $message = &{$self->{'filter'}}($relative_time, $log_id, $pid, $message); - } - - # Format the line. - my $line = ""; - if ($self->{'is_show_relative_time'}) - { - $line .= sprintf("%12.6f : ", $relative_time); - } - if ($self->{'is_show_log_id'}) - { - $line .= $log_id . " : "; - } - if ($self->{'is_show_process_id'}) - { - $line .= $pid . " : "; - } - $line .= $self->{'indentation'}; - $line .= $message; - - # Print the line to a file or to the console or store it for later use. - my $fid = $self->{'file'}; - if (defined $fid) - { - print $fid ($line); - } - if (($force || ! $installer::globals::quiet) - && $self->{'is_print_to_console'}) - { - print($line); - } - if ($self->{'is_save_lines'}) - { - push @{$self->{'lines'}}, [$relative_time, $log_id, $pid, $message, $force]; - } + my ($self, $relative_time, $log_id, $pid, $message, $force) = @_; + + # Apply the line filter. + if (defined $self->{'filter'}) + { + $message = &{$self->{'filter'}}($relative_time, $log_id, $pid, $message); + } + + # Format the line. + my $line = ""; + if ($self->{'is_show_relative_time'}) + { + $line .= sprintf("%12.6f : ", $relative_time); + } + if ($self->{'is_show_log_id'}) + { + $line .= $log_id . " : "; + } + if ($self->{'is_show_process_id'}) + { + $line .= $pid . " : "; + } + $line .= $self->{'indentation'}; + $line .= $message; + + # Print the line to a file or to the console or store it for later use. + my $fid = $self->{'file'}; + if (defined $fid) + { + print $fid ($line); + } + if (($force || ! $installer::globals::quiet) + && $self->{'is_print_to_console'}) + { + print($line); + } + if ($self->{'is_save_lines'}) + { + push @{$self->{'lines'}}, [$relative_time, $log_id, $pid, $message, $force]; + } } @@ -284,55 +284,55 @@ sub process_line ($$$$$$) =head2 set_filename (Self, $filename) - When the name of a writable file is given then all future messages will go to that file. - Output to the console is turned off. - This method is typically used to tie the language dependent $Lang logger to different log files. + When the name of a writable file is given then all future messages will go to that file. + Output to the console is turned off. + This method is typically used to tie the language dependent $Lang logger to different log files. =cut sub set_filename ($$) { - my ($self, $filename) = @_; - - $filename = "" unless defined $filename; - if ($self->{'filename'} ne $filename) - { - if (defined $self->{'file'}) - { - $self->{'is_print_to_console'} = 1; - close $self->{'file'}; - $self->{'file'} = undef; - } + my ($self, $filename) = @_; - $self->{'filename'} = $filename; - - if ($filename ne "") - { - open $self->{'file'}, ">", $self->{'filename'} - || Die "can not open log file ".$self->{'filename'}." for writing"; - $self->{'is_print_to_console'} = 0; - - # Make all writes synchronous so that we don't loose any messages on an - # 'abrupt' end. - my $handle = select $self->{'file'}; - $| = 1; - select $handle; - } - } + $filename = "" unless defined $filename; + if ($self->{'filename'} ne $filename) + { + if (defined $self->{'file'}) + { + $self->{'is_print_to_console'} = 1; + close $self->{'file'}; + $self->{'file'} = undef; + } + + $self->{'filename'} = $filename; + + if ($filename ne "") + { + open $self->{'file'}, ">", $self->{'filename'} + || Die "can not open log file ".$self->{'filename'}." for writing"; + $self->{'is_print_to_console'} = 0; + + # Make all writes synchronous so that we don't loose any messages on an + # 'abrupt' end. + my $handle = select $self->{'file'}; + $| = 1; + select $handle; + } + } } =head2 set_filter ($self, $filter) - - Sets $filter (a function reference) as line filter. It is applied to each line. - The filter can extract information from the given message and modify it before it is printed. + + Sets $filter (a function reference) as line filter. It is applied to each line. + The filter can extract information from the given message and modify it before it is printed. =cut sub set_filter ($$) { - my ($self, $filter) = @_; - $self->{'filter'} = $filter; + my ($self, $filter) = @_; + $self->{'filter'} = $filter; } @@ -340,36 +340,36 @@ sub set_filter ($$) =head2 add_timestamp ($self, $message) - Print the given message together with the current (absolute) time. + Print the given message together with the current (absolute) time. =cut sub add_timestamp ($$) { my ($self, $message) = @_; - + my $timestring = get_time_string(); - $self->printf("%s\t%s", $message, $timestring); + $self->printf("%s\t%s", $message, $timestring); } =head2 copy_lines_from ($self, $other) - Copy saved lines from another logger object. + Copy saved lines from another logger object. =cut sub copy_lines_from ($$) { - my ($self, $other) = @_; + my ($self, $other) = @_; - my $is_print_to_console = $self->{'is_print_to_console'}; - my $is_save_lines = $self->{'is_save_lines'}; - my $fid = $self->{'file'}; + my $is_print_to_console = $self->{'is_print_to_console'}; + my $is_save_lines = $self->{'is_save_lines'}; + my $fid = $self->{'file'}; - foreach my $line (@{$other->{'lines'}}) - { - $self->process_line(@$line); - } + foreach my $line (@{$other->{'lines'}}) + { + $self->process_line(@$line); + } } @@ -377,24 +377,24 @@ sub copy_lines_from ($$) =head2 set_forward ($self, $other) - Set a forwarding target. All future messages are forwarded (copied) to $other. - A typical use is to tie $Info to $Lang so that all messages sent to $Info are - printed to the console AND written to the log file. + Set a forwarding target. All future messages are forwarded (copied) to $other. + A typical use is to tie $Info to $Lang so that all messages sent to $Info are + printed to the console AND written to the log file. =cut sub set_forward ($$) { - my ($self, $other) = @_; + my ($self, $other) = @_; - # At the moment at most one forward target is allowed. - if (defined $other) - { - $self->{'forward'} = [$other]; - } - else - { - $self->{'forward'} = []; - } + # At the moment at most one forward target is allowed. + if (defined $other) + { + $self->{'forward'} = [$other]; + } + else + { + $self->{'forward'} = []; + } } @@ -402,8 +402,8 @@ sub set_forward ($$) sub increase_indentation ($) { - my ($self) = @_; - $self->{'indentation'} .= " "; + my ($self) = @_; + $self->{'indentation'} .= " "; } @@ -411,8 +411,8 @@ sub increase_indentation ($) sub decrease_indentation ($) { - my ($self) = @_; - $self->{'indentation'} = substr($self->{'indentation'}, 4); + my ($self) = @_; + $self->{'indentation'} = substr($self->{'indentation'}, 4); } @@ -440,7 +440,7 @@ sub include_header_into_logfile sub include_header_into_globallogfile { my ($message) = @_; - + $Global->print("\n"); $Global->print(get_time_string()); $Global->print("######################################################\n"); @@ -454,12 +454,12 @@ sub include_header_into_globallogfile sub include_timestamp_into_logfile { - Die "deprected"; + Die "deprecated"; my ($message) = @_; - + my $infoline; my $timestring = get_time_string(); - $Lang->printf("%s\t%s", $message, $timestring); + $Lang->printf("%s\t%s", $message, $timestring); } #################################################### @@ -470,20 +470,20 @@ sub log_hashref { my ($hashref) = @_; - $Global->print("\n"); - $Global->print("Logging variable settings:\n"); + $Global->print("\n"); + $Global->print("Logging variable settings:\n"); my $itemkey; - + foreach $itemkey ( keys %{$hashref} ) { my $line = ""; my $itemvalue = ""; if ( $hashref->{$itemkey} ) { $itemvalue = $hashref->{$itemkey}; } - $Global->printf("%s=%s\n", $itemkey, $itemvalue); + $Global->printf("%s=%s\n", $itemkey, $itemvalue); } - $Global->print("\n"); + $Global->print("\n"); } ######################################################### @@ -496,11 +496,11 @@ sub globallog my $infoline; - $Global->print("\n"); - $Global->print(get_time_string()); - $Global->print("################################################################\n"); - $Global->print($message."\n"); - $Global->print("################################################################\n"); + $Global->print("\n"); + $Global->print(get_time_string()); + $Global->print("################################################################\n"); + $Global->print($message."\n"); + $Global->print("################################################################\n"); } ############################################################### @@ -523,8 +523,8 @@ sub copy_globalinfo_into_logfile sub debuginfo { - my ( $message ) = @_; - + my ( $message ) = @_; + $message = $message . "\n"; push(@installer::globals::functioncalls, $message); } @@ -536,8 +536,8 @@ sub debuginfo sub savedebug { my ( $outputdir ) = @_; - - installer::files::save_file($outputdir . $installer::globals::debugfilename, \@installer::globals::functioncalls); + + installer::files::save_file($outputdir . $installer::globals::debugfilename, \@installer::globals::functioncalls); print_message( "... writing debug file " . $outputdir . $installer::globals::debugfilename . "\n" ); } @@ -546,11 +546,11 @@ sub savedebug ############################################################### sub starttime -{ +{ $installer::globals::starttime = time(); $StartTime = [gettimeofday()]; - my $localtime = localtime(); + my $localtime = localtime(); } ############################################################### @@ -562,11 +562,11 @@ sub convert_timestring my ($secondstring) = @_; my $timestring = ""; - + if ( $secondstring < 60 ) # less than a minute { if ( $secondstring < 10 ) { $secondstring = "0" . $secondstring; } - $timestring = "00\:$secondstring min\."; + $timestring = "00\:$secondstring min\."; } elsif ( $secondstring < 3600 ) { @@ -588,9 +588,9 @@ sub convert_timestring if ( $hours < 10 ) { $hours = "0" . $hours; } if ( $minutes < 10 ) { $minutes = "0" . $minutes; } if ( $seconds < 10 ) { $seconds = "0" . $seconds; } - $timestring = "$hours\:$minutes\:$seconds hours"; + $timestring = "$hours\:$minutes\:$seconds hours"; } - + return $timestring; } @@ -614,7 +614,7 @@ sub get_time_string sub get_file_age { my ( $filename ) = @_; - + my $filetime = (stat($filename))[9]; my $timediff = time() - $filetime; return $timediff; @@ -626,8 +626,8 @@ sub get_file_age sub stoptime { - my $localtime = localtime(); - $Info->printf("stopping log at %s\n", $localtime); + my $localtime = localtime(); + $Info->printf("stopping log at %s\n", $localtime); } ############################################################### @@ -643,10 +643,10 @@ sub set_installation_date my $day = $timearray[3]; my $month = $timearray[4] + 1; my $year = $timearray[5] - 100; - - if ( $year < 10 ) { $year = "0" . $year; } - if ( $month < 10 ) { $month = "0" . $month; } - if ( $day < 10 ) { $day = "0" . $day; } + + if ( $year < 10 ) { $year = "0" . $year; } + if ( $month < 10 ) { $month = "0" . $month; } + if ( $day < 10 ) { $day = "0" . $day; } $datestring = $year . $month . $day; @@ -659,21 +659,21 @@ sub set_installation_date sub print_message { - Die "print_message is deprecated"; + Die "print_message is deprecated"; - my $message = shift; - chomp $message; - my $force = shift || 0; - print "$message\n" if ( $force || ! $installer::globals::quiet ); - return; + my $message = shift; + chomp $message; + my $force = shift || 0; + print "$message\n" if ( $force || ! $installer::globals::quiet ); + return; } sub print_message_without_newline { - my $message = shift; - chomp $message; - print "$message" if ( ! $installer::globals::quiet ); - return; + my $message = shift; + chomp $message; + print "$message" if ( ! $installer::globals::quiet ); + return; } ############################################################### @@ -682,10 +682,10 @@ sub print_message_without_newline sub print_warning { - my $message = shift; - chomp $message; - print STDERR "WARNING: $message"; - return; + my $message = shift; + chomp $message; + print STDERR "WARNING: $message"; + return; } ############################################################### @@ -694,17 +694,17 @@ sub print_warning sub print_error { - my $message = shift; - chomp $message; + my $message = shift; + chomp $message; - PrintError($message); + PrintError($message); - print STDERR "\n"; - print STDERR "**************************************************\n"; - print STDERR "ERROR: $message"; - print STDERR "\n"; - print STDERR "**************************************************\n"; - return; + print STDERR "\n"; + print STDERR "**************************************************\n"; + print STDERR "ERROR: $message"; + print STDERR "\n"; + print STDERR "**************************************************\n"; + return; } @@ -712,36 +712,34 @@ sub print_error sub PrintError ($@) { - my ($format, @arguments) = @_; + my ($format, @arguments) = @_; - $Info->printf("Error: ".$format, @arguments); + $Info->printf("Error: ".$format, @arguments); } =head2 PrintStackTrace() - This is for debugging the print and printf methods of the logger class and their use. - Therefore we use the Perl print/printf directly and not the logger methods to avoid loops in case of errors. + This is for debugging the print and printf methods of the logger class and their use. + Therefore we use the Perl print/printf directly and not the logger methods to avoid loops in case of errors. =cut sub PrintStackTrace () { - print "Stack Trace:\n"; - my $i = 1; - while ((my @call_details = (caller($i++)))) - { - printf("%s:%s in function %s\n", $call_details[1], $call_details[2], $call_details[3]); - } + print "Stack Trace:\n"; + my $i = 1; + while ((my @call_details = (caller($i++)))) + { + printf("%s:%s in function %s\n", $call_details[1], $call_details[2], $call_details[3]); + } } sub Die ($) { - my ($message) = @_; - PrintStackTrace(); - die $message; + my ($message) = @_; + PrintStackTrace(); + die $message; } - - 1;
