ccLog.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. //Local
  19. #include "qCC_db.h"
  20. //system
  21. #include <stdio.h>
  22. #include <string>
  23. //Qt
  24. #include <QString>
  25. //! Main log interface
  26. /** This interface is meant to be used as a unique (static) instance.
  27. It should be thread safe!
  28. **/
  29. class QCC_DB_LIB_API ccLog
  30. {
  31. public:
  32. //! Destructor
  33. virtual ~ccLog() {}
  34. //! Returns the static and unique instance
  35. static ccLog* TheInstance();
  36. //! Registers a unique instance
  37. static void RegisterInstance(ccLog* logInstance);
  38. //! Enables the message backup system
  39. /** Stores the messages until a valid logging instance is registered.
  40. **/
  41. static void EnableMessageBackup(bool state);
  42. //! Message level
  43. enum MessageLevelFlags
  44. {
  45. LOG_VERBOSE = 0, /**< Verbose message (Debug) **/
  46. LOG_STANDARD = 1, /**< Standard message (Print) **/
  47. LOG_IMPORTANT = 2, /**< Important messages (PrintHigh) **/
  48. LOG_WARNING = 3, /**< Warning message (Warning) **/
  49. LOG_ERROR = 4, /**< Error message (Error) **/
  50. DEBUG_FLAG = 8 /**< Debug flag (reserved) **/
  51. };
  52. //! Returns the current verbosity level
  53. static int VerbosityLevel();
  54. //! Sets the verbosity level
  55. static void SetVerbosityLevel(int level);
  56. //! Static shortcut to ccLog::logMessage
  57. static void LogMessage(const QString& message, int level);
  58. //! Generic message logging method
  59. /** To be implemented by child class.
  60. \warning MUST BE THREAD SAFE!
  61. \param message message
  62. \param level message severity (see MessageLevelFlags)
  63. **/
  64. virtual void logMessage(const QString& message, int level) = 0;
  65. //! Prints out a verbose formatted message in console
  66. /** Works just like the 'printf' command.
  67. \return always 'true'
  68. **/
  69. static bool PrintVerbose(const char* format, ...);
  70. //! QString version of ccLog::PrintVerbose
  71. static bool PrintVerbose(const QString& message);
  72. //! Prints out a formatted message in console
  73. /** Works just like the 'printf' command.
  74. \return always 'true'
  75. **/
  76. static bool Print(const char* format, ...);
  77. //! QString version of ccLog::Print
  78. static bool Print(const QString& message);
  79. //! Prints out an important formatted message in console
  80. /** Works just like the 'printf' command.
  81. \return always 'true'
  82. **/
  83. static bool PrintHigh(const char* format, ...);
  84. //! QString version of ccLog::PrintHigh
  85. static bool PrintHigh(const QString& message);
  86. //! Same as Print, but works only in Debug mode
  87. /** Works just like the 'printf' command.
  88. \return always 'true'
  89. **/
  90. static bool PrintDebug(const char* format, ...);
  91. //! QString version of ccLog::PrintDebug
  92. static bool PrintDebug(const QString& message);
  93. //! Prints out a formatted warning message in console
  94. /** Works just like the 'printf' command.
  95. \return always 'false'
  96. **/
  97. static bool Warning(const char* format, ...);
  98. //! QString version of ccLog::Warning
  99. static bool Warning(const QString& message);
  100. //! Same as Warning, but works only in Debug mode
  101. /** Works just like the 'printf' command.
  102. \return always 'false'
  103. **/
  104. static bool WarningDebug(const char* format, ...);
  105. //! QString version of ccLog::WarningDebug
  106. static bool WarningDebug(const QString& message);
  107. //! Display an error dialog with formatted message
  108. /** Works just like the 'printf' command.
  109. \return always 'false'
  110. **/
  111. static bool Error(const char* format, ...);
  112. //! QString version of 'Error'
  113. static bool Error(const QString& message);
  114. //! Same as Error, but works only in Debug mode
  115. /** Works just like the 'printf' command.
  116. \return always 'false'
  117. **/
  118. static bool ErrorDebug(const char* format, ...);
  119. //! QString version of ccLog::ErrorDebug
  120. static bool ErrorDebug(const QString& message);
  121. };