Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logging facilities #1571

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/OpenCvSharp/Cv2/Cv2_core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3590,6 +3590,35 @@ public static string Format(InputArray mtx, FormatType format = FormatType.Defau

#endregion

#region logger.hpp

/// <summary>
/// Set global logging level
/// </summary>
/// <param name="logLevel">logging level</param>
/// <returns>previous logging level</returns>
public static LogLevel SetLogLevel(LogLevel logLevel)
{
NativeMethods.HandleException(
NativeMethods.core_logger_setLogLevel(logLevel, out var previous));

return previous;
}

/// <summary>
/// Get global logging level
/// </summary>
/// <returns>logging level</returns>
public static LogLevel GetLogLevel()
{
NativeMethods.HandleException(
NativeMethods.core_logger_getLogLevel(out var logLevel));

return logLevel;
}

#endregion

/// <summary>
/// Computes absolute value of each matrix element
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ static partial class NativeMethods

#endregion

#region logger.hpp

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus core_logger_setLogLevel(LogLevel logLevel, out LogLevel returnValue);

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus core_logger_getLogLevel(out LogLevel returnValue);

#endregion

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus core_borderInterpolate(
int p, int len, int borderType, out int returnValue);
Expand Down
42 changes: 42 additions & 0 deletions src/OpenCvSharp/Modules/core/Enum/LogLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace OpenCvSharp;

/// <summary>
/// cv::utils::logging::LogLevel
/// </summary>
public enum LogLevel
{
/// <summary>
/// for using in setLogVevel() call
/// </summary>
LOG_LEVEL_SILENT = 0,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing the common prefix LOG_LEVEL_ from each field name, which is the same as the type name.

Suggested change
LOG_LEVEL_SILENT = 0,
SILENT = 0,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good point.


/// <summary>
/// Fatal (critical) error (unrecoverable internal error)
/// </summary>
LOG_LEVEL_FATAL = 1,

/// <summary>
/// Error message.
/// </summary>
LOG_LEVEL_ERROR = 2,

/// <summary>
/// Warning message.
/// </summary>
LOG_LEVEL_WARNING = 3,

/// <summary>
/// Info message.
/// </summary>
LOG_LEVEL_INFO = 4,

/// <summary>
/// Debug message. Disabled in the "Release" build.
/// </summary>
LOG_LEVEL_DEBUG = 5,

/// <summary>
/// Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build.
/// </summary>
LOG_LEVEL_VERBOSE = 6
}
18 changes: 18 additions & 0 deletions src/OpenCvSharpExtern/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,24 @@ CVAPI(ExceptionStatus) core_format(cv::_InputArray *mtx, int fmt, std::string *b

#pragma endregion

#pragma region logger.hpp

CVAPI(ExceptionStatus) core_logger_setLogLevel(cv::utils::logging::LogLevel logLevel, cv::utils::logging::LogLevel* returnValue)
{
BEGIN_WRAP
*returnValue = cv::utils::logging::setLogLevel(logLevel);
END_WRAP
}

CVAPI(ExceptionStatus) core_logger_getLogLevel(cv::utils::logging::LogLevel *returnValue)
{
BEGIN_WRAP
*returnValue = cv::utils::logging::getLogLevel();
END_WRAP
}

#pragma endregion

#pragma region RNG

CVAPI(ExceptionStatus) core_RNG_fill(uint64 *state, cv::_InputOutputArray *mat, int distType, cv::_InputArray *a, cv::_InputArray *b, int saturateRange)
Expand Down
1 change: 1 addition & 0 deletions src/OpenCvSharpExtern/include_opencv.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#ifdef _WINRT_DLL
#include <opencv2/highgui/highgui_winrt.hpp>
#endif
#include <opencv2/core/utils/logger.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/shape.hpp>
Expand Down