1cdf0e10cSrcweirpackage loghelper;
2cdf0e10cSrcweir
3*9780544fSAndrew Rist#**************************************************************
4*9780544fSAndrew Rist#
5*9780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
6*9780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
7*9780544fSAndrew Rist#  distributed with this work for additional information
8*9780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
9*9780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
10*9780544fSAndrew Rist#  "License"); you may not use this file except in compliance
11*9780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
12*9780544fSAndrew Rist#
13*9780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
14*9780544fSAndrew Rist#
15*9780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
16*9780544fSAndrew Rist#  software distributed under the License is distributed on an
17*9780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*9780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
19*9780544fSAndrew Rist#  specific language governing permissions and limitations
20*9780544fSAndrew Rist#  under the License.
21*9780544fSAndrew Rist#
22*9780544fSAndrew Rist#**************************************************************
23*9780544fSAndrew Rist
24*9780544fSAndrew Rist
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse strict;
27cdf0e10cSrcweir
28cdf0e10cSrcweirBEGIN {
29cdf0e10cSrcweir    use Exporter   ();
30cdf0e10cSrcweir    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
31cdf0e10cSrcweir
32cdf0e10cSrcweir    $VERSION     = 1.00;
33cdf0e10cSrcweir    # if using RCS/CVS, this may be preferred
34cdf0e10cSrcweir    $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
35cdf0e10cSrcweir    @ISA         = qw(Exporter);
36cdf0e10cSrcweir    @EXPORT      = qw(&set_logfile &close_logfile &log_print &setVerbose);
37cdf0e10cSrcweir    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
38cdf0e10cSrcweir    # your exported package globals go here,
39cdf0e10cSrcweir    # as well as any optionally exported functions
40cdf0e10cSrcweir    @EXPORT_OK   = ( ); # qw($Var1 %Hashit &func3);
41cdf0e10cSrcweir}
42cdf0e10cSrcweir
43cdf0e10cSrcweir# ------------------------------- Log into a file -------------------------------
44cdf0e10cSrcweirlocal *LOGFILE;
45cdf0e10cSrcweirour $nGlobalLog = 0;
46cdf0e10cSrcweirour $nGlobalVerbose = 0;
47cdf0e10cSrcweir
48cdf0e10cSrcweirsub setVerbose()
49cdf0e10cSrcweir{
50cdf0e10cSrcweir    $nGlobalVerbose = 1;
51cdf0e10cSrcweir}
52cdf0e10cSrcweir
53cdf0e10cSrcweirsub set_logfile($)
54cdf0e10cSrcweir{
55cdf0e10cSrcweir    my $sLogFile = shift;
56cdf0e10cSrcweir
57cdf0e10cSrcweir    if (open(LOGFILE, ">$sLogFile"))
58cdf0e10cSrcweir    {
59cdf0e10cSrcweir        $nGlobalLog = 1;
60cdf0e10cSrcweir    }
61cdf0e10cSrcweir}
62cdf0e10cSrcweirsub close_logfile()
63cdf0e10cSrcweir{
64cdf0e10cSrcweir    close(LOGFILE);
65cdf0e10cSrcweir    $nGlobalLog = 0;
66cdf0e10cSrcweir}
67cdf0e10cSrcweir
68cdf0e10cSrcweirsub log_print($)
69cdf0e10cSrcweir{
70cdf0e10cSrcweir    my $sLine = shift;
71cdf0e10cSrcweir    if ($nGlobalLog)
72cdf0e10cSrcweir    {
73cdf0e10cSrcweir        print LOGFILE $sLine;
74cdf0e10cSrcweir    }
75cdf0e10cSrcweir    if ($nGlobalVerbose == 1)
76cdf0e10cSrcweir    {
77cdf0e10cSrcweir        print $sLine;
78cdf0e10cSrcweir    }
79cdf0e10cSrcweir    else
80cdf0e10cSrcweir    {
81cdf0e10cSrcweir        # In this special case for NetBeans, which show if a debugger can access.
82cdf0e10cSrcweir        # The Line should print anyway.
83cdf0e10cSrcweir        if ($sLine =~ /Listening for transport/)
84cdf0e10cSrcweir        {
85cdf0e10cSrcweir            print $sLine;
86cdf0e10cSrcweir        }
87cdf0e10cSrcweir    }
88cdf0e10cSrcweir}
89cdf0e10cSrcweir
90cdf0e10cSrcweir1;
91