Log.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libfbasics - library of some basic tools
  4. * See file License for license information.
  5. */
  6. #ifndef _LOG_H_
  7. #define _LOG_H_
  8. #include <iostream>
  9. #include <sstream>
  10. namespace NICE {
  11. /**
  12. * A simple Logging mechanism.
  13. * \note Interface might change in future versions!
  14. */
  15. class Log { //: public std::ostream<char> {
  16. public:
  17. inline Log(std::ostream& _target = std::cerr)
  18. : target(&_target), quiet(false) {}
  19. virtual ~Log();
  20. // inline static Log& global() {
  21. // return globalLog;
  22. // }
  23. //
  24. // inline static Log& error() {
  25. // return globalLog;
  26. // }
  27. //! for debug messages
  28. inline static std::ostream& debug() { return _debugLog(); }
  29. //! for errors
  30. inline static std::ostream& error() { return _errorLog(); }
  31. //! for timing data
  32. inline static std::ostream& timing() { return _timingLog(); }
  33. //! for detailed results
  34. inline static std::ostream& detail() { return _detailLog(); }
  35. //! for main results (defaults to std::cout, not std::cerr)
  36. inline static std::ostream& result() { return _resultLog(); }
  37. //! for debug messages
  38. inline static Log& debugLog() { return _debugLog; }
  39. //! for errors
  40. inline static Log& errorLog() { return _errorLog; }
  41. //! for timing data
  42. inline static Log& timingLog() { return _timingLog; }
  43. //! for detailed results
  44. inline static Log& detailLog() { return _detailLog; }
  45. //! for main results (defaults to std::cout, not std::cerr)
  46. inline static Log& resultLog() { return _resultLog; }
  47. inline std::ostream& operator() () {
  48. if (quiet) {
  49. return dummy;
  50. } else {
  51. return *target;
  52. }
  53. }
  54. inline void setQuiet(const bool _quiet = true) {
  55. quiet = _quiet;
  56. }
  57. private:
  58. static Log _debugLog;
  59. static Log _errorLog;
  60. static Log _timingLog;
  61. static Log _detailLog;
  62. static Log _resultLog;
  63. static std::stringstream dummy;
  64. std::ostream* target;
  65. bool quiet;
  66. };
  67. } // namespace
  68. #endif //_LOG_H_