mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
core(logger): add log level configuration option
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_LOGGER_DEFINES_HPP
|
||||
#define OPENCV_LOGGER_DEFINES_HPP
|
||||
|
||||
//! @addtogroup core_logging
|
||||
//! @{
|
||||
|
||||
// Supported logging levels and their semantic
|
||||
#define CV_LOG_LEVEL_SILENT 0 //!< for using in setLogLevel() call
|
||||
#define CV_LOG_LEVEL_FATAL 1 //!< Fatal (critical) error (unrecoverable internal error)
|
||||
#define CV_LOG_LEVEL_ERROR 2 //!< Error message
|
||||
#define CV_LOG_LEVEL_WARN 3 //!< Warning message
|
||||
#define CV_LOG_LEVEL_INFO 4 //!< Info message
|
||||
#define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build.
|
||||
#define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build.
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // OPENCV_LOGGER_DEFINES_HPP
|
||||
@@ -2,14 +2,14 @@
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_LOGGING_HPP
|
||||
#define OPENCV_LOGGING_HPP
|
||||
#ifndef OPENCV_LOGGER_HPP
|
||||
#define OPENCV_LOGGER_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <limits.h> // INT_MAX
|
||||
|
||||
// TODO This file contains just interface part with implementation stubs.
|
||||
#include "logger.defines.hpp"
|
||||
|
||||
//! @addtogroup core_logging
|
||||
// This section describes OpenCV logging utilities.
|
||||
@@ -20,15 +20,6 @@ namespace cv {
|
||||
namespace utils {
|
||||
namespace logging {
|
||||
|
||||
// Supported logging levels and their semantic
|
||||
#define CV_LOG_LEVEL_SILENT 0 //!< for using in setLogVevel() call
|
||||
#define CV_LOG_LEVEL_FATAL 1 //!< Fatal (critical) error (unrecoverable internal error)
|
||||
#define CV_LOG_LEVEL_ERROR 2 //!< Error message
|
||||
#define CV_LOG_LEVEL_WARN 3 //!< Warning message
|
||||
#define CV_LOG_LEVEL_INFO 4 //!< Info message
|
||||
#define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build.
|
||||
#define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build.
|
||||
|
||||
//! Supported logging levels and their semantic
|
||||
enum LogLevel {
|
||||
LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call
|
||||
@@ -43,6 +34,17 @@ enum LogLevel {
|
||||
#endif
|
||||
};
|
||||
|
||||
/** Set global logging level
|
||||
@return previous logging level
|
||||
*/
|
||||
CV_EXPORTS LogLevel setLogLevel(LogLevel logLevel);
|
||||
/** Get global logging level */
|
||||
CV_EXPORTS LogLevel getLogLevel();
|
||||
|
||||
namespace internal {
|
||||
/** Write log message */
|
||||
CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message);
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* \def CV_LOG_STRIP_LEVEL
|
||||
@@ -58,23 +60,23 @@ enum LogLevel {
|
||||
#endif
|
||||
|
||||
|
||||
#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; }
|
||||
#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; }
|
||||
#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; }
|
||||
#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; }
|
||||
#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; }
|
||||
#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; }
|
||||
#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO
|
||||
#define CV_LOG_INFO(tag, ...)
|
||||
#else
|
||||
#define CV_LOG_INFO(tag, ...) for(;;) { std::stringstream ss; ss << "[ INFO:" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cout << ss.str(); break; }
|
||||
#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; }
|
||||
#endif
|
||||
#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG
|
||||
#define CV_LOG_DEBUG(tag, ...)
|
||||
#else
|
||||
#define CV_LOG_DEBUG(tag, ...) for(;;) { std::stringstream ss; ss << "[DEBUG:" << cv::utils::getThreadID() << "] " << __VA_ARGS__ << std::endl; std::cout << ss.str(); break; }
|
||||
#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; }
|
||||
#endif
|
||||
#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE
|
||||
#define CV_LOG_VERBOSE(tag, v, ...)
|
||||
#else
|
||||
#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; }
|
||||
#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; }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -82,4 +84,4 @@ enum LogLevel {
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // OPENCV_LOGGING_HPP
|
||||
#endif // OPENCV_LOGGER_HPP
|
||||
|
||||
Reference in New Issue
Block a user