2
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
3
// of this distribution and at http://opencv.org/license.html.
4
4
5
- #ifndef OPENCV_LOGGING_HPP
6
- #define OPENCV_LOGGING_HPP
5
+ #ifndef OPENCV_LOGGER_HPP
6
+ #define OPENCV_LOGGER_HPP
7
7
8
8
#include < iostream>
9
9
#include < sstream>
10
10
#include < limits.h> // INT_MAX
11
11
12
- // TODO This file contains just interface part with implementation stubs.
12
+ # include " logger.defines.hpp "
13
13
14
14
// ! @addtogroup core_logging
15
15
// This section describes OpenCV logging utilities.
@@ -20,15 +20,6 @@ namespace cv {
20
20
namespace utils {
21
21
namespace logging {
22
22
23
- // Supported logging levels and their semantic
24
- #define CV_LOG_LEVEL_SILENT 0 // !< for using in setLogVevel() call
25
- #define CV_LOG_LEVEL_FATAL 1 // !< Fatal (critical) error (unrecoverable internal error)
26
- #define CV_LOG_LEVEL_ERROR 2 // !< Error message
27
- #define CV_LOG_LEVEL_WARN 3 // !< Warning message
28
- #define CV_LOG_LEVEL_INFO 4 // !< Info message
29
- #define CV_LOG_LEVEL_DEBUG 5 // !< Debug message. Disabled in the "Release" build.
30
- #define CV_LOG_LEVEL_VERBOSE 6 // !< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build.
31
-
32
23
// ! Supported logging levels and their semantic
33
24
enum LogLevel {
34
25
LOG_LEVEL_SILENT = 0 , // !< for using in setLogVevel() call
@@ -43,6 +34,17 @@ enum LogLevel {
43
34
#endif
44
35
};
45
36
37
+ /* * Set global logging level
38
+ @return previous logging level
39
+ */
40
+ CV_EXPORTS LogLevel setLogLevel (LogLevel logLevel);
41
+ /* * Get global logging level */
42
+ CV_EXPORTS LogLevel getLogLevel ();
43
+
44
+ namespace internal {
45
+ /* * Write log message */
46
+ CV_EXPORTS void writeLogMessage (LogLevel logLevel, const char * message);
47
+ } // namespace
46
48
47
49
/* *
48
50
* \def CV_LOG_STRIP_LEVEL
@@ -58,28 +60,28 @@ enum LogLevel {
58
60
#endif
59
61
60
62
61
- #define CV_LOG_FATAL (tag, ...) for (;;) { std::stringstream ss; ss << " [FATAL: " << cv::utils::getThreadID () << " ] " << __VA_ARGS__ << std::endl; std::cerr << ss.str () << std::flush ; break ; }
62
- #define CV_LOG_ERROR (tag, ...) for (;;) { std::stringstream ss; ss << " [ERROR: " << cv::utils::getThreadID () << " ] " << __VA_ARGS__ << std::endl; std::cerr << ss.str () << std::flush ; break ; }
63
- #define CV_LOG_WARNING (tag, ...) for (;;) { std::stringstream ss; ss << " [ WARN: " << cv::utils::getThreadID () << " ] " << __VA_ARGS__ << std::endl; std::cout << ss.str () << std::flush ; break ; }
63
+ #define CV_LOG_FATAL (tag, ...) for (;;) { if ( cv::utils::logging::getLogLevel () < cv::utils::logging::LOG_LEVEL_FATAL) break ; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage (cv::utils::logging::LOG_LEVEL_FATAL, ss.str (). c_str ()) ; break ; }
64
+ #define CV_LOG_ERROR (tag, ...) for (;;) { if ( cv::utils::logging::getLogLevel () < cv::utils::logging::LOG_LEVEL_ERROR) break ; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage (cv::utils::logging::LOG_LEVEL_ERROR, ss.str (). c_str ()) ; break ; }
65
+ #define CV_LOG_WARNING (tag, ...) for (;;) { if ( cv::utils::logging::getLogLevel () < cv::utils::logging::LOG_LEVEL_WARNING) break ; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage (cv::utils::logging::LOG_LEVEL_WARNING, ss.str (). c_str ()) ; break ; }
64
66
#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO
65
67
#define CV_LOG_INFO (tag, ...)
66
68
#else
67
- #define CV_LOG_INFO (tag, ...) for (;;) { std::stringstream ss; ss << " [ INFO: " << cv::utils::getThreadID () << " ] " << __VA_ARGS__ << std::endl; std::cout << ss.str (); break ; }
69
+ #define CV_LOG_INFO (tag, ...) for (;;) { if ( cv::utils::logging::getLogLevel () < cv::utils::logging::LOG_LEVEL_INFO) break ; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage (cv::utils::logging::LOG_LEVEL_INFO, ss.str (). c_str () ); break ; }
68
70
#endif
69
71
#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG
70
72
#define CV_LOG_DEBUG (tag, ...)
71
73
#else
72
- #define CV_LOG_DEBUG (tag, ...) for (;;) { std::stringstream ss; ss << " [DEBUG: " << cv::utils::getThreadID () << " ] " << __VA_ARGS__ << std::endl; std::cout << ss.str (); break ; }
74
+ #define CV_LOG_DEBUG (tag, ...) for (;;) { if ( cv::utils::logging::getLogLevel () < cv::utils::logging::LOG_LEVEL_DEBUG) break ; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage (cv::utils::logging::LOG_LEVEL_DEBUG, ss.str (). c_str () ); break ; }
73
75
#endif
74
76
#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE
75
77
#define CV_LOG_VERBOSE (tag, v, ...)
76
78
#else
77
- #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 ; }
79
+ #define CV_LOG_VERBOSE (tag, v, ...) for (;;) { if ( cv::utils::logging::getLogLevel () < cv::utils::logging::LOG_LEVEL_VERBOSE) break ; std::stringstream ss; ss << " [VERB" << v << " :" << cv::utils::getThreadID () << " ] " << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage (cv::utils::logging::LOG_LEVEL_VERBOSE, ss.str (). c_str () ); break ; }
78
80
#endif
79
81
80
82
81
83
}}} // namespace
82
84
83
85
// ! @}
84
86
85
- #endif // OPENCV_LOGGING_HPP
87
+ #endif // OPENCV_LOGGER_HPP
0 commit comments