Now Helper s/[[:space:]]+/ /g on the description of all help.
[the00z_lib.git] / The00z / Logger.pm
blob2bed0477e64047c19aed17e6d84e3b44e99c6209
1 package The00z::Logger;
3 use IO::File;
4 use Carp qw(croak);
6 our $VERSION = '0.0.1';
8 sub
9 new
11 my ($pkg,$logfile) = @_;
13 my $self = {};
15 my $filehandler = IO::File->new(">>$logfile")
16 or croak "Cannot open $logfile\n";
18 $self->{'filehandler'} = $filehandler;
19 $self->{'level'} = 1;
20 $self->{'logfile'} = $logfile;
22 $self->{'filehandler'}->print("Opening "
23 . $self->{'logfile'} . " : " . localtime(time) . "\n");
25 bless($self,$pkg);
27 return $self;
30 sub
31 write
33 my ($self, $level) = (shift, shift);
35 if ($level <= $self->{'level'})
37 $self->{'filehandler'}->print($_) for @_;
41 sub
42 level
44 my ($self, $level) = @_;
45 $self->{'level'} = $level
46 if @_ == 2 and $level =~ m/^\d+$/;
47 return $self->{'level'};
50 sub
51 DESTROY
53 my $self = shift;
55 $self->write($self->{'level'} ,"Closing ". $self->{'logfile'} . " : "
56 . localtime(time) . "\n");
58 $self->{'filehandler'}->close()
59 or croak "Unable to write " . $self->{'logfile'} . "\n";
61 %{$self} = ();