File: prLog.pl

package info (click to toggle)
storebackup 3.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,396 kB
  • sloc: perl: 24,988; makefile: 44; sh: 37
file content (815 lines) | stat: -rw-r--r-- 22,466 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
# -*- perl -*-

#
#   Copyright (C) Heinz-Josef Claes (2000-2022)
#                 hjclaes@web.de
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#


######################################################################
# usage of printLog
# Prints lines formatted to STDOUT or a log file.
#
# my $prLog = $printLog('-file' => "fileName",  # optional, default is STDOUT
#                       '-filedescriptor' => ...., # optional
#                       '-kind' => [list of allowed messages'],
#                       '-withTime' => 'yes',   # 'yes' or 'no'
#                       '-withPID' => 'yes',    # 'yes' or 'no'
#                       '-hostname' => '',
#                       '-maxFileLen' => 1e6,
#                       '-noOfOldFiles' => 5,
#                       '-filter' => {},
#                       '-closeFile' => 'no',
#                       '-multiprint' => 'no',
#                       '-saveLogs' => 'no',
#                       '-compressWith' => undef,
#                       '-tmpdir' => '/tmp'
#                       );
# $prLog->fork('pathTo_stbuLogPl');
# my $fifo = $prLog->getFifoName();
# $prLog->setStopAtNoMessages('-kind' => ..., '-stopAt' => ...,
#                             '-message' => ...., '-exit' => ...);
# my $enc = $prLog->encountered('-kind' => ....);
# $prLog->setFileSpecs('-maxFilelen' => ...,, '-noOfOldFiles' => ....,
#		       '-saveLogs' => 'no', '-compressWith' => undef
# $prLog->printLog('-kind' => ..., '-str' => [...],
#                  '-add' => ...., '-exit' => ....);
# $prLog->pr(....);    # print list of lines directly
# $prLog->DESTROY();
#
######################################################################
# Options of printLog::new
#
# '-file'        file name where log messages have to be printed.
#                default is undef, which means STDOUT
# '-filedescriptor' write to file specified descriptor. '-file' must
#                not be set if this option is used
# '-kind'        default is ['I:INFO', 'W:WARNING', 'E:ERROR',
#      	        'S:STATISTIC', 'D:DEBUG']
#                example: $prLog->print('-kind' => 'I', ...)
#                will print a message started with 'INFO'.
#                If '-kind' is used with one word only (without :),
#                you have to specify all of those letters as '-kind'
#                parameter for method 'print()'
# '-withTime'    'yes' or 'no', default is 'yes'
#                additionally print the actual tome to the log file
# '-withPID'     'yes' or 'no', default is 'yes'
#                additionally print the PID to the log file
# '-hostname'    additionally print the specified string (eg. hostname)
#                to the log file
# '-maxFilelen'  default: 1e6, 0 means unlimited file length
#                size when to rotate the log file
# '-noOfOldFiles' number of files to keep when rotating log files
# '-filter'      Replace the output key by values of hashes specified
#                eg: {'e' => 'E', '\s' => "\t"}
#                will replace all instances of 'e' with 'E' and all
#                instances white space with tabulators
# '-closeFile'   open access to log file for each write and close
#                directly afterwords. Default is 'no'
# '-multiprint'  position to the end of the log file before each
#                individual print statement. May be usefull if other
#                processes write to the same log file. Default is 'no'
#                better use method fork() if possible
# '-saveLogs'    do not rotate log files. Store them with time stamp.
#                Default is 'no' which means not to store (= rotate)
# '-compressWith' specifiy compression algorithm for saving logs,
#                may be eg. 'gzip -9', 'bzip2'. Default is undef which
#                meancs not to compress
# '-tmpdir'      default is '/tmp'. Used onyl if method 'fork()' is called
#
#######################################################################
# Options of printLog::fork
#
# creates a named pipe and forks lib/stbuLog.pl
#  which reads from that pipe
# for each call of print (__reallyPrint) checks if 
#  lib/stbuLog.pl was forked. If yes, writes to named
#  pipe created
# to be used if program is forked (not exec'ed!)
# if fork exec, write to namend pipe in execed program directly
# get the name of the fifo with getFifoName
#
# 1. parameter   path to directory where stbuLog.pl is located
#
#######################################################################
# Options of printLog::getFifoName
#
# get name of the fifo file, see printLog::fork
#
#######################################################################
# Options of printLog::setStopAtNoMessages
#
# process is exited after n messages of that type
#
# '-kind'        type of message to configure
# '-stopAt'      stop after specified number of lines
# '-message'     message to print, default is "too may errors, exiting"
# '-exit'        exit status to use when exiting
#
#######################################################################
# Options of printLog::encountered
#


use IO::Handle;
use strict;

require 'checkObjPar.pl';
require 'fileDir.pl';


############################################################
package printLog;

sub new
{
    my ($class) = shift;
    my ($self) = {};

    # Defaultwerte f"ur Parameter setzen
    my (%params) = ('-file'           => undef,  # Default: STDOUT
		    '-filedescriptor' => undef,  # wenn beides nicht gesetzt
		    '-kind'           => ['I:INFO', 'W:WARNING', 'E:ERROR',
					  'S:STATISTIC', 'D:DEBUG'],
		    '-withTime'       => 'yes',
		    '-withPID'        => 'yes',
		    '-hostname'       => '',
		    '-maxFilelen'     => 1e6, # 0 means unlimited file length
		    '-noOfOldFiles'   => 5,
		    '-filter'         => {},  # Replace in Output Key by Value
		    '-closeFile'      => 'no',# ffnet und schliet die Datei
		                              # vor bzw. nach jedem Schreiben
		    '-multiprint'     => 'no',# pos an's Ende vor jedem print,
		                              # mehrere Appl. print in ein log
		                              # besser: methode fork()
		    '-saveLogs'       => 'no',# nicht rundschreiben, wenn 'yes'
		    '-compressWith'   => undef,  # Komprimierungsprogr.,
		                                 # z.B. 'gzip -9', 'bzip2'
		                                 # nur zusammen mit '-saveLogs'
		    '-tmpdir'         => '/tmp'  # used for forking (name pipe)
		    );

    &::checkObjectParams(\%params, \@_, 'printLog::new', []);

    $self->{'param'} = \%params;    # Parameter an Objekt binden

    $self->{'fifo'} = undef;       # not forked
    $self->{'pidNumber'} = $$;     # don't use pid of forked process

    my (%kindhash, $k, $maxlen);
    $maxlen = 0;
    foreach $k (@{$self->{'param'}{'-kind'}})    # Art der m"oglichen
    {                                            # Meldungen analysieren
	my ($key, $val);
	if ($k =~ /:/)
	{
	    ($key, $val) = split(/:/, $k, 2);
	}
	else
	{
	    $key = $val = $k;
	}
	$kindhash{$key} = $val;
	my ($len) = length($val);
	$maxlen = $len if ($len > $maxlen);
    }
    $kindhash{'?'} = '???';            # Falls falsches K"urzel "ubergeben
    foreach $k (keys %kindhash)        # Breite anpassen
    {
	$kindhash{$k} = sprintf("%-${maxlen}s", $kindhash{$k});
    }
    $self->{'kindhash'} = \%kindhash;

    local *FILE;
    if (defined $params{'-file'} and defined $params{'-filedescriptor'})
    {
	die "printLog::new called with parameter '-file' and '-filedescriptor'";
    }
    elsif (defined $params{'-file'})
    {
	if ($params{'-closeFile'} eq 'no')     # normales Verhalten, Datei
	{                                      # geffnet halten
	    open(FILE, ">>$params{'-file'}") or
		die "cannot open <$params{'-file'}>\n";
	    $self->{'filehandle'} = *FILE;
	}
    }
    elsif (defined $params{'-filedescriptor'})
    {
	$self->{'filehandle'} = $params{'-filedescriptor'};
    }
    else
    {
	$self->{'filehandle'} = *STDOUT;
    }

    if (defined $params{'-file'} and -f $params{'-file'})
    {
	$self->{'filesize'} = (stat($params{'-file'}))[7];
    }
    else
    {
	$self->{'filesize'} = 0;
    }

    $self->{filter} = $params{-filter};;

    bless($self, $class);
}


##################################################
# creates a named pipe and forks lib/stbuLog.pl
#  which reads from that pipe
# for each call of print (__reallyPrint) checks if 
#  lib/stbuLog.pl was forked. If yes, writes to named
#  pipe created
#
# to be used if program is forked (not exec'ed!)
# if fork exec, write to namend pipe in execed program directly
#  get the name of the fifo with getFifoName (see below)
sub fork
{
    my $self = shift;
    my $pathTo_stbuLogPl = shift;

    return if defined $self->{'fifo'};
    
    my $fifo = ::uniqFileName($self->{'param'}{'-tmpdir'} . '/prLog-');
    POSIX::mkfifo($fifo, 0600) or
	die "cannot mknod <$fifo> for printLog";
    $self->{'fifo'} = $fifo;

# build options for call of stbuLog.pl
    my (@opts) = ('--readFile' => $fifo);

    if (defined $self->{'param'}{'-file'})
    {
	push @opts, ('--out' => $self->{'param'}{'-file'},
		     '--maxFilelen' => $self->{'param'}{'-maxFilelen'});

	if ($self->{'param'}{'-saveLogs'} eq 'yes')
	{
	    push @opts, ('--saveLogs');
	    push @opts, ('--compressWith' => $self->{'param'}{'-compressWith'})
		if (defined $self->{'param'}{'-compressWith'});
	}
	else  # write round
	{
	    push @opts, ('--noOfOldFiles' => $self->{'param'}{'-noOfOldFiles'});
	}
    }

    my $p = printLog->new();
#print "$$ STARTING stbuLog.pl with @opts\n";
    my $logD = forkProc->new('-exec' => "$pathTo_stbuLogPl/stbuLog.pl",
			     '-param' => \@opts,
			     '-prLog' => $p);
    die "cannot start <$pathTo_stbuLogPl/stbuLog.pl>"
	unless ($logD->processRuns());

    $self->{'logD'} = $logD;
    local *FIFO;
    open(FIFO, '>', $fifo) or
	die "cannot open <$fifo> for writing";
    $self->{'fifoFD'} = *FIFO;
}


##################################################
sub getFifoName
{
    my $self = shift;

    return $self->{'fifo'};
}


##################################################
sub setStopAtNoMessages
{
    my $self = shift;

    # Defaultwerte f"ur Parameter setzen
    my (%params) = ('-kind' => undef,
		    '-stopAt' => undef,
		    '-message' => 'too many errors, exiting',
		    '-exit' => 1);


    &::checkObjectParams(\%params, \@_, 'printLog::setStopAtNoMessages',
			 ['-kind', '-stopAt']);

    $self->{'encounteredStop'}->{$params{'-kind'}} = $params{'-stopAt'};
    $self->{'encounteredKindStop'}->{$params{'-kind'}} =
	$params{'-kind'};
    $self->{'encounteredMessageStop'}->{$params{'-kind'}} =
	$params{'-message'};
    $self->{'encounteredExit'}->{$params{'-kind'}} =
	$params{'-exit'};
}


##################################################
sub encountered
{
    my $self = shift;

    # Defaultwerte f"ur Parameter setzen
    my (%params) = ('-kind' => undef);

    &::checkObjectParams(\%params, \@_, 'printLog::encountered', ['-kind']);

    my $ret = $self->{'encountered'}->{$params{'-kind'}};
    return $ret ? $ret : 0;
}


##################################################
sub setFileSpecs
{
    my $self = shift;

    # Defaultwerte f"ur Parameter setzen
    my (%params) = ('-maxFilelen' => undef,
		    '-noOfOldFiles' => undef,
		    '-saveLogs' => 'no',
		    '-compressWith'   => undef
		    );

    &::checkObjectParams(\%params, \@_, 'printLog::print', []);

    $self->{'param'}{'-maxFilelen'} = $params{'-maxFilelen'}
        if ($params{'-maxFilelen'});
    $self->{'param'}{'-noOfOldFiles'} = $params{'-noOfOldFiles'}
        if ($params{'-noOfOldFiles'});
    $self->{'param'}{'-saveLogs'} = $params{'-saveLogs'};
    $self->{'param'}{'-compressWith'} = $params{'-compressWith'}
        if ($params{'-compressWith'});
}



##################################################
sub print
{
    my $self = shift;

    # Defaultwerte f"ur Parameter setzen
    my (%params) = ('-kind' => undef,
		    '-str' => [],  # Liste mit auszugebenden Strings
		    '-add' => [],  # add as comma sep. list in [] to last line
		    '-exit' => undef
		    );

    &::checkObjectParams(\%params, \@_, 'printLog::print',
			 ['-kind', '-str']);

    my $closeFile = $params{'-closeFile'};
    if (defined $closeFile and $closeFile eq 'yes')
    {
	local *FILE;
	open(FILE, ">>$params{'-file'}") or
	    die "cannot open <$params{'-file'}>\n";
	$self->{'filehandle'} = *FILE;
    }

    my $kind = $params{'-kind'};
    $self->{'encountered'}->{$kind} += 1;

    my $k = $self->{'kindhash'}{$kind};
    $k = $self->{'kindhash'}{'?'} unless ($k);

    my $t = $self->__getTime();
    my $pid = $self->{'param'}{'-withPID'} eq 'yes' ?
	sprintf("%5d ", $self->{'pidNumber'}) : '';

    my $hostname = $self->{'param'}{'-hostname'};
    $hostname = "$hostname " if length($hostname);

    my (@b);
    foreach $a (@{$params{'-str'}})
    {
	push @b, split(/\n/, $a);
    }
    my (@a, $a);
    foreach $a (@b)
    {
	my $b;
	foreach $b (keys %{$self->{filter}})
	{
	    $a =~ s/$b/${$self->{filter}}{$b}/g;
        }
        push @a, "$k $t" . $hostname . "$pid$a";
    }
    my $add = $params{'-add'};
    if (@$add)
    {
	$a[@a-1] .= ' [' . join(', ', @$add) . ']';
    }

    $self->__print(@a);

    if (defined($self->{'encounteredStop'}->{$kind}) and
	$self->{'encountered'}->{$kind} >=
	$self->{'encounteredStop'}->{$kind})
    {
	$k = $self->{'encounteredKindStop'}->{$params{'-kind'}};
	$k = $self->{'kindhash'}{$k};
	$k = $self->{'kindhash'}{'?'} unless ($k);
	(@a) = ("$k $t$hostname$pid" .
		$self->{'encounteredMessageStop'}->{$params{'-kind'}});
	$self->__print(@a);
	exit $self->{'encounteredExit'}->{$params{'-kind'}};
    }

    exit $params{'-exit'} if ($params{'-exit'});   # Aufhren, falls gesetzt

    if (defined $closeFile and $closeFile eq 'yes')
    {
	local *FILE = $self->{'filehandle'};
	close(FILE);
    }
}



##################################################
sub pr
{
    my $self = shift;

    my $t = $self->__getTime();
    my $pid = $self->{'param'}{'-withPID'} eq 'yes' ? sprintf("%5d ", $$) : '';

    my $hostname = $self->{'param'}{'-hostname'};
    $hostname = "$hostname " if length($hostname);

    my (@a, $a);
    foreach $a (@_)
    {
	push @a, "$t" . $hostname . "$pid$a";
    }

    $self->__print(@a);
}


##################################################
sub __getTime       # interne Methode
{
    my $self = shift;

    my $t = '';
    if ($self->{'param'}{'-withTime'} eq 'yes')
    {
	my (@t) = (localtime(time))[5,4,3,2,1,0];
	$t[0] += 1900;                   # localtime liefert Zeit seit 1900
	$t[1]++;                         # Monat fngt bei 1 an
	$t = sprintf("%04d.%02d.%02d %02d:%02d:%02d ", @t);
    }

    return $t;
}


##################################################
sub __print         # interne Methode
{
    my ($self) = shift;
    local *FILE = $self->{'filehandle'};

    if ($self->{'filesize'} >= $self->{'param'}{'-maxFilelen'}
	and $self->{'param'}{'-maxFilelen'} != 0
	and $self->{'param'}{'-file'})
    {
	if ($self->{'param'}{'-saveLogs'} eq 'yes')   # Mit Datum wegsichern
	{
	    close(FILE);
	    my $f = $self->{'param'}{'-file'};
	    my (@t) = (localtime(time))[5,4,3,2,1,0];
	    $t[0] += 1900;              # localtime liefert Zeit seit 1900
	    $t[1]++;                    # Monat fngt bei 1 an
	    my $t = sprintf("%04d.%02d.%02d_%02d.%02d.%02d", @t);
	    my $t0 = $t;
	    $t =~ s/\s/_/;         # blank zwischen Datum und Uhrzeit ersetzen
	    $t =~ s/\s$//;         # blank am Ende lschen
	    link $f, "$f.$t";
	    unlink $f;

	    my $c = $self->{'param'}{'-compressWith'};
	    if ($c)                # komprimieren
	    {
		my $pid = CORE::fork;
		if (defined($pid))     # fork erfolgreich
		{
		    goto Continue if $pid;     # im parent
		    unless (exec("$c $f.$t"))
		    {
			die "cannot open <$f>\n" unless ( open(FILE, ">$f") );

			$self->{'filehandle'} = *FILE;

			$self->{'filesize'} = 0;

			$self->__reallyPrint(
			    ["${t0}ERROR$pid cannot exec <$c $f.$t>"]);
                        exit 0;
		    }
		}
		else
		{
		    die "cannot open <$f>\n" unless ( open(FILE, ">$f") );

		    $self->{'filehandle'} = *FILE;

		    $self->{'filesize'} = 0;

		    $self->__reallyPrint(
			    ["${t0}ERROR$pid fork to start <$c>"]);
		    exit 0;
		}
	    }

Continue:;
	    die "cannot open <$f>\n" unless ( open(FILE, ">$f") );

	    $self->{'filehandle'} = *FILE;

	    $self->{'filesize'} = 0;
	}
	else       # Rundschreiben
	{
	    close(FILE);
	    my ($n) = $self->{'param'}{'-noOfOldFiles'};
	    my ($f) = $self->{'param'}{'-file'};
	    my ($i);
	    link $f, "$f.0";
	    unlink "$f";
	    for ($i = $n ; $i > 0 ; $i--)
	    {
		my ($j) = $i - 1;
		unlink "$f.$i";
		link "$f.$j", "$f.$i" if (-f "$f.$j");
	    }
	    unlink "$f.0";

	    die "cannot open <$f>\n" unless ( open(FILE, ">$f") );

	    $self->{'filehandle'} = *FILE;

	    $self->{'filesize'} = 0;
	}
    }

    $self->__reallyPrint(\@_);
}


##################################################
sub __reallyPrint
{
    my $self = shift;
    my $lines = shift;

#print "in __reallyPrint, fifo = ", $self->{'fifo'}, " <@$lines>\n";
    if ($self->{'fifo'})
    {
	local *FIFO;
	*FIFO = $self->{'fifoFD'};
	foreach my $l (@$lines)
	{
#print "PRINT TO FIFO: <$l>\n";
	    print FIFO $l, "\n";
	}
	FIFO->autoflush(1);
    }
    else
    {
	local *FILE = $self->{'filehandle'};

	if ($self->{'param'}{'-multiprint'} eq 'yes')
	{
	    my (@s) = stat($self->{'param'}{'-file'});
	    if (@s > 0)              # file still exists
	    {
		seek(FILE, 0, 2);
	    }
	    else        # file has been moved from another process
	    {
		close(FILE);
		open(FILE, ">>" . $self->{'param'}{'-file'}) or
		    die "cannot write to file <", $self->{'param'}{'-file'}, ">\n";
		$self->{'filehandle'} = *FILE;
	    }
	}

	my ($l);
	foreach $l (@$lines)
	{
	    my ($p) = "$l\n";
	    $self->{'filesize'} += length($p);

	    print FILE $p or
		die "cannot write to file <", $self->{'param'}{'-file'}, ">";
	}
	FILE->autoflush(1);
    }
}


##################################################
sub DESTROY
{
    my $self = shift;

#print "0\n";
#print "fifo=",$self->{'fifo'},"\n";
    if (defined $self->{'fifo'})
    {
	local *FIFO;
	*FIFO = $self->{'fifoFD'};
	print FIFO "__FINISH__\n";
	close(FIFO);
#print "1\n";
	$self->{'logD'}->wait();
#print "2\n";
	unlink $self->{'fifo'};
    }
    else
    {
	local *FILE = $self->{'filehandle'};
	if (*FILE ne *STDOUT)
	{
	    close(FILE) or
		die "cannot close <", $self->{'param'}{'-file'}, ">\n";
	}
	# wait sets $? if there are no child processes. This causes the
	# entire program to exit with return code 255 - really undesired.
	# So we have to circumvent this. Unfortunately setting $? = 0
	# causes the program to *always* exit with return code zero. So it
	# seems better to not wait() at all - what is it good for anyway?
	#wait;      # wait for execed compression
    }
}


############################################################
# ermglicht es, mehere prLog gemeinsam anzusprechen
package printLogMultiple;

sub new
{
    my $class = shift;
    my $self = {};

    my (%params) = ('-prLogs' => []);

    &::checkObjectParams(\%params, \@_, 'printLogMultiple::new', []);
    &::setParamsDirect($self, \%params);

    $self->{'pathTo_stbuLogPl'} = undef;

    bless $self, $class;
}


##################################################
sub fork
{
    my $self = shift;
    my $pathTo_stbuLogPl = shift;

    $self->{'pathTo_stbuLogPl'} = $pathTo_stbuLogPl;

    my $prLog;
    foreach $prLog (@{$self->{'prLogs'}})
    {
	$prLog->fork($pathTo_stbuLogPl);
    }
}


##################################################
sub encountered
{
    my $self = shift;

    # Defaultwerte f"ur Parameter setzen
    my (%params) = ('-kind' => undef);

    &::checkObjectParams(\%params, \@_, 'printLog::encountered', ['-kind']);

    my $ret = $self->{'encountered'}->{$params{'-kind'}};
    return $ret ? $ret : 0;
}


##################################################
sub addEncounter
{
    my $self = shift;

    # Defaultwerte f"ur Parameter setzen
    my (%params) = ('-kind' => undef,
		    '-add' => 0);

    &::checkObjectParams(\%params, \@_, 'printLog::addEncounter', ['-kind']);

    $self->{'encountered'}->{$params{'-kind'}} += $params{'-add'};
}


##################################################
sub add      # weitere prLog hinzufgen
{
    my $self = shift;

    my (%params) = ('-prLogs' => []);

    &::checkObjectParams(\%params, \@_, 'printLogMultiple::add',
			 ['-prLogs']);

    push @{$self->{'prLogs'}}, @{$params{'-prLogs'}};

    $self->fork($self->{'pathTo_stbuLogPl'})
	if defined $self->{'pathTo_stbuLogPl'};
}


##################################################
sub sub      #  prLog entfernen
{
    my $self = shift;

    my (%params) = ('-prLogs' => []);

    &::checkObjectParams(\%params, \@_, 'printLogMultiple::add',
			 ['-prLogs']);
    my (%subs, $sub);
    foreach $sub (@{$params{'-prLogs'}})
    {
	$subs{$sub} = 1;
    }

    my (@new);
    foreach $sub (@{$self->{'prLogs'}})
    {
	push @new, $sub unless exists $subs{$sub};
    }

    $self->{'prLogs'} = \@new;
}

##################################################
sub print
{
    my $self = shift;

    my (%prLogs) = (@_);
    my $exit = undef;
    if (exists $prLogs{'-exit'})
    {
	$exit = $prLogs{'-exit'};
	delete $prLogs{'-exit'};
    }
    $self->{'encountered'}->{$prLogs{'-kind'}} += 1;

    my $prLog;
    foreach $prLog (@{$self->{'prLogs'}})
    {
	$prLog->print(%prLogs);
    }

    if ($exit)
    {
        main::cleanup($exit);
    }
}

##################################################
sub pr
{
    my $self = shift;

    my $prLog;
    foreach $prLog (@{$self->{'prLogs'}})
    {
	$prLog->pr(@_);
    }
}

1