diff options
Diffstat (limited to 'LedgerSMB')
-rw-r--r-- | LedgerSMB/Log.pm | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/LedgerSMB/Log.pm b/LedgerSMB/Log.pm index f816660b..0613132b 100644 --- a/LedgerSMB/Log.pm +++ b/LedgerSMB/Log.pm @@ -13,6 +13,7 @@ This module is loosly based on Apache::Log. Available methods: (in order, most to least severe) + =over 4 =item emerg @@ -31,6 +32,14 @@ Available methods: (in order, most to least severe) =item debug +=item longmess + +This uses Carp to make a debug message with the full stack backtrace, including function arguments, where Carp can infer them. + +=item dump + +This uses Data::Dumper to dump the contents of a data structure as a debug message. + =back =cut @@ -41,30 +50,20 @@ use warnings; use IO::File; use Data::Dumper; use LedgerSMB::Sysconfig; +use Carp (); +our $VERSION = '1.0.0'; -our $fh; +our $log_line; sub print { if (!$LedgerSMB::Sysconfig::logging){ return 0; } shift; - unless($fh) { - # TODO: this is grosly wrong, but so is this module in the first place. - # the log messages *should* end up in the apache log, but that will - # hopefully be corrected in the future. - - $fh=IO::File->new('>>users/ledger-smb.log'); - $fh->autoflush(1); - __PACKAGE__->print('general',"Log file opened"); - } + $log_line = sprintf('[%s] [%s] %i %s', scalar(localtime), +shift, $$, join(' ',@_))."\n"; + print STDERR $log_line; - $fh->print(sprintf('[%s] [%s] %i %s', - scalar(localtime), - +shift, - $$, - join(' ',@_))."\n"); } @@ -76,11 +75,14 @@ sub warn { shift->print('warn',@_) } sub notice { shift->print('notice',@_) } sub info { shift->print('info',@_) } sub debug { shift->print('debug',@_) } + +sub longmess { shift->print('debug',Carp::longmess(@_)) } + sub dump { my $self = shift; my $d = Data::Dumper->new([@_]); $d->Sortkeys(1); - $self->print('dump',$d->Dump()); + $self->print('debug',$d->Dump()); } 1; |