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