PageRenderTime 53ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/CXGN/Error/Tag.pm

https://github.com/dmb387/cxgn-corelibs
Perl | 74 lines | 64 code | 10 blank | 0 comment | 2 complexity | 433492db45fb19bcc5c19c9e5df0b749 MD5 | raw file
  1. =head1 NAME
  2. CXGN::Error::Tag
  3. =head1 AUTHOR
  4. John Binns <zombieite@gmail.com>
  5. =head1 DESCRIPTION
  6. Allows you to send tagged error messages to STDERR. We may someday want to
  7. grep through error logs to find these tagged messages.
  8. =head2 dbg
  9. Short for "debug". Prints a message to STDERR with tag markers around it,
  10. but only if we are NOT the production server. a shorter way to do the common
  11. debugging technique of
  12. print STDERR 'i got here!';
  13. And, it won't matter too much if you forget to comment it out later.
  14. use CXGN::Error::Tag ('dbg','wrn');
  15. dbg;#prints just empty dbg tags, as long as you are not a production server.
  16. dbg('my debug message');#prints a message in dbg tags
  17. dbg('my debug message','tag');#prints a message in tags of your choosing
  18. =head2 wrn
  19. Short for "warn". Does a warn with your message, putting tag markers around it.
  20. The warn command (or this command) will sometimes behave a bit differently from merely
  21. printing to STDERR. For instance, on our web server, "warn" also usually prints
  22. a timestamp to the log.
  23. use CXGN::Error::Tag ('dbg','wrn');
  24. wrn;#prints just empty wrn tags
  25. wrn('my debug message');#prints a message in wrn tags
  26. wrn('my debug message','tag');#prints a message in tags of your choosing
  27. =cut
  28. package CXGN::Error::Tag;
  29. use strict;
  30. use CXGN::VHost;
  31. BEGIN{our @EXPORT_OK=('dbg','wrn');}
  32. our @EXPORT_OK;
  33. use base qw/Exporter/;
  34. our($open,$close)=('<[',']>');
  35. sub dbg
  36. {
  37. my($error,$tag)=@_;
  38. $error||='';
  39. $tag||='dbg';
  40. my $conf=CXGN::VHost->new();
  41. unless($conf->get_conf('production_server'))
  42. {
  43. print STDERR "$open$tag$close$error$open/$tag$close\n"
  44. }
  45. }
  46. sub wrn
  47. {
  48. my($error,$tag)=@_;
  49. $error||='';
  50. $tag||='wrn';
  51. warn"$open$tag$close$error$open/$tag$close";
  52. }
  53. 1;