logger.hpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef OPENCV_LOGGING_HPP
  5. #define OPENCV_LOGGING_HPP
  6. #include <iostream>
  7. #include <sstream>
  8. #include <limits.h> // INT_MAX
  9. // TODO This file contains just interface part with implementation stubs.
  10. //! @addtogroup core_logging
  11. // This section describes OpenCV logging utilities.
  12. //
  13. //! @{
  14. namespace cv {
  15. namespace utils {
  16. namespace logging {
  17. // Supported logging levels and their semantic
  18. #define CV_LOG_LEVEL_SILENT 0 //!< for using in setLogVevel() call
  19. #define CV_LOG_LEVEL_FATAL 1 //!< Fatal (critical) error (unrecoverable internal error)
  20. #define CV_LOG_LEVEL_ERROR 2 //!< Error message
  21. #define CV_LOG_LEVEL_WARN 3 //!< Warning message
  22. #define CV_LOG_LEVEL_INFO 4 //!< Info message
  23. #define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build.
  24. #define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build.
  25. //! Supported logging levels and their semantic
  26. enum LogLevel {
  27. LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call
  28. LOG_LEVEL_FATAL = 1, //!< Fatal (critical) error (unrecoverable internal error)
  29. LOG_LEVEL_ERROR = 2, //!< Error message
  30. LOG_LEVEL_WARNING = 3, //!< Warning message
  31. LOG_LEVEL_INFO = 4, //!< Info message
  32. LOG_LEVEL_DEBUG = 5, //!< Debug message. Disabled in the "Release" build.
  33. LOG_LEVEL_VERBOSE = 6, //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build.
  34. #ifndef CV_DOXYGEN
  35. ENUM_LOG_LEVEL_FORCE_INT = INT_MAX
  36. #endif
  37. };
  38. /**
  39. * \def CV_LOG_STRIP_LEVEL
  40. *
  41. * Define CV_LOG_STRIP_LEVEL=CV_LOG_LEVEL_[DEBUG|INFO|WARN|ERROR|FATAL|DISABLED] to compile out anything at that and before that logging level
  42. */
  43. #ifndef CV_LOG_STRIP_LEVEL
  44. # if defined NDEBUG
  45. # define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG
  46. # else
  47. # define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE
  48. # endif
  49. #endif
  50. #define CV_LOG_FATAL(tag, ...) for(;;) { std::stringstream ss; ss << "[FATAL:" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cerr << ss.str(); break; }
  51. #define CV_LOG_ERROR(tag, ...) for(;;) { std::stringstream ss; ss << "[ERROR:" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cerr << ss.str(); break; }
  52. #define CV_LOG_WARNING(tag, ...) for(;;) { std::stringstream ss; ss << "[ WARN:" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cout << ss.str(); break; }
  53. #if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO
  54. #define CV_LOG_INFO(tag, ...)
  55. #else
  56. #define CV_LOG_INFO(tag, ...) for(;;) { std::stringstream ss; ss << "[ INFO:" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cout << ss.str(); break; }
  57. #endif
  58. #if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG
  59. #define CV_LOG_DEBUG(tag, ...)
  60. #else
  61. #define CV_LOG_DEBUG(tag, ...) for(;;) { std::stringstream ss; ss << "[DEBUG:" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cout << ss.str(); break; }
  62. #endif
  63. #if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE
  64. #define CV_LOG_VERBOSE(tag, v, ...)
  65. #else
  66. #define CV_LOG_VERBOSE(tag, v, ...) for(;;) { std::stringstream ss; ss << "[VERB" << v << ":" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cout << ss.str(); break; }
  67. #endif
  68. }}} // namespace
  69. //! @}
  70. #endif // OPENCV_LOGGING_HPP