1
2=head1 NAME
3
4LedgerSMB::Log - LedgerSMB logging and debugging framework
5
6=head1 SYOPSIS
7
8This module maintains a connection to the LedgerSMB log file
9(Seperate from the apche error log, for now)
10
11=head1 METHODS
12
13This module is loosly based on Apache::Log.
14
15Available methods: (in order, most to least severe)
16
17
18=over 4
19
20=item emerg
21
22=item alert
23
24=item crit
25
26=item error
27
28=item warn
29
30=item notice
31
32=item info
33
34=item debug
35
36=item longmess
37
38This uses Carp to make a debug message with the full stack backtrace, including function arguments, where Carp can infer them.
39
40=item dump
41
42This uses Data::Dumper to dump the contents of a data structure as a debug message.
43
44=back
45
46=cut
47
48package LedgerSMB::Log;
49use strict;
50use warnings;
51use IO::File;
52use Data::Dumper;
53use LedgerSMB::Sysconfig;
54use Carp ();
55
56our $VERSION = '1.0.0';
57
58our $log_line;
59
60sub print {
61    if ( !$LedgerSMB::Sysconfig::logging ) {
62        return 0;
63    }
64    shift;
65    $log_line = sprintf( '[%s] [%s] %i %s',
66        scalar(localtime), +shift, $$, join( ' ', @_ ) )
67      . "\n";
68    print STDERR $log_line;
69
70}
71
72sub emerg  { shift->print( 'emerg',  @_ ) }
73sub alert  { shift->print( 'alert',  @_ ) }
74sub crit   { shift->print( 'crit',   @_ ) }
75sub error  { shift->print( 'error',  @_ ) }
76sub warn   { shift->print( 'warn',   @_ ) }
77sub notice { shift->print( 'notice', @_ ) }
78sub info   { shift->print( 'info',   @_ ) }
79sub debug  { shift->print( 'debug',  @_ ) }
80
81sub longmess { shift->print( 'debug', Carp::longmess(@_) ) }
82
83sub dump {
84    my $self = shift;
85    my $d = Data::Dumper->new( [@_] );
86    $d->Sortkeys(1);
87    $self->print( 'debug', $d->Dump() );
88}
89
901;
91