summaryrefslogtreecommitdiff
path: root/LedgerSMB/Log.pm
blob: f816660bab52933c738c1441ef7a1dc85bf64e8d (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. =back
  19. =cut
  20. package LedgerSMB::Log;
  21. use strict;
  22. use warnings;
  23. use IO::File;
  24. use Data::Dumper;
  25. use LedgerSMB::Sysconfig;
  26. our $fh;
  27. sub print {
  28. if (!$LedgerSMB::Sysconfig::logging){
  29. return 0;
  30. }
  31. shift;
  32. unless($fh) {
  33. # TODO: this is grosly wrong, but so is this module in the first place.
  34. # the log messages *should* end up in the apache log, but that will
  35. # hopefully be corrected in the future.
  36. $fh=IO::File->new('>>users/ledger-smb.log');
  37. $fh->autoflush(1);
  38. __PACKAGE__->print('general',"Log file opened");
  39. }
  40. $fh->print(sprintf('[%s] [%s] %i %s',
  41. scalar(localtime),
  42. +shift,
  43. $$,
  44. join(' ',@_))."\n");
  45. }
  46. sub emerg { shift->print('emerg',@_) }
  47. sub alert { shift->print('alert',@_) }
  48. sub crit { shift->print('crit',@_) }
  49. sub error { shift->print('error',@_) }
  50. sub warn { shift->print('warn',@_) }
  51. sub notice { shift->print('notice',@_) }
  52. sub info { shift->print('info',@_) }
  53. sub debug { shift->print('debug',@_) }
  54. sub dump {
  55. my $self = shift;
  56. my $d = Data::Dumper->new([@_]);
  57. $d->Sortkeys(1);
  58. $self->print('dump',$d->Dump());
  59. }
  60. 1;