xref: /AOO41X/main/solenv/bin/modules/installer/logger.pm (revision 0374af7915f25fa61cbb53efb815651e31d9d658)
19780544fSAndrew Rist#**************************************************************
2cdf0e10cSrcweir#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
19cdf0e10cSrcweir#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::logger;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::files;
27cdf0e10cSrcweiruse installer::globals;
28b274bc22SAndre Fischeruse Time::HiRes qw(gettimeofday tv_interval);
29b274bc22SAndre Fischeruse English;
30b274bc22SAndre Fischeruse IO::Handle;
31b274bc22SAndre Fischeruse strict;
32b274bc22SAndre Fischer
33b274bc22SAndre Fischermy $StartTime = undef;
34b274bc22SAndre Fischer
35*0374af79SAndre Fischersub Die ($)
36*0374af79SAndre Fischer{
37*0374af79SAndre Fischer    my ($message) = @_;
38*0374af79SAndre Fischer    print "Stack Trace:\n";
39*0374af79SAndre Fischer    my $i = 1;
40*0374af79SAndre Fischer    while ((my @call_details = (caller($i++))))
41*0374af79SAndre Fischer    {
42*0374af79SAndre Fischer        printf("%s:%s in function %s\n", $call_details[1], $call_details[2], $call_details[3]);
43*0374af79SAndre Fischer    }
44*0374af79SAndre Fischer
45*0374af79SAndre Fischer    die $message;
46*0374af79SAndre Fischer}
47*0374af79SAndre Fischer
48*0374af79SAndre Fischer
49b274bc22SAndre Fischer=head1 NAME
50b274bc22SAndre Fischer
51b274bc22SAndre Fischer    installer::logger
52b274bc22SAndre Fischer
53b274bc22SAndre Fischer    Logging for the installer modules.
54b274bc22SAndre Fischer
55b274bc22SAndre Fischer=cut
56b274bc22SAndre Fischer
57b274bc22SAndre Fischer=head1 DESCRIPTION
58b274bc22SAndre Fischer
59b274bc22SAndre Fischer    This module is in a transition state from a set of loosly connected functions to a single class.
60b274bc22SAndre Fischer
61b274bc22SAndre Fischer    There are three globaly available logger objects:
62b274bc22SAndre Fischer
63b274bc22SAndre Fischer=over
64b274bc22SAndre Fischer
65b274bc22SAndre Fischer=item $Lang
66b274bc22SAndre Fischer
67b274bc22SAndre Fischer    is language specific and writes messages to a log file.
68b274bc22SAndre Fischer
69b274bc22SAndre Fischer=cut
70b274bc22SAndre Fischer
71b274bc22SAndre Fischer=item $Glob
72b274bc22SAndre Fischer
73b274bc22SAndre Fischer    is independent of the current language.  Its messages are prepended to each $Lang logger.
74b274bc22SAndre Fischer
75b274bc22SAndre Fischer=cut
76b274bc22SAndre Fischer
77b274bc22SAndre Fischer=item $Info
78b274bc22SAndre Fischer
79b274bc22SAndre Fischer    is for output to the console.
80b274bc22SAndre Fischer
81b274bc22SAndre Fischer=cut
82b274bc22SAndre Fischer
83b274bc22SAndre Fischer=back
84b274bc22SAndre Fischer
85b274bc22SAndre Fischer=cut
86b274bc22SAndre Fischer
87b274bc22SAndre Fischer
88b274bc22SAndre Fischerour $Global = installer::logger->new("glob",
89b274bc22SAndre Fischer    'is_save_lines' => 1,
90b274bc22SAndre Fischer    'is_print_to_console' => 0,
91b274bc22SAndre Fischer    'is_show_relative_time' => 1);
92b274bc22SAndre Fischerour $Lang = installer::logger->new("lang",
93b274bc22SAndre Fischer    'is_print_to_console' => 0,
94b274bc22SAndre Fischer    'is_show_relative_time' => 1,
95b274bc22SAndre Fischer    'is_show_log_id' => 1
96b274bc22SAndre Fischer    );
97b274bc22SAndre Fischerour $Info = installer::logger->new("info",
98b274bc22SAndre Fischer    'is_show_relative_time' => 0,
99b274bc22SAndre Fischer    'is_show_process_id' => 0,
100b274bc22SAndre Fischer    'is_show_log_id' => 0
101b274bc22SAndre Fischer    );
102b274bc22SAndre Fischer
103b274bc22SAndre Fischer=head2 new($class, $id, @arguments)
104b274bc22SAndre Fischer
105b274bc22SAndre Fischer    Create a new instance of the logger class.
106b274bc22SAndre Fischer    @arguments lets you override default values.
107b274bc22SAndre Fischer
108b274bc22SAndre Fischer=cut
109b274bc22SAndre Fischer
110b274bc22SAndre Fischersub new ($$@)
111b274bc22SAndre Fischer{
112b274bc22SAndre Fischer    my ($class, $id, @arguments) = @_;
113b274bc22SAndre Fischer
114b274bc22SAndre Fischer    my $self = {
115b274bc22SAndre Fischer        'id' => $id,
116b274bc22SAndre Fischer        'filename' => "",
117b274bc22SAndre Fischer        # When set then lines are printed to this file.
118b274bc22SAndre Fischer        'file' => undef,
119b274bc22SAndre Fischer        # When true then lines are printed to the console.
120b274bc22SAndre Fischer        'is_print_to_console' => 1,
121b274bc22SAndre Fischer        'is_save_lines' => 0,
122b274bc22SAndre Fischer        # A container of printed lines.  Lines are added only when 'is_save_lines' is true.
123b274bc22SAndre Fischer        'lines' => [],
124b274bc22SAndre Fischer        # Another logger to which all prints are forwarded.
125b274bc22SAndre Fischer        'forward' => [],
126b274bc22SAndre Fischer        # A filter function that for example can recoginze build errors.
127b274bc22SAndre Fischer        'filter' => undef,
128b274bc22SAndre Fischer        # Show relative time
129b274bc22SAndre Fischer        'is_show_relative_time' => 0,
130b274bc22SAndre Fischer        # Show log id (mostly for debugging the logger)
131b274bc22SAndre Fischer        'is_show_log_id' => 0,
132b274bc22SAndre Fischer        # Show the process id, useful on the console when doing a multiprocessor build.
133b274bc22SAndre Fischer        'is_show_process_id' => 0
134b274bc22SAndre Fischer    };
135b274bc22SAndre Fischer    while (scalar @arguments >= 2)
136b274bc22SAndre Fischer    {
137b274bc22SAndre Fischer        my $key = shift @arguments;
138b274bc22SAndre Fischer        my $value = shift @arguments;
139b274bc22SAndre Fischer        $self->{$key} = $value;
140b274bc22SAndre Fischer    }
141b274bc22SAndre Fischer
142b274bc22SAndre Fischer    bless($self, $class);
143b274bc22SAndre Fischer
144b274bc22SAndre Fischer    return $self;
145b274bc22SAndre Fischer}
146b274bc22SAndre Fischer
147b274bc22SAndre Fischer
148b274bc22SAndre Fischer
149b274bc22SAndre Fischer=head2 printf($self, $message, @arguments)
150b274bc22SAndre Fischer
151b274bc22SAndre Fischer    Identical in syntax and semantics to the usual perl (s)printf.
152b274bc22SAndre Fischer
153b274bc22SAndre Fischer=cut
154b274bc22SAndre Fischersub printf ($$@)
155b274bc22SAndre Fischer{
156b274bc22SAndre Fischer    my ($self, $format, @arguments) = @_;
157b274bc22SAndre Fischer
158b274bc22SAndre Fischer    $self->print(sprintf($format, @arguments), 0);
159b274bc22SAndre Fischer}
160b274bc22SAndre Fischer
161b274bc22SAndre Fischer
162b274bc22SAndre Fischer
163b274bc22SAndre Fischer
164b274bc22SAndre Fischer=head2 print ($self, $message, [optional] $force)
165b274bc22SAndre Fischer
166b274bc22SAndre Fischer    Print the given message.
167b274bc22SAndre Fischer    If the optional $force parameter is given and it evaluates to true then the message
168b274bc22SAndre Fischer    is printed even when the golbal $installer::globals::quiet is true.
169b274bc22SAndre Fischer
170b274bc22SAndre Fischer=cut
171b274bc22SAndre Fischersub print ($$;$)
172b274bc22SAndre Fischer{
173b274bc22SAndre Fischer    my ($self, $message, $force) = @_;
174b274bc22SAndre Fischer
175*0374af79SAndre Fischer    Die "newline at start of line" if ($message =~ /^\n.+/);
176b274bc22SAndre Fischer
177b274bc22SAndre Fischer    $force = 0 unless defined $force;
178b274bc22SAndre Fischer
179b274bc22SAndre Fischer    my $relative_time = tv_interval($StartTime, [gettimeofday()]);
180b274bc22SAndre Fischer    foreach my $target ($self, @{$self->{'forward'}})
181b274bc22SAndre Fischer    {
182b274bc22SAndre Fischer        $target->process_line(
183b274bc22SAndre Fischer            $relative_time,
184b274bc22SAndre Fischer            $self->{'id'},
185b274bc22SAndre Fischer            $PID,
186b274bc22SAndre Fischer            $message,
187b274bc22SAndre Fischer            $force);
188b274bc22SAndre Fischer    }
189b274bc22SAndre Fischer}
190b274bc22SAndre Fischer
191b274bc22SAndre Fischer
192b274bc22SAndre Fischer
193b274bc22SAndre Fischer
194b274bc22SAndre Fischer=head2 process_line ($self, $relative_time, $log_id, $pid, $message, $force)
195b274bc22SAndre Fischer
196b274bc22SAndre Fischer    Internal function that decides whether to
197b274bc22SAndre Fischer    a) write to a log file
198b274bc22SAndre Fischer    b) print to the console
199b274bc22SAndre Fischer    c) store in an array for later use
200b274bc22SAndre Fischer    the preformatted message.
201b274bc22SAndre Fischer
202b274bc22SAndre Fischer=cut
203b274bc22SAndre Fischersub process_line ($$$$$$)
204b274bc22SAndre Fischer{
205b274bc22SAndre Fischer    my ($self, $relative_time, $log_id, $pid, $message, $force) = @_;
206b274bc22SAndre Fischer
207b274bc22SAndre Fischer    # Apply the line filter.
208b274bc22SAndre Fischer    if (defined $self->{'filter'})
209b274bc22SAndre Fischer    {
210b274bc22SAndre Fischer        $message = &{$self->{'filter'}}($relative_time, $log_id, $pid, $message);
211b274bc22SAndre Fischer    }
212b274bc22SAndre Fischer
213b274bc22SAndre Fischer    # Format the line.
214b274bc22SAndre Fischer    my $line = "";
215b274bc22SAndre Fischer    if ($self->{'is_show_relative_time'})
216b274bc22SAndre Fischer    {
217b274bc22SAndre Fischer        $line .= sprintf("%12.6f : ", $relative_time);
218b274bc22SAndre Fischer    }
219b274bc22SAndre Fischer    if ($self->{'is_show_log_id'})
220b274bc22SAndre Fischer    {
221b274bc22SAndre Fischer        $line .= $log_id . " : ";
222b274bc22SAndre Fischer    }
223b274bc22SAndre Fischer    if ($self->{'is_show_process_id'})
224b274bc22SAndre Fischer    {
225b274bc22SAndre Fischer        $line .= $pid . " : ";
226b274bc22SAndre Fischer    }
227b274bc22SAndre Fischer    $line .= $message;
228b274bc22SAndre Fischer
229b274bc22SAndre Fischer    # Print the line to a file or to the console or store it for later use.
230b274bc22SAndre Fischer    my $fid = $self->{'file'};
231b274bc22SAndre Fischer    if (defined $fid)
232b274bc22SAndre Fischer    {
233b274bc22SAndre Fischer        print $fid ($line);
234b274bc22SAndre Fischer    }
235b274bc22SAndre Fischer    if (($force || ! $installer::globals::quiet)
236b274bc22SAndre Fischer        && $self->{'is_print_to_console'})
237b274bc22SAndre Fischer    {
238b274bc22SAndre Fischer        print($line);
239b274bc22SAndre Fischer    }
240b274bc22SAndre Fischer    if ($self->{'is_save_lines'})
241b274bc22SAndre Fischer    {
242b274bc22SAndre Fischer        push @{$self->{'lines'}}, [$relative_time, $log_id, $pid, $message, $force];
243b274bc22SAndre Fischer    }
244b274bc22SAndre Fischer}
245b274bc22SAndre Fischer
246b274bc22SAndre Fischer
247b274bc22SAndre Fischer
248b274bc22SAndre Fischer
249b274bc22SAndre Fischer=head2 set_filename (Self, $filename)
250b274bc22SAndre Fischer
251b274bc22SAndre Fischer    When the name of a writable file is given then all future messages will go to that file.
252b274bc22SAndre Fischer    Output to the console is turned off.
253b274bc22SAndre Fischer    This method is typically used to tie the language dependent $Lang logger to different log files.
254b274bc22SAndre Fischer
255b274bc22SAndre Fischer=cut
256b274bc22SAndre Fischersub set_filename ($$)
257b274bc22SAndre Fischer{
258b274bc22SAndre Fischer    my ($self, $filename) = @_;
259b274bc22SAndre Fischer
260b274bc22SAndre Fischer    $filename = "" unless defined $filename;
261b274bc22SAndre Fischer    if ($self->{'filename'} ne $filename)
262b274bc22SAndre Fischer    {
263b274bc22SAndre Fischer        if (defined $self->{'file'})
264b274bc22SAndre Fischer        {
265b274bc22SAndre Fischer            $self->{'is_print_to_console'} = 1;
266b274bc22SAndre Fischer            close $self->{'file'};
267b274bc22SAndre Fischer            $self->{'file'} = undef;
268b274bc22SAndre Fischer        }
269b274bc22SAndre Fischer
270b274bc22SAndre Fischer        $self->{'filename'} = $filename;
271b274bc22SAndre Fischer
272b274bc22SAndre Fischer        if ($filename ne "")
273b274bc22SAndre Fischer        {
274b274bc22SAndre Fischer            open $self->{'file'}, ">", $self->{'filename'}
275*0374af79SAndre Fischer            || Die "can not open log file ".$self->{'filename'}." for writing";
276b274bc22SAndre Fischer            $self->{'is_print_to_console'} = 0;
277b274bc22SAndre Fischer
278b274bc22SAndre Fischer            # Make all writes synchronous so that we don't loose any messages on an
279b274bc22SAndre Fischer            # 'abrupt' end.
280b274bc22SAndre Fischer            my $handle = select $self->{'file'};
281b274bc22SAndre Fischer            $| = 1;
282b274bc22SAndre Fischer            select $handle;
283b274bc22SAndre Fischer        }
284b274bc22SAndre Fischer    }
285b274bc22SAndre Fischer}
286b274bc22SAndre Fischer
287b274bc22SAndre Fischer
288b274bc22SAndre Fischer
289b274bc22SAndre Fischer
290b274bc22SAndre Fischer=head2 set_filter ($self, $filter)
291b274bc22SAndre Fischer
292b274bc22SAndre Fischer    Sets $filter (a function reference) as line filter.  It is applied to each line.
293b274bc22SAndre Fischer    The filter can extract information from the given message and modify it before it is printed.
294b274bc22SAndre Fischer
295b274bc22SAndre Fischer=cut
296b274bc22SAndre Fischersub set_filter ($$)
297b274bc22SAndre Fischer{
298b274bc22SAndre Fischer    my ($self, $filter) = @_;
299b274bc22SAndre Fischer    $self->{'filter'} = $filter;
300b274bc22SAndre Fischer}
301b274bc22SAndre Fischer
302b274bc22SAndre Fischer
303b274bc22SAndre Fischer
304b274bc22SAndre Fischer
305b274bc22SAndre Fischer=head2 add_timestamp ($self, $message)
306b274bc22SAndre Fischer
307b274bc22SAndre Fischer    Print the given message together with the current (absolute) time.
308b274bc22SAndre Fischer
309b274bc22SAndre Fischer=cut
310b274bc22SAndre Fischersub add_timestamp ($$)
311b274bc22SAndre Fischer{
312b274bc22SAndre Fischer	my ($self, $message) = @_;
313b274bc22SAndre Fischer
314b274bc22SAndre Fischer	my $timestring = get_time_string();
315b274bc22SAndre Fischer    $self->printf("%s\t%s", $message, $timestring);
316b274bc22SAndre Fischer}
317b274bc22SAndre Fischer
318b274bc22SAndre Fischer
319b274bc22SAndre Fischer
320b274bc22SAndre Fischer=head2 copy_lines_from ($self, $other)
321b274bc22SAndre Fischer
322b274bc22SAndre Fischer    Copy saved lines from another logger object.
323b274bc22SAndre Fischer
324b274bc22SAndre Fischer=cut
325b274bc22SAndre Fischersub copy_lines_from ($$)
326b274bc22SAndre Fischer{
327b274bc22SAndre Fischer    my ($self, $other) = @_;
328b274bc22SAndre Fischer
329b274bc22SAndre Fischer    my $is_print_to_console = $self->{'is_print_to_console'};
330b274bc22SAndre Fischer    my $is_save_lines = $self->{'is_save_lines'};
331b274bc22SAndre Fischer    my $fid = $self->{'file'};
332b274bc22SAndre Fischer
333b274bc22SAndre Fischer    foreach my $line (@{$other->{'lines'}})
334b274bc22SAndre Fischer    {
335b274bc22SAndre Fischer        $self->process_line(@$line);
336b274bc22SAndre Fischer    }
337b274bc22SAndre Fischer}
338b274bc22SAndre Fischer
339b274bc22SAndre Fischer
340b274bc22SAndre Fischer
341b274bc22SAndre Fischer
342b274bc22SAndre Fischer=head2 set_forward ($self, $other)
343b274bc22SAndre Fischer
344b274bc22SAndre Fischer    Set a forwarding target.  All future messages are forwarded (copied) to $other.
345b274bc22SAndre Fischer    A typical use is to tie $Info to $Lang so that all messages sent to $Info are
346b274bc22SAndre Fischer    printed to the console AND written to the log file.
347b274bc22SAndre Fischer
348b274bc22SAndre Fischer=cut
349b274bc22SAndre Fischersub set_forward ($$)
350b274bc22SAndre Fischer{
351b274bc22SAndre Fischer    my ($self, $other) = @_;
352b274bc22SAndre Fischer
353b274bc22SAndre Fischer    # At the moment at most one forward target is allowed.
354b274bc22SAndre Fischer    if (defined $other)
355b274bc22SAndre Fischer    {
356b274bc22SAndre Fischer        $self->{'forward'} = [$other];
357b274bc22SAndre Fischer    }
358b274bc22SAndre Fischer    else
359b274bc22SAndre Fischer    {
360b274bc22SAndre Fischer        $self->{'forward'} = [];
361b274bc22SAndre Fischer    }
362b274bc22SAndre Fischer}
363b274bc22SAndre Fischer
364b274bc22SAndre Fischer
365b274bc22SAndre Fischer
366cdf0e10cSrcweir
367cdf0e10cSrcweir####################################################
368cdf0e10cSrcweir# Including header files into the logfile
369cdf0e10cSrcweir####################################################
370cdf0e10cSrcweir
371cdf0e10cSrcweirsub include_header_into_logfile
372cdf0e10cSrcweir{
373cdf0e10cSrcweir	my ($message) = @_;
374cdf0e10cSrcweir
375b274bc22SAndre Fischer	$Lang->print("\n");
376b274bc22SAndre Fischer	$Lang->print(get_time_string());
377b274bc22SAndre Fischer	$Lang->print("######################################################\n");
378b274bc22SAndre Fischer	$Lang->print($message."\n");
379b274bc22SAndre Fischer	$Lang->print("######################################################\n");
380cdf0e10cSrcweir}
381cdf0e10cSrcweir
382cdf0e10cSrcweir####################################################
383cdf0e10cSrcweir# Including header files into the logfile
384cdf0e10cSrcweir####################################################
385cdf0e10cSrcweir
386cdf0e10cSrcweirsub include_header_into_globallogfile
387cdf0e10cSrcweir{
388cdf0e10cSrcweir	my ($message) = @_;
389cdf0e10cSrcweir
390b274bc22SAndre Fischer	$Global->print("\n");
391b274bc22SAndre Fischer	$Global->print(get_time_string());
392b274bc22SAndre Fischer	$Global->print("######################################################\n");
393b274bc22SAndre Fischer	$Global->print($message."\n");
394b274bc22SAndre Fischer	$Global->print("######################################################\n");
395cdf0e10cSrcweir}
396cdf0e10cSrcweir
397cdf0e10cSrcweir####################################################
398cdf0e10cSrcweir# Write timestamp into log file
399cdf0e10cSrcweir####################################################
400cdf0e10cSrcweir
401cdf0e10cSrcweirsub include_timestamp_into_logfile
402cdf0e10cSrcweir{
403*0374af79SAndre Fischer    Die "deprected";
404cdf0e10cSrcweir	my ($message) = @_;
405cdf0e10cSrcweir
406cdf0e10cSrcweir	my $infoline;
407cdf0e10cSrcweir	my $timestring = get_time_string();
408b274bc22SAndre Fischer    $Lang->printf("%s\t%s", $message, $timestring);
409cdf0e10cSrcweir}
410cdf0e10cSrcweir
411cdf0e10cSrcweir####################################################
412cdf0e10cSrcweir# Writing all variables content into the log file
413cdf0e10cSrcweir####################################################
414cdf0e10cSrcweir
415cdf0e10cSrcweirsub log_hashref
416cdf0e10cSrcweir{
417cdf0e10cSrcweir	my ($hashref) = @_;
418cdf0e10cSrcweir
419b274bc22SAndre Fischer    $Global->print("\n");
420b274bc22SAndre Fischer    $Global->print("Logging variable settings:\n");
421cdf0e10cSrcweir
422cdf0e10cSrcweir	my $itemkey;
423cdf0e10cSrcweir
424cdf0e10cSrcweir	foreach $itemkey ( keys %{$hashref} )
425cdf0e10cSrcweir	{
426cdf0e10cSrcweir		my $line = "";
427cdf0e10cSrcweir		my $itemvalue = "";
428cdf0e10cSrcweir		if ( $hashref->{$itemkey} ) { $itemvalue = $hashref->{$itemkey}; }
429b274bc22SAndre Fischer        $Global->printf("%s=%s\n", $itemkey, $itemvalue);
430cdf0e10cSrcweir	}
431cdf0e10cSrcweir
432b274bc22SAndre Fischer    $Global->print("\n");
433cdf0e10cSrcweir}
434cdf0e10cSrcweir
435cdf0e10cSrcweir#########################################################
436cdf0e10cSrcweir# Including global logging info into global log array
437cdf0e10cSrcweir#########################################################
438cdf0e10cSrcweir
439cdf0e10cSrcweirsub globallog
440cdf0e10cSrcweir{
441cdf0e10cSrcweir	my ($message) = @_;
442cdf0e10cSrcweir
443cdf0e10cSrcweir	my $infoline;
444cdf0e10cSrcweir
445b274bc22SAndre Fischer    $Global->print("\n");
446b274bc22SAndre Fischer    $Global->print(get_time_string());
447b274bc22SAndre Fischer    $Global->print("################################################################\n");
448b274bc22SAndre Fischer    $Global->print($message."\n");
449b274bc22SAndre Fischer    $Global->print("################################################################\n");
450cdf0e10cSrcweir}
451cdf0e10cSrcweir
452cdf0e10cSrcweir###############################################################
453cdf0e10cSrcweir# For each product (new language) a new log file is created.
454cdf0e10cSrcweir# Therefore the global logging has to be saved in this file.
455cdf0e10cSrcweir###############################################################
456cdf0e10cSrcweir
457cdf0e10cSrcweirsub copy_globalinfo_into_logfile
458cdf0e10cSrcweir{
459cdf0e10cSrcweir	for ( my $i = 0; $i <= $#installer::globals::globallogfileinfo; $i++ )
460cdf0e10cSrcweir	{
461cdf0e10cSrcweir		push(@installer::globals::logfileinfo, $installer::globals::globallogfileinfo[$i]);
462cdf0e10cSrcweir	}
463cdf0e10cSrcweir}
464cdf0e10cSrcweir
465cdf0e10cSrcweir###############################################################
466cdf0e10cSrcweir# For each product (new language) a new log file is created.
467cdf0e10cSrcweir# Therefore the global logging has to be saved in this file.
468cdf0e10cSrcweir###############################################################
469cdf0e10cSrcweir
470cdf0e10cSrcweirsub debuginfo
471cdf0e10cSrcweir{
472cdf0e10cSrcweir	my  ( $message ) = @_;
473cdf0e10cSrcweir
474cdf0e10cSrcweir	$message = $message . "\n";
475cdf0e10cSrcweir	push(@installer::globals::functioncalls, $message);
476cdf0e10cSrcweir}
477cdf0e10cSrcweir
478cdf0e10cSrcweir###############################################################
479cdf0e10cSrcweir# Saving the debug information.
480cdf0e10cSrcweir###############################################################
481cdf0e10cSrcweir
482cdf0e10cSrcweirsub savedebug
483cdf0e10cSrcweir{
484cdf0e10cSrcweir	my ( $outputdir ) = @_;
485cdf0e10cSrcweir
486cdf0e10cSrcweir	installer::files::save_file($outputdir . $installer::globals::debugfilename, \@installer::globals::functioncalls);
487cdf0e10cSrcweir	print_message( "... writing debug file " . $outputdir . $installer::globals::debugfilename . "\n" );
488cdf0e10cSrcweir}
489cdf0e10cSrcweir
490cdf0e10cSrcweir###############################################################
491cdf0e10cSrcweir# Starting the time
492cdf0e10cSrcweir###############################################################
493cdf0e10cSrcweir
494cdf0e10cSrcweirsub starttime
495cdf0e10cSrcweir{
496cdf0e10cSrcweir	$installer::globals::starttime = time();
497b274bc22SAndre Fischer	$StartTime = [gettimeofday()];
498b274bc22SAndre Fischer
499b274bc22SAndre Fischer    my $localtime = localtime();
500cdf0e10cSrcweir}
501cdf0e10cSrcweir
502cdf0e10cSrcweir###############################################################
503cdf0e10cSrcweir# Convert time string
504cdf0e10cSrcweir###############################################################
505cdf0e10cSrcweir
506cdf0e10cSrcweirsub convert_timestring
507cdf0e10cSrcweir{
508cdf0e10cSrcweir	my ($secondstring) = @_;
509cdf0e10cSrcweir
510cdf0e10cSrcweir	my $timestring = "";
511cdf0e10cSrcweir
512cdf0e10cSrcweir	if ( $secondstring < 60 )	 # less than a minute
513cdf0e10cSrcweir	{
514cdf0e10cSrcweir		if ( $secondstring < 10 ) { $secondstring = "0" . $secondstring; }
515cdf0e10cSrcweir		$timestring = "00\:$secondstring min\.";
516cdf0e10cSrcweir	}
517cdf0e10cSrcweir	elsif ( $secondstring < 3600 )
518cdf0e10cSrcweir	{
519cdf0e10cSrcweir		my $minutes = $secondstring / 60;
520cdf0e10cSrcweir		my $seconds = $secondstring % 60;
521cdf0e10cSrcweir		if ( $minutes =~ /(\d*)\.\d*/ ) { $minutes = $1; }
522cdf0e10cSrcweir		if ( $minutes < 10 ) { $minutes = "0" . $minutes; }
523cdf0e10cSrcweir		if ( $seconds < 10 ) { $seconds = "0" . $seconds; }
524cdf0e10cSrcweir		$timestring = "$minutes\:$seconds min\.";
525cdf0e10cSrcweir	}
526cdf0e10cSrcweir	else	# more than one hour
527cdf0e10cSrcweir	{
528cdf0e10cSrcweir		my $hours = $secondstring / 3600;
529cdf0e10cSrcweir		my $secondstring = $secondstring % 3600;
530cdf0e10cSrcweir		my $minutes = $secondstring / 60;
531cdf0e10cSrcweir		my $seconds = $secondstring % 60;
532cdf0e10cSrcweir		if ( $hours =~ /(\d*)\.\d*/ ) { $hours = $1; }
533cdf0e10cSrcweir		if ( $minutes =~ /(\d*)\.\d*/ ) { $minutes = $1; }
534cdf0e10cSrcweir		if ( $hours < 10 ) { $hours = "0" . $hours; }
535cdf0e10cSrcweir		if ( $minutes < 10 ) { $minutes = "0" . $minutes; }
536cdf0e10cSrcweir		if ( $seconds < 10 ) { $seconds = "0" . $seconds; }
537cdf0e10cSrcweir		$timestring = "$hours\:$minutes\:$seconds hours";
538cdf0e10cSrcweir	}
539cdf0e10cSrcweir
540cdf0e10cSrcweir	return $timestring;
541cdf0e10cSrcweir}
542cdf0e10cSrcweir
543cdf0e10cSrcweir###############################################################
544cdf0e10cSrcweir# Returning time string for logging
545cdf0e10cSrcweir###############################################################
546cdf0e10cSrcweir
547cdf0e10cSrcweirsub get_time_string
548cdf0e10cSrcweir{
549cdf0e10cSrcweir	my $currenttime = time();
550cdf0e10cSrcweir	$currenttime = $currenttime - $installer::globals::starttime;
551cdf0e10cSrcweir	$currenttime = convert_timestring($currenttime);
552cdf0e10cSrcweir	$currenttime = localtime() . " \(" . $currenttime . "\)\n";
553cdf0e10cSrcweir	return $currenttime;
554cdf0e10cSrcweir}
555cdf0e10cSrcweir
556cdf0e10cSrcweir###############################################################
557cdf0e10cSrcweir# Returning the age of a file (in seconds)
558cdf0e10cSrcweir###############################################################
559cdf0e10cSrcweir
560cdf0e10cSrcweirsub get_file_age
561cdf0e10cSrcweir{
562cdf0e10cSrcweir	my ( $filename ) = @_;
563cdf0e10cSrcweir
564cdf0e10cSrcweir	my $filetime = (stat($filename))[9];
565cdf0e10cSrcweir	my $timediff = time() - $filetime;
566cdf0e10cSrcweir	return $timediff;
567cdf0e10cSrcweir}
568cdf0e10cSrcweir
569cdf0e10cSrcweir###############################################################
570cdf0e10cSrcweir# Stopping the time
571cdf0e10cSrcweir###############################################################
572cdf0e10cSrcweir
573cdf0e10cSrcweirsub stoptime
574cdf0e10cSrcweir{
575b274bc22SAndre Fischer    my $localtime = localtime();
576b274bc22SAndre Fischer    $Info->printf("stopping log at %s\n", $localtime);
577cdf0e10cSrcweir}
578cdf0e10cSrcweir
579cdf0e10cSrcweir###############################################################
580cdf0e10cSrcweir# Set date string, format: yymmdd
581cdf0e10cSrcweir###############################################################
582cdf0e10cSrcweir
583cdf0e10cSrcweirsub set_installation_date
584cdf0e10cSrcweir{
585cdf0e10cSrcweir	my $datestring = "";
586cdf0e10cSrcweir
587cdf0e10cSrcweir	my @timearray = localtime(time);
588cdf0e10cSrcweir
589cdf0e10cSrcweir	my $day = $timearray[3];
590cdf0e10cSrcweir	my $month = $timearray[4] + 1;
591cdf0e10cSrcweir	my $year = $timearray[5] - 100;
592cdf0e10cSrcweir
593cdf0e10cSrcweir	if ( $year < 10 ) { $year = "0" . $year; }
594cdf0e10cSrcweir	if ( $month < 10 ) { $month = "0" . $month; }
595cdf0e10cSrcweir	if ( $day < 10 ) { $day = "0" . $day; }
596cdf0e10cSrcweir
597cdf0e10cSrcweir	$datestring = $year . $month . $day;
598cdf0e10cSrcweir
599cdf0e10cSrcweir	return $datestring;
600cdf0e10cSrcweir}
601cdf0e10cSrcweir
602cdf0e10cSrcweir###############################################################
603cdf0e10cSrcweir# Console output: messages
604cdf0e10cSrcweir###############################################################
605cdf0e10cSrcweir
606cdf0e10cSrcweirsub print_message
607cdf0e10cSrcweir{
608*0374af79SAndre Fischer    Die "print_message is deprecated";
609b274bc22SAndre Fischer
610cdf0e10cSrcweir    my $message = shift;
611cdf0e10cSrcweir    chomp $message;
612cdf0e10cSrcweir    my $force = shift || 0;
613cdf0e10cSrcweir    print "$message\n" if ( $force || ! $installer::globals::quiet );
614cdf0e10cSrcweir    return;
615cdf0e10cSrcweir}
616cdf0e10cSrcweir
617cdf0e10cSrcweirsub print_message_without_newline
618cdf0e10cSrcweir{
619cdf0e10cSrcweir    my $message = shift;
620cdf0e10cSrcweir    chomp $message;
621cdf0e10cSrcweir    print "$message" if ( ! $installer::globals::quiet );
622cdf0e10cSrcweir    return;
623cdf0e10cSrcweir}
624cdf0e10cSrcweir
625cdf0e10cSrcweir###############################################################
626cdf0e10cSrcweir# Console output: warnings
627cdf0e10cSrcweir###############################################################
628cdf0e10cSrcweir
629cdf0e10cSrcweirsub print_warning
630cdf0e10cSrcweir{
631cdf0e10cSrcweir    my $message = shift;
632cdf0e10cSrcweir    chomp $message;
633cdf0e10cSrcweir    print STDERR "WARNING: $message";
634cdf0e10cSrcweir    return;
635cdf0e10cSrcweir}
636cdf0e10cSrcweir
637cdf0e10cSrcweir###############################################################
638cdf0e10cSrcweir# Console output: errors
639cdf0e10cSrcweir###############################################################
640cdf0e10cSrcweir
641cdf0e10cSrcweirsub print_error
642cdf0e10cSrcweir{
643cdf0e10cSrcweir    my $message = shift;
644cdf0e10cSrcweir    chomp $message;
645b274bc22SAndre Fischer    print STDERR "\n";
646b274bc22SAndre Fischer    print STDERR "**************************************************\n";
647cdf0e10cSrcweir    print STDERR "ERROR: $message";
648b274bc22SAndre Fischer    print STDERR "\n";
649b274bc22SAndre Fischer    print STDERR "**************************************************\n";
650cdf0e10cSrcweir    return;
651cdf0e10cSrcweir}
652cdf0e10cSrcweir
653cdf0e10cSrcweir1;
654