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