Copyright Notice

 Copyright I.N.R.A. - C.N.R.S.
 emmanuel.courcelle@toulouse.inra.fr
 jerome.gouzy@toulouse.inra.fr
 This software is a perl module whose purpose is to help you writing 
 your own scripts
 This software is governed by the CeCILL  license under French law and
 abiding by the rules of distribution of free software.  You can  use, 
 modify and/ or redistribute the software under the terms of the CeCILL
 license as circulated by CEA, CNRS and INRIA at the following URL
 http://www.cecill.info";
 As a counterpart to the access to the source code and  rights to copy,
 modify and redistribute granted by the license, users are provided only
 with a limited warranty  and the software's author,  the holder of the
 economic rights,  and the successive licensors  have only  limited
 liability.
 In this respect, the user's attention is drawn to the risks associated
 with loading,  using,  modifying and/or developing or reproducing the
 software by the user in light of its specific status of free software,
 that may mean  that it is complicated to manipulate,  and  that  also
 therefore means  that it is reserved for developers  and  experienced
 professionals having in-depth computer knowledge. Users are therefore
 encouraged to load and test the software's suitability as regards their
 requirements in conditions enabling the security of their systems and/or 
 data to be ensured and,  more generally, to use and operate it in the 
 same conditions as regards security.
 The fact that you are presently reading this means that you have had
 knowledge of the CeCILL license and that you accept its terms.


NAME

Logger - An object to write some traces to a log file in a structured way


THE TIME STAMP

This object generates a time stamp computed to be easily manageable (with sort and other unix commands). Because of the last number (iteration), you are sure that the generated stamp is UNIQUE to your program.

#04#11#09#13#16#27#01# means 9 nov 2004, 13h 16mn 27s iteration 01. (N.B. The nb of iterations is limited to 100)

Please note it is very easy to sort the time stamps: the sort utility, without any parameter, sorts the stamps from oldest to newest.


THE TIMER STAMP

The timer stamp represents an duration; it thus has a different meaning from a time stamp, but the format is nearly the same:

#00#00#00#13#16#27#36# means the elapsed time was 13hours, 16 minutes, 27.36 seconds

If the module Time::HiRes is not available (not installed on system), the timer resolution will be 1s and the last number will be always 00 and the resolution will be limited to 1 s


PUBLIC METHODS

 New
    my $log = New Logger ($logfile,$log_level,$status);
 CalcStamp
    my $stamp = $log->CalcStamp()
 Trace
    $log->Trace($msg,$stamp,$log_type);
 SetLogFile
    $log->SetLogFile($logfile)
 StartTimer
    $log->StartTimer("timer")
 StopTimer
    my $elapsed = $log->StopTimer("timer")
 CalcTimerStamp()
    my $timer_stamp = $log->CalcStamp("timer")


METHODS AND SUBROUTINES - DETAILED DESCRIPTION

New

 Usage:     my $log = New Logger ($logfile,$log_level,$status);
 Procedure: Initialize an object, opening the logfile specified.
 Return:    the created object
 Args:      $logfile, the log file name
               "file.log" opens in write mode
               ">file.log" opens in write mode, too
               ">>file.log" opens in append mode
            $log_level = a string representing a log level (cf. Trace)
            $status = 'COMPRESSION'   -> gzip the logfile
                      'NOCOMPRESSION' -> normal (default status)

SetLogFile

 Usage: my $log->SetLogFile($logfile);
 Function: Close the current logfile and open a new file
 Return:   nothing
 Args:     $logfile, the new log file name
           "file.log" opens in write mode
           ">file.log" opens in write mode, too
           ">>file.log" opens in append mode

StartTimer


 Title: StartTimer
 Usage: $log->StartTimer('timer')
 Function: reset and start the timer called 'timer'
           Call gmtime() and keep the number returned in a private member.
 Args:     The timer name
 On error: No error

StopTimer

 Usage: $log->StopTimer('timer')
 Function: "stop" the timer called 'timer'
           Call gmtime() and returns the alapsed time since the number sotred by StartTimer
 Args:     The timer name
 Return:   The elapsed time
 On error: No error

CalcTimerStamp

 Usage: $log->CalcStamp("timer")
 Function: compute a timer stamp 
 Return:   the stamp
 Args:     The timer name
 On error: croak a message

CalcStamp

 Usage:    $log->CalcStamp()
 Function: compute an unique stamp
 Return:   the stamp
 Args:     none
 static:  stamp_old_time, stamp_seq

Trace

 Usage: $log->Trace($msg,$stamp,$log_type)
 Function: write $msg to LOG only if $log_type matches with __log_level
           If $stamp is "", only $msg is printed
           If $stamp is ".", print a standard stamp
           If $stamp is "*", call CalcStamp
           If $stamp is a name but not a stamp ("timer"), call CalcTimerStamp("timer")
           If $stamp is a correct stamp (#\d\d# etc.), print this stamp
           The output is formatted as follows:
                 $stamp $log_type $msg (space is the separator)
           NO \n is written, so you must provide \n in $msg if needed. 
                   You may thus trace a line in two steps:
           $Trace("first part","#.....#","D");
           ...
           $Trace("second part\n","","D");
           $log_type is a regex, a match is done as follows:
           if ($log_level =~ /$log_type/) {
               display the line
           }
           TIPS ==> If you supply '.', the line is ALWAYS printed.
 Return:   none
 Args:     $msg      = the message to trace
           $stamp    = the stamp to print
           $log_type = type of log, compare with __log_level