Puppet::LogBody - Log facility


Puppet-LogBody documentation Contained in the Puppet-LogBody distribution.

Index


Code Index:

NAME

Top

Puppet::LogBody - Log facility

SYNOPSIS

Top

 use Puppet::LogBody ;

 my $log = new Puppet::LogBody 
  ( 
   name => 'log test', 
   'how' => 'print'
  ) ;

 $log -> log("hello")  ;                 # printed on STDOUT
 $log -> log("world",'how' => 'warn')  ; # printed on STDERR

 my @a = $log-> getAll() ; # @a contains ['hello','world']

DESCRIPTION

Top

This class implements a log facility which can either print on STDOUT or warn on STDERR (or hide) the log message. But in any case, the log message will be stored in the class so that all log messages can be retrieved later by the user.

Constructor

Top

new (...)

Creates the log object.

Parameters are

For instance if name is set to 'foo' a call to log('hello') will print:

 foo:
       hello

Methods

Top

As Puppet::LogBody inherits from Puppet::Log, all the parent methods are available.

log(text,...)

Will log the passed text

Optional parameters are:

clear()

Clear all stored logs

getAll()

Return an array made of all stored logs.

About Puppet body classes

Top

Puppet classes are a set of utility classes which can be used by any object. If you use directly the Puppet::*Body class, you get the plain functionnality. And if you use the Puppet::* class, you can get the same functionnality and a Tk Gui to manage it.

AUTHOR

Top

Dominique Dumont, ddumont at cpan dot org.

Copyright (c) 1998-1999,2007 Dominique Dumont. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Top

perl(1), Puppet::Log(3)


Puppet-LogBody documentation Contained in the Puppet-LogBody distribution.

############################################################
#
# $Header: /home/domi/perlDev/old/Puppet_LogBody/RCS/LogBody.pm,v 1.3 2007/09/20 12:55:03 domi Exp $
#
# $Source: /home/domi/perlDev/old/Puppet_LogBody/RCS/LogBody.pm,v $
# $Revision: 1.3 $
# $Locker:  $
# 
############################################################

package Puppet::LogBody ;

use Carp ;

use strict ;
use vars qw($VERSION) ;

$VERSION = sprintf "%d.%03d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/;

# see loadspecs for other names
sub new 
  {
    my $type = shift ;
    my $self = {} ;
    my %args = @_ ;

    $self->{name} = $args{'name'} ; #complete log name

    $self->{how}  = $args{'how'} ;

    $self->{'data'}= [] ;

    bless $self,$type ;
  }

sub log
  {
    my $self = shift ;
    my $text = shift ;
    my %args = @_ ;

    my $how = exists $args{'how'} ? $args{how} : $self->{how};

    chomp ($text) ;
    $text .= "\n";

    push @{$self->{'data'}}, $text ; # always keep text in local array

    if (defined $how)
      {
        my $str = defined $self->{name} ? $self->{name}.": \n\t" : '';
        $str .= $text;
        if ($how eq 'print')   {print $str ;}
        elsif ($how eq 'warn') {warn  $str ;}
      } 
    return $text ;
  }

sub clear
  {
    my $self = shift ;
    $self->{'data'} =[];
  }

sub getAll
  {
    my $self = shift ;
    return @{$self->{'data'}} ;
  }

1;

__END__