2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer
::logger
;
27 use installer
::globals
;
30 include_header_into_logfile
31 include_timestamp_into_logfile
34 copy_globalinfo_into_logfile
44 ####################################################
45 # Including header files into the logfile
46 ####################################################
48 sub include_header_into_logfile
54 $infoline = "\n" . _get_time_string
();
55 push( @installer::globals
::logfileinfo
, $infoline);
57 $infoline = "######################################################\n";
58 push( @installer::globals
::logfileinfo
, $infoline);
60 $infoline = "$message\n";
61 push( @installer::globals
::logfileinfo
, $infoline);
64 $infoline = "######################################################\n";
65 push( @installer::globals
::logfileinfo
, $infoline);
68 ####################################################
69 # Write timestamp into log file
70 ####################################################
72 sub include_timestamp_into_logfile
77 my $timestring = _get_time_string
();
78 $infoline = "$message\t$timestring";
79 push( @installer::globals
::logfileinfo
, $infoline);
82 ####################################################
83 # Writing all variables content into the log file
84 ####################################################
90 my $infoline = "\nLogging variable settings:\n";
91 push(@installer::globals
::globallogfileinfo
, $infoline);
95 foreach $itemkey ( keys %{$hashref} )
99 if ( $hashref->{$itemkey} ) { $itemvalue = $hashref->{$itemkey}; }
100 $line = $itemkey . "=" . $itemvalue . "\n";
101 push(@installer::globals
::globallogfileinfo
, $line);
105 push(@installer::globals
::globallogfileinfo
, $infoline);
108 #########################################################
109 # Including global logging info into global log array
110 #########################################################
118 $infoline = "\n" . _get_time_string
();
119 push( @installer::globals
::globallogfileinfo
, $infoline);
121 $infoline = "######################################################\n";
122 push( @installer::globals
::globallogfileinfo
, $infoline);
124 $infoline = "$message\n";
125 push( @installer::globals
::globallogfileinfo
, $infoline);
127 $infoline = "######################################################\n";
128 push( @installer::globals
::globallogfileinfo
, $infoline);
132 ###############################################################
133 # For each product (new language) a new log file is created.
134 # Therefore the global logging has to be saved in this file.
135 ###############################################################
137 sub copy_globalinfo_into_logfile
139 for ( my $i = 0; $i <= $#installer::globals
::globallogfileinfo
; $i++ )
141 push(@installer::globals
::logfileinfo
, $installer::globals
::globallogfileinfo
[$i]);
145 ###############################################################
147 ###############################################################
154 ###############################################################
155 # Convert time string
156 ###############################################################
158 sub _convert_timestring
160 my ($secondstring) = @_;
164 if ( $secondstring < 60 ) # less than a minute
166 if ( $secondstring < 10 ) { $secondstring = "0" . $secondstring; }
167 $timestring = "00\:$secondstring min\.";
169 elsif ( $secondstring < 3600 )
171 my $minutes = $secondstring / 60;
172 my $seconds = $secondstring % 60;
173 if ( $minutes =~ /(\d*)\.\d*/ ) { $minutes = $1; }
174 if ( $minutes < 10 ) { $minutes = "0" . $minutes; }
175 if ( $seconds < 10 ) { $seconds = "0" . $seconds; }
176 $timestring = "$minutes\:$seconds min\.";
178 else # more than one hour
180 my $hours = $secondstring / 3600;
181 my $secondstring = $secondstring % 3600;
182 my $minutes = $secondstring / 60;
183 my $seconds = $secondstring % 60;
184 if ( $hours =~ /(\d*)\.\d*/ ) { $hours = $1; }
185 if ( $minutes =~ /(\d*)\.\d*/ ) { $minutes = $1; }
186 if ( $hours < 10 ) { $hours = "0" . $hours; }
187 if ( $minutes < 10 ) { $minutes = "0" . $minutes; }
188 if ( $seconds < 10 ) { $seconds = "0" . $seconds; }
189 $timestring = "$hours\:$minutes\:$seconds hours";
195 ###############################################################
196 # Returning time string for logging
197 ###############################################################
201 my $currenttime = time();
202 $currenttime = $currenttime - $starttime;
203 $currenttime = _convert_timestring
($currenttime);
204 $currenttime = localtime() . " \(" . $currenttime . "\)\n";
208 ###############################################################
210 ###############################################################
214 print_message
( _get_time_string
() );
217 ###############################################################
218 # Console output: messages
219 ###############################################################
225 my $force = shift || 0;
226 print "$message\n" if ( $force || ! $installer::globals
::quiet
);
230 ###############################################################
231 # Console output: warnings
232 ###############################################################
238 print STDERR
"WARNING: $message";
242 ###############################################################
243 # Console output: errors
244 ###############################################################
250 print STDERR
"\n**************************************************\n";
251 print STDERR
"ERROR: $message";
252 print STDERR
"\n**************************************************\n";