1#************************************************************************* 2# 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# Copyright 2000, 2010 Oracle and/or its affiliates. 6# 7# OpenOffice.org - a multi-platform office productivity suite 8# 9# This file is part of OpenOffice.org. 10# 11# OpenOffice.org is free software: you can redistribute it and/or modify 12# it under the terms of the GNU Lesser General Public License version 3 13# only, as published by the Free Software Foundation. 14# 15# OpenOffice.org is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU Lesser General Public License version 3 for more details 19# (a copy is included in the LICENSE file that accompanied this code). 20# 21# You should have received a copy of the GNU Lesser General Public License 22# version 3 along with OpenOffice.org. If not, see 23# <http://www.openoffice.org/license.html> 24# for a copy of the LGPLv3 License. 25# 26#************************************************************************* 27 28package installer::logger; 29 30use installer::files; 31use installer::globals; 32 33#################################################### 34# Including header files into the logfile 35#################################################### 36 37sub include_header_into_logfile 38{ 39 my ($message) = @_; 40 41 my $infoline; 42 43 $infoline = "\n" . get_time_string(); 44 push( @installer::globals::logfileinfo, $infoline); 45 46 $infoline = "######################################################\n"; 47 push( @installer::globals::logfileinfo, $infoline); 48 49 $infoline = "$message\n"; 50 push( @installer::globals::logfileinfo, $infoline); 51 52 53 $infoline = "######################################################\n"; 54 push( @installer::globals::logfileinfo, $infoline); 55} 56 57#################################################### 58# Including header files into the logfile 59#################################################### 60 61sub include_header_into_globallogfile 62{ 63 my ($message) = @_; 64 65 my $infoline; 66 67 $infoline = "\n" . get_time_string(); 68 push( @installer::globals::globallogfileinfo, $infoline); 69 70 $infoline = "######################################################\n"; 71 push( @installer::globals::globallogfileinfo, $infoline); 72 73 $infoline = "$message\n"; 74 push( @installer::globals::globallogfileinfo, $infoline); 75 76 77 $infoline = "######################################################\n"; 78 push( @installer::globals::globallogfileinfo, $infoline); 79} 80 81#################################################### 82# Write timestamp into log file 83#################################################### 84 85sub include_timestamp_into_logfile 86{ 87 my ($message) = @_; 88 89 my $infoline; 90 my $timestring = get_time_string(); 91 $infoline = "$message\t$timestring"; 92 push( @installer::globals::logfileinfo, $infoline); 93} 94 95#################################################### 96# Writing all variables content into the log file 97#################################################### 98 99sub log_hashref 100{ 101 my ($hashref) = @_; 102 103 my $infoline = "\nLogging variable settings:\n"; 104 push(@installer::globals::globallogfileinfo, $infoline); 105 106 my $itemkey; 107 108 foreach $itemkey ( keys %{$hashref} ) 109 { 110 my $line = ""; 111 my $itemvalue = ""; 112 if ( $hashref->{$itemkey} ) { $itemvalue = $hashref->{$itemkey}; } 113 $line = $itemkey . "=" . $itemvalue . "\n"; 114 push(@installer::globals::globallogfileinfo, $line); 115 } 116 117 $infoline = "\n"; 118 push(@installer::globals::globallogfileinfo, $infoline); 119} 120 121######################################################### 122# Including global logging info into global log array 123######################################################### 124 125sub globallog 126{ 127 my ($message) = @_; 128 129 my $infoline; 130 131 $infoline = "\n" . get_time_string(); 132 push( @installer::globals::globallogfileinfo, $infoline); 133 134 $infoline = "################################################################\n"; 135 push( @installer::globals::globallogfileinfo, $infoline); 136 137 $infoline = "$message\n"; 138 push( @installer::globals::globallogfileinfo, $infoline); 139 140 $infoline = "################################################################\n"; 141 push( @installer::globals::globallogfileinfo, $infoline); 142 143} 144 145############################################################### 146# For each product (new language) a new log file is created. 147# Therefore the global logging has to be saved in this file. 148############################################################### 149 150sub copy_globalinfo_into_logfile 151{ 152 for ( my $i = 0; $i <= $#installer::globals::globallogfileinfo; $i++ ) 153 { 154 push(@installer::globals::logfileinfo, $installer::globals::globallogfileinfo[$i]); 155 } 156} 157 158############################################################### 159# For each product (new language) a new log file is created. 160# Therefore the global logging has to be saved in this file. 161############################################################### 162 163sub debuginfo 164{ 165 my ( $message ) = @_; 166 167 $message = $message . "\n"; 168 push(@installer::globals::functioncalls, $message); 169} 170 171############################################################### 172# Saving the debug information. 173############################################################### 174 175sub savedebug 176{ 177 my ( $outputdir ) = @_; 178 179 installer::files::save_file($outputdir . $installer::globals::debugfilename, \@installer::globals::functioncalls); 180 print_message( "... writing debug file " . $outputdir . $installer::globals::debugfilename . "\n" ); 181} 182 183############################################################### 184# Starting the time 185############################################################### 186 187sub starttime 188{ 189 $installer::globals::starttime = time(); 190} 191 192############################################################### 193# Convert time string 194############################################################### 195 196sub convert_timestring 197{ 198 my ($secondstring) = @_; 199 200 my $timestring = ""; 201 202 if ( $secondstring < 60 ) # less than a minute 203 { 204 if ( $secondstring < 10 ) { $secondstring = "0" . $secondstring; } 205 $timestring = "00\:$secondstring min\."; 206 } 207 elsif ( $secondstring < 3600 ) 208 { 209 my $minutes = $secondstring / 60; 210 my $seconds = $secondstring % 60; 211 if ( $minutes =~ /(\d*)\.\d*/ ) { $minutes = $1; } 212 if ( $minutes < 10 ) { $minutes = "0" . $minutes; } 213 if ( $seconds < 10 ) { $seconds = "0" . $seconds; } 214 $timestring = "$minutes\:$seconds min\."; 215 } 216 else # more than one hour 217 { 218 my $hours = $secondstring / 3600; 219 my $secondstring = $secondstring % 3600; 220 my $minutes = $secondstring / 60; 221 my $seconds = $secondstring % 60; 222 if ( $hours =~ /(\d*)\.\d*/ ) { $hours = $1; } 223 if ( $minutes =~ /(\d*)\.\d*/ ) { $minutes = $1; } 224 if ( $hours < 10 ) { $hours = "0" . $hours; } 225 if ( $minutes < 10 ) { $minutes = "0" . $minutes; } 226 if ( $seconds < 10 ) { $seconds = "0" . $seconds; } 227 $timestring = "$hours\:$minutes\:$seconds hours"; 228 } 229 230 return $timestring; 231} 232 233############################################################### 234# Returning time string for logging 235############################################################### 236 237sub get_time_string 238{ 239 my $currenttime = time(); 240 $currenttime = $currenttime - $installer::globals::starttime; 241 $currenttime = convert_timestring($currenttime); 242 $currenttime = localtime() . " \(" . $currenttime . "\)\n"; 243 return $currenttime; 244} 245 246############################################################### 247# Returning the age of a file (in seconds) 248############################################################### 249 250sub get_file_age 251{ 252 my ( $filename ) = @_; 253 254 my $filetime = (stat($filename))[9]; 255 my $timediff = time() - $filetime; 256 return $timediff; 257} 258 259############################################################### 260# Stopping the time 261############################################################### 262 263sub stoptime 264{ 265 my $infoline = get_time_string(); 266 print_message( "$infoline" ); 267} 268 269############################################################### 270# Set date string, format: yymmdd 271############################################################### 272 273sub set_installation_date 274{ 275 my $datestring = ""; 276 277 my @timearray = localtime(time); 278 279 my $day = $timearray[3]; 280 my $month = $timearray[4] + 1; 281 my $year = $timearray[5] - 100; 282 283 if ( $year < 10 ) { $year = "0" . $year; } 284 if ( $month < 10 ) { $month = "0" . $month; } 285 if ( $day < 10 ) { $day = "0" . $day; } 286 287 $datestring = $year . $month . $day; 288 289 return $datestring; 290} 291 292############################################################### 293# Console output: messages 294############################################################### 295 296sub print_message 297{ 298 my $message = shift; 299 chomp $message; 300 my $force = shift || 0; 301 print "$message\n" if ( $force || ! $installer::globals::quiet ); 302 return; 303} 304 305sub print_message_without_newline 306{ 307 my $message = shift; 308 chomp $message; 309 print "$message" if ( ! $installer::globals::quiet ); 310 return; 311} 312 313############################################################### 314# Console output: warnings 315############################################################### 316 317sub print_warning 318{ 319 my $message = shift; 320 chomp $message; 321 print STDERR "WARNING: $message"; 322 return; 323} 324 325############################################################### 326# Console output: errors 327############################################################### 328 329sub print_error 330{ 331 my $message = shift; 332 chomp $message; 333 print STDERR "\n**************************************************\n"; 334 print STDERR "ERROR: $message"; 335 print STDERR "\n**************************************************\n"; 336 return; 337} 338 3391; 340