1package loghelper;
2
3#*************************************************************************
4#
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6#
7# Copyright 2000, 2010 Oracle and/or its affiliates.
8#
9# OpenOffice.org - a multi-platform office productivity suite
10#
11# This file is part of OpenOffice.org.
12#
13# OpenOffice.org is free software: you can redistribute it and/or modify
14# it under the terms of the GNU Lesser General Public License version 3
15# only, as published by the Free Software Foundation.
16#
17# OpenOffice.org is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20# GNU Lesser General Public License version 3 for more details
21# (a copy is included in the LICENSE file that accompanied this code).
22#
23# You should have received a copy of the GNU Lesser General Public License
24# version 3 along with OpenOffice.org.  If not, see
25# <http://www.openoffice.org/license.html>
26# for a copy of the LGPLv3 License.
27#
28#*************************************************************************
29
30use strict;
31
32BEGIN {
33    use Exporter   ();
34    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
35
36    $VERSION     = 1.00;
37    # if using RCS/CVS, this may be preferred
38    $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
39    @ISA         = qw(Exporter);
40    @EXPORT      = qw(&set_logfile &close_logfile &log_print &setVerbose);
41    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
42    # your exported package globals go here,
43    # as well as any optionally exported functions
44    @EXPORT_OK   = ( ); # qw($Var1 %Hashit &func3);
45}
46
47# ------------------------------- Log into a file -------------------------------
48local *LOGFILE;
49our $nGlobalLog = 0;
50our $nGlobalVerbose = 0;
51
52sub setVerbose()
53{
54    $nGlobalVerbose = 1;
55}
56
57sub set_logfile($)
58{
59    my $sLogFile = shift;
60
61    if (open(LOGFILE, ">$sLogFile"))
62    {
63        $nGlobalLog = 1;
64    }
65}
66sub close_logfile()
67{
68    close(LOGFILE);
69    $nGlobalLog = 0;
70}
71
72sub log_print($)
73{
74    my $sLine = shift;
75    if ($nGlobalLog)
76    {
77        print LOGFILE $sLine;
78    }
79    if ($nGlobalVerbose == 1)
80    {
81        print $sLine;
82    }
83    else
84    {
85        # In this special case for NetBeans, which show if a debugger can access.
86        # The Line should print anyway.
87        if ($sLine =~ /Listening for transport/)
88        {
89            print $sLine;
90        }
91    }
92}
93
941;
95