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