summaryrefslogtreecommitdiff
path: root/LedgerSMB/Log.pm
blob: d102705d17fdbe3774db8f1a90dfd2193034fc36 (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',
  39. scalar(localtime), +shift, $$, join( ' ', @_ ) )
  40. . "\n";
  41. print STDERR $log_line;
  42. }
  43. sub emerg { shift->print( 'emerg', @_ ) }
  44. sub alert { shift->print( 'alert', @_ ) }
  45. sub crit { shift->print( 'crit', @_ ) }
  46. sub error { shift->print( 'error', @_ ) }
  47. sub warn { shift->print( 'warn', @_ ) }
  48. sub notice { shift->print( 'notice', @_ ) }
  49. sub info { shift->print( 'info', @_ ) }
  50. sub debug { shift->print( 'debug', @_ ) }
  51. sub longmess { shift->print( 'debug', Carp::longmess(@_) ) }
  52. sub dump {
  53. my $self = shift;
  54. my $d = Data::Dumper->new( [@_] );
  55. $d->Sortkeys(1);
  56. $self->print( 'debug', $d->Dump() );
  57. }
  58. 1;