summaryrefslogtreecommitdiff
path: root/LedgerSMB/Log.pm
blob: 235a2dedf72f84db82b984e75d42a6e42df4674f (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 { shift->print('dump',Dumper(@_)) }
  55. 1;