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