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