cutdigital / mcut

A library for detecting and resolving intersections between two surface meshes.
https://cutdigital.github.io/mcut.site
Other
413 stars 76 forks source link

Silence log messaging #30

Closed Q-Minh closed 1 year ago

Q-Minh commented 1 year ago

Hi,

Thank you so much for this amazing library, the code is very well designed (very similar to CUDA APIs!) and the features are incredibly useful. I've tried out various of MCUT's features on a limited set of inputs, and they work as expected. However, I noticed that the log_msg macro is used throughout the internal implementations with no quiet mode or filtering option. Would it be possible to silence the logs, as outputting and flushing things to the console is problematic for performance and usability in other code bases?

Thank you so much again!

chitalu commented 1 year ago

Hi @Q-Minh

Thanks, I understand. I will keep this issue open so that I look into it soon.

Q-Minh commented 1 year ago

If I may suggest one approach, you could define a preprocessor directive in the CMakeLists.txt such as MC_DISABLE_LOG_MSG so that users of your library can explicitly turn it on if they wish to via set(MC_DISABLE_LOG_MSG ON). Then, in the library's sources, you can define the log_msg macro conditionally, i.e.

#ifndef MC_DISABLE_LOG_MSG
// Define log_msg macro as usual
// ...
#else
// Define log_msg macro as no-op
// ...
#endif

This way, you don't need to change any of the implementation/interface code.

chitalu commented 1 year ago

Thanks for the suggestion.

Justpenz233 commented 1 year ago

Also consider adding additional control flags into mcDebugMessageControl, for supressing all mesaages.

chitalu commented 1 year ago

Hi @Q-Minh ,

This is now resolved (pull latest commit from mster).

@Justpenz233 You can already do this by:

// ....
McSize numBytes = 0;
McFlags contextFlags;
api_err = mcGetInfo(context, MC_CONTEXT_FLAGS, 0, nullptr, &numBytes);

api_err = mcGetInfo(context, MC_CONTEXT_FLAGS, numBytes, &contextFlags, nullptr);

if (contextFlags & MC_DEBUG) {
    mcDebugMessageCallback(context, mcDebugOutput, nullptr);
    mcDebugMessageControl(context, McDebugSource::MC_DEBUG_SOURCE_ALL,
        McDebugType::MC_DEBUG_TYPE_ALL,
        McDebugSeverity::MC_DEBUG_SEVERITY_ALL, 
        false); // <---- here is what you want
}
// ....