Skip to content

Commit

Permalink
Verbosity level and other related changes (CloudCompare#1956)
Browse files Browse the repository at this point in the history
* Implement verbosity options to ccLog

* various fixes in command line tools.

* Added process timer for each subcommand and print every command name as a warning. Adn for that delete every command print from each command->process.

* update changelog

* remove white lines

* syntax fixes, and comment fixes

* octree subsampling reuse already computed octree if possible.

* updates after review

* increase the number of verbosity levels

---------

Co-authored-by: Daniel Girardeau-Montaut <[email protected]>
  • Loading branch information
HeadLessHUN and dgirardeau authored Feb 8, 2024
1 parent bcadd49 commit dde9986
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 170 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ v2.13.beta (???) - (??/??/2024)
- it is possible to use FIRST and LAST at the same time. Example: xx...xx
- REMOVE_SENSORS
- removes all the sensors (both TLS and cameras, directly under clouds, meshes or mesh vertices)
- VERBOSITY [0-3] to set verbosity level (0 standard or higher, 1 debug or higher, 2 warning or higher,3 only error)
- to hide plugin messages it should be the first argument even before -SILENT, in this case -SILENT can be the second argument.

- Improvements:

Expand Down
2 changes: 2 additions & 0 deletions libs/CCPluginAPI/include/ccCommandLineInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ class CCPLUGIN_LIB_API ccCommandLineInterface
public: //logging

//logging
virtual void printVerbose(const QString& message) const = 0;
virtual void print(const QString& message) const = 0;
virtual void printHigh(const QString& message) const = 0;
virtual void printDebug(const QString& message) const = 0;
virtual void warning(const QString& message) const = 0;
virtual void warningDebug(const QString& message) const = 0;
Expand Down
75 changes: 51 additions & 24 deletions libs/qCC_db/include/ccLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,21 @@ class QCC_DB_LIB_API ccLog
//! Message level
enum MessageLevelFlags
{
LOG_STANDARD = 0, /**< Standard message (Print) **/
LOG_DEBUG = 1, /**< Debug only flag **/
LOG_WARNING = 2, /**< Warning message (Warning) **/
LOG_VERBOSE = 0, /**< Verbose message (Debug) **/
LOG_STANDARD = 1, /**< Standard message (Print) **/
LOG_IMPORTANT = 2, /**< Important messages (PrintHigh) **/
LOG_WARNING = 3, /**< Warning message (Warning) **/
LOG_ERROR = 4, /**< Error message (Error) **/

DEBUG_FLAG = 8 /**< Debug flag (reserved) **/
};

//! Returns the current verbosity level
static int VerbosityLevel();

//! Sets the verbosity level
static void SetVerbosityLevel(int level);

//! Static shortcut to ccLog::logMessage
static void LogMessage(const QString& message, int level);

Expand All @@ -69,57 +78,75 @@ class QCC_DB_LIB_API ccLog
**/
virtual void logMessage(const QString& message, int level) = 0;

//! Prints out a verbose formatted message in console
/** Works just like the 'printf' command.
\return always 'true'
**/
static bool PrintVerbose(const char* format, ...);

//! QString version of ccLog::PrintVerbose
static bool PrintVerbose(const QString& message);

//! Prints out a formatted message in console
/** Works just like the 'printf' command.
\return always return 'true'
\return always 'true'
**/
static bool Print(const char *format, ...);
static bool Print(const char* format, ...);

//! QString version of ccLog::Print
inline static bool Print(const QString& message) { LogMessage(message, LOG_STANDARD); return true; }
static bool Print(const QString& message);

//! Prints out an important formatted message in console
/** Works just like the 'printf' command.
\return always 'true'
**/
static bool PrintHigh(const char* format, ...);

//! QString version of ccLog::PrintHigh
static bool PrintHigh(const QString& message);

//! Same as Print, but works only in debug mode
//! Same as Print, but works only in Debug mode
/** Works just like the 'printf' command.
\return always return 'true'
\return always 'true'
**/
static bool PrintDebug(const char *format, ...);
static bool PrintDebug(const char* format, ...);

//! QString version of ccLog::PrintDebug
inline static bool PrintDebug(const QString& message) { LogMessage(message, LOG_STANDARD | LOG_DEBUG); return true; }
static bool PrintDebug(const QString& message);

//! Prints out a formatted warning message in console
/** Works just like the 'printf' command.
\return always return 'false'
\return always 'false'
**/
static bool Warning(const char *format, ...);
static bool Warning(const char* format, ...);

//! QString version of ccLog::Warning
inline static bool Warning(const QString& message) { LogMessage(message, LOG_WARNING); return false; }
static bool Warning(const QString& message);

//! Same as Warning, but works only in debug mode
//! Same as Warning, but works only in Debug mode
/** Works just like the 'printf' command.
\return always return 'false'
\return always 'false'
**/
static bool WarningDebug(const char *format, ...);
static bool WarningDebug(const char* format, ...);

//! QString version of ccLog::WarningDebug
inline static bool WarningDebug(const QString& message) { LogMessage(message, LOG_WARNING | LOG_DEBUG); return false; }
static bool WarningDebug(const QString& message);

//! Display an error dialog with formatted message
/** Works just like the 'printf' command.
\return always return 'false'
\return always 'false'
**/
static bool Error(const char *format, ...);
static bool Error(const char* format, ...);

//! QString version of 'Error'
inline static bool Error(const QString& message) { LogMessage(message, LOG_ERROR); return false; }
static bool Error(const QString& message);

//! Same as Error, but works only in debug mode
//! Same as Error, but works only in Debug mode
/** Works just like the 'printf' command.
\return always return 'false'
\return always 'false'
**/
static bool ErrorDebug(const char *format, ...);
static bool ErrorDebug(const char* format, ...);

//! QString version of ccLog::ErrorDebug
static bool ErrorDebug(const QString& message) { LogMessage(message, LOG_ERROR | LOG_DEBUG); return false; }
static bool ErrorDebug(const QString& message);
};
98 changes: 90 additions & 8 deletions libs/qCC_db/src/ccLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ struct Message

//message backup system
static bool s_backupEnabled;

//message verbosity level
#ifdef QT_DEBUG
static int s_verbosityLevel = ccLog::LOG_VERBOSE;
#else
static int s_verbosityLevel = ccLog::LOG_STANDARD;
#endif

//backed up messages
static std::vector<Message> s_backupMessages;

Expand All @@ -66,15 +74,23 @@ void ccLog::EnableMessageBackup(bool state)
s_backupEnabled = state;
}

int ccLog::VerbosityLevel()
{
return s_verbosityLevel;
}

void ccLog::SetVerbosityLevel(int level)
{
s_verbosityLevel = std::min(level, static_cast<int>(LOG_ERROR)); // can't ignore error messages
}

void ccLog::LogMessage(const QString& message, int level)
{
#ifndef QT_DEBUG
//skip debug messages in release mode as soon as possible
if (level & LOG_DEBUG)
//skip messages below the current 'verbosity' level
if ((level & 7) < s_verbosityLevel)
{
return;
}
#endif

if (s_instance)
{
Expand Down Expand Up @@ -119,44 +135,110 @@ void ccLog::RegisterInstance(ccLog* logInstance)
LogMessage(QString(s_buffer), flags);\
}\

bool ccLog::PrintVerbose(const char* format, ...)
{
LOG_ARGS(LOG_VERBOSE)
return true;
}

bool ccLog::PrintVerbose(const QString& message)
{
LogMessage(message, LOG_VERBOSE);
return true;
}

bool ccLog::Print(const char* format, ...)
{
LOG_ARGS(LOG_STANDARD)
return true;
}

bool ccLog::Print(const QString& message)
{
LogMessage(message, LOG_STANDARD);
return true;
}

bool ccLog::PrintHigh(const char* format, ...)
{
LOG_ARGS(LOG_IMPORTANT)
return true;
}

bool ccLog::PrintHigh(const QString& message)
{
LogMessage(message, LOG_IMPORTANT);
return true;
}

bool ccLog::Warning(const char* format, ...)
{
LOG_ARGS(LOG_WARNING)
return false;
}

bool ccLog::Warning(const QString& message)
{
LogMessage(message, LOG_WARNING);
return false;
}

bool ccLog::Error(const char* format, ...)
{
LOG_ARGS(LOG_ERROR)
return false;
}

bool ccLog::Error(const QString& message)
{
LogMessage(message, LOG_ERROR);
return false;
}

bool ccLog::PrintDebug(const char* format, ...)
{
#ifdef QT_DEBUG
LOG_ARGS(LOG_STANDARD | LOG_DEBUG)
LOG_ARGS(LOG_STANDARD | DEBUG_FLAG)
#endif
return true;
return false;
}

bool ccLog::PrintDebug(const QString& message)
{
#ifdef QT_DEBUG
LogMessage(message, LOG_STANDARD | DEBUG_FLAG);
#endif
return false;
}

bool ccLog::WarningDebug(const char* format, ...)
{
#ifdef QT_DEBUG
LOG_ARGS(LOG_WARNING | LOG_DEBUG)
LOG_ARGS(LOG_WARNING)
#endif
return false;
}

bool ccLog::WarningDebug(const QString& message)
{
#ifdef QT_DEBUG
LogMessage(message, LOG_WARNING | DEBUG_FLAG);
#endif
return false;
}

bool ccLog::ErrorDebug(const char* format, ...)
{
#ifdef QT_DEBUG
LOG_ARGS(LOG_ERROR | LOG_DEBUG)
LOG_ARGS(LOG_ERROR)
#endif
return false;
}

bool ccLog::ErrorDebug(const QString& message)
{
#ifdef QT_DEBUG
LogMessage(message, LOG_ERROR | DEBUG_FLAG);
#endif
return false;
}
Loading

0 comments on commit dde9986

Please sign in to comment.