Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 42a2e06e authored by saubatn's avatar saubatn
Browse files

UPDATE Log level updated. Level 0, always enabled features CAMITK_ERROR &...

UPDATE Log level updated. Level 0, always enabled features CAMITK_ERROR & CAMITK_INFO. Level 1 (WARNING) and 2 (DEBUG) are optional.
FEATURE 588 Fixed warnings at compilation Time (Component.h)

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1871 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 8705d54e
......@@ -5,19 +5,14 @@
# --- Log in file or not
set( CAMITK_LOG_FILE FALSE CACHE BOOL "Log in Log.txt file in binary program directory (current working directory)")
if( CAMITK_LOG_FILE )
ADD_DEFINITIONS(-DLOG_IN_FILE)
add_definitions(-DLOG_IN_FILE)
endif()
# --- Log mode declaration (level)
set( CAMITK_LOG_LEVEL "0" CACHE STRING "Log Level: 0-Error and information (default) / 1-Warning / 2-Debug" )
if( CAMITK_LOG_LEVEL STREQUAL "2" )
add_definitions(-DCAMITK_LOG_DEBUG)
endif()
set( CAMITK_LOG_LEVEL "0" CACHE STRING "Log Level: 0-Information + Error (always enabled) / 1- + Warning / 2- + Warning + Debug" )
if( CAMITK_LOG_LEVEL STREQUAL "1" )
add_definitions(-DCAMITK_LOG_WARNING)
endif()
if(CAMITK_LOG_LEVEL STRLESS "1" OR LOG_MODE STRGREATER "2")
add_definitions(-DCAMITK_LOG_ERROR)
endif()
elseif( CAMITK_LOG_LEVEL STREQUAL "2" )
add_definitions(-DCAMITK_LOG_DEBUG)
endif()
\ No newline at end of file
......@@ -38,18 +38,18 @@ namespace camitk {
// -------------------- initResources --------------------
void ActionExtension::initResources(){
// Get the selected language
QString selectedLanguage = Application::getSelectedLanguage();
// Get the selected language
QString selectedLanguage = Application::getSelectedLanguage();
QString actionExtensionDirName = QDir(this->getLocation()).dirName();
// remove any occurence of "-debug.dll" or ".so" or ".dylib" on the extension file name
actionExtensionDirName.remove("-debug.dll").remove(".so").remove(".dylib");
QString languageFile = ":/translate_" + actionExtensionDirName + "/translate/translate_" + selectedLanguage + ".qm";
QTranslator* translator = new QTranslator();
if (!translator->load(languageFile))
CAMITK_WARNING("Application", "initResources", "Cannot load file: " + languageFile.toStdString());
else
QCoreApplication::installTranslator(translator);
QString actionExtensionDirName = QDir(this->getLocation()).dirName();
// remove any occurence of "-debug.dll" or ".so" or ".dylib" on the extension file name
actionExtensionDirName.remove("-debug.dll").remove(".so").remove(".dylib");
QString languageFile = ":/translate_" + actionExtensionDirName + "/translate/translate_" + selectedLanguage + ".qm";
QTranslator* translator = new QTranslator();
if (!translator->load(languageFile))
CAMITK_WARNING("Application", "initResources", "Cannot load file: " + languageFile.toStdString())
else
QCoreApplication::installTranslator(translator);
}
// -------------------- destructor --------------------
......
......@@ -33,6 +33,7 @@
#include "InterfaceProperty.h"
#include "InterfaceFrame.h"
#include "AbortException.h"
#include "Log.h"
// -- QT stuff
#include <QPixmap>
......@@ -759,39 +760,47 @@ public:
*/
///@{
const QString & getFrameName() const {
if(myFrame)
return myFrame->getFrameName();
if(!myFrame)
CAMITK_ERROR("Component", "getFrameName", "Delegate myFrame is not instanciated.")
return myFrame->getFrameName();
}
delegate1(myFrame, setFrameName, QString)
InterfaceFrame* getParentFrame() const {
if(myFrame)
return myFrame->getParentFrame();
if(!myFrame)
CAMITK_ERROR("Component", "getParentFrame", "Delegate myFrame is not instanciated.")
return myFrame->getParentFrame();
}
void setParentFrame(InterfaceFrame* frame, bool keepTransform = true) {
if(!myFrame)
CAMITK_ERROR("Component", "setParentFrame", "Delegate myFrame is not instanciated.")
return myFrame->setParentFrame(frame, keepTransform);
}
const QVector<InterfaceFrame *> & getChildrenFrame() const {
if(myFrame)
return myFrame->getChildrenFrame();
if(!myFrame)
CAMITK_ERROR("Component", "getChildrenFrame", "Delegate myFrame is not instanciated.")
return myFrame->getChildrenFrame();
}
const vtkSmartPointer<vtkTransform> getTransformFromWorld() const {
if(myFrame)
return myFrame->getTransformFromWorld();
if(!myFrame)
CAMITK_ERROR("Component", "getTransformFromWorld", "Delegate myFrame is not instanciated.")
return myFrame->getTransformFromWorld();
}
const vtkSmartPointer<vtkTransform> getTransformFromParent() const {
if(myFrame)
return myFrame->getTransformFromParent();
if(!myFrame)
CAMITK_ERROR("Component", "getTransformFromParent", "Delegate myFrame is not instanciated.")
return myFrame->getTransformFromParent();
}
vtkSmartPointer<vtkTransform> getTransformFromFrame(InterfaceFrame * frame) const {
if(myFrame)
return myFrame->getTransformFromFrame(frame);
if(!myFrame)
CAMITK_ERROR("Component", "getTransformFromFrame", "Delegate myFrame is not instanciated.")
return myFrame->getTransformFromFrame(frame);
}
delegate1(myFrame, setTransformFromParent, vtkSmartPointer<vtkTransform>)
......@@ -807,15 +816,17 @@ public:
delegate3(myFrame, setRotation, double, double, double)
vtkSmartPointer<vtkAxesActor> getFrameAxisActor() {
if(myFrame)
return myFrame->getFrameAxisActor();
if(!myFrame)
CAMITK_ERROR("Component", "getFrameAxisActor", "Delegate myFrame is not instanciated.")
return myFrame->getFrameAxisActor();
}
delegate2(myFrame, setFrameVisibility, Viewer *, bool)
bool getFrameVisibility(Viewer * viewer) const {
if(myFrame)
return myFrame->getFrameVisibility(viewer);
if(!myFrame)
CAMITK_ERROR("Component", "getFrameVisibility", "Delegate myFrame is not instanciated.")
return myFrame->getFrameVisibility(viewer);
}
delegate1(myFrame, addFrameChild, InterfaceFrame *)
......@@ -823,13 +834,15 @@ public:
delegate1(myFrame, removeFrameChild, InterfaceFrame *)
const QVector<InterfaceFrame *> & getDescendantsFrame() {
if(myFrame)
return myFrame->getDescendantsFrame();
if(!myFrame)
CAMITK_ERROR("Component", "getDescendantsFrame", "Delegate myFrame is not instanciated.")
return myFrame->getDescendantsFrame();
}
const QVector<QString *> & getDescendantsFrameName() {
if(myFrame)
return myFrame->getDescendantsFrameName();
if(!myFrame)
CAMITK_ERROR("Component", "getDescendantsFrameName", "Delegate myFrame is not instanciated.")
return myFrame->getDescendantsFrameName();
}
///@}
......
......@@ -55,18 +55,18 @@ bool ComponentExtension::save(Component* component) const {
// -------------------- initResources --------------------
void ComponentExtension::initResources(){
// Get the selected language
QString selectedLanguage = Application::getSelectedLanguage();
// Get the selected language
QString selectedLanguage = Application::getSelectedLanguage();
QString componentExtensionDirName = QDir(this->getLocation()).dirName();
// remove any occurence of "-debug.dll" or ".so" or ".dylib" on the extension file name
componentExtensionDirName.remove("-debug.dll").remove(".so").remove(".dylib");
QString languageFile = ":/translate_" + componentExtensionDirName + "/translate/translate_" + selectedLanguage + ".qm";
QTranslator* translator = new QTranslator();
if (!translator->load(languageFile))
CAMITK_WARNING("Application", "initResources", "Cannot load file: " + languageFile.toStdString());
else
QCoreApplication::installTranslator(translator);
QString componentExtensionDirName = QDir(this->getLocation()).dirName();
// remove any occurence of "-debug.dll" or ".so" or ".dylib" on the extension file name
componentExtensionDirName.remove("-debug.dll").remove(".so").remove(".dylib");
QString languageFile = ":/translate_" + componentExtensionDirName + "/translate/translate_" + selectedLanguage + ".qm";
QTranslator* translator = new QTranslator();
if (!translator->load(languageFile))
CAMITK_WARNING("Application", "initResources", "Cannot load file: " + languageFile.toStdString())
else
QCoreApplication::installTranslator(translator);
}
......
......@@ -117,6 +117,7 @@ InterfaceFrame * Frame::getParentFrame() const {
const QVector<InterfaceFrame *> & Frame::getChildrenFrame() const {
return childrenFrame;
}
// ------------------- getDescendantsFrame ----------------------------------
const QVector<InterfaceFrame *> & Frame::getDescendantsFrame() {
......
......@@ -37,151 +37,149 @@
namespace camitk
{
// information for the user, generic information, always here
// information for the user, generic information, always here.
#define CAMITK_INFO(CLASSNAME, METHODNAME, MSG) Log("INFO", CLASSNAME, METHODNAME, MSG)
#define CAMITK_INFO_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if (((B))) { \
CAMITK_INFO(CLASSNAME, METHODNAME, MSG) \
} \
} \
if (((B))) { \
CAMITK_INFO(CLASSNAME, METHODNAME, MSG) \
} \
}
// error generated by the program (unexpectedly)
// important errors use this macro. May result in seg faulting the app. Always enabled.
#define CAMITK_ERROR(CLASSNAME, METHODNAME, MSG) Log("ERROR", CLASSNAME, METHODNAME, MSG)
#define CAMITK_ERROR_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if ((B)) { \
CAMITK_ERROR(CLASSNAME, METHODNAME, MSG) \
} \
} \
// ---------------- CAMITK_LOG_ERROR ----------------
#ifdef CAMITK_LOG_ERROR
#define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG)
#define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG)
#define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG)
#define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG)
#endif // CAMITK_LOG_ERROR
// ---------------- CAMITK_LOG_WARNING ----------------
#ifdef CAMITK_LOG_WARNING
#define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG);
#define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if ((B)) { \
CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
CAMITK_ERROR(CLASSNAME, METHODNAME, MSG) \
} \
} \
}
#define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG)
#define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG)
// ---------------- Warning and Debug default values ----------------
#define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) ;
#define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) ;
// ---------------- CAMITK_LOG_WARNING ----------------
#ifdef CAMITK_LOG_WARNING
// enable log level 1 : warning
#undef CAMITK_WARNING
#define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG)
#define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if ((B)) { \
CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
} \
}
#endif // CAMITK_LOG_WARNING
// ---------------- CAMITK_LOG_DEBUG ----------------
// ---------------- CAMITK_LOG_DEBUG ----------------
#ifdef CAMITK_LOG_DEBUG
#define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG);
#define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if ((B)) { \
CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
} \
} \
#define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) Log("DEBUG", CLASSNAME, METHODNAME, MSG);
#define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if ((B)) { \
CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) \
} \
} \
// enable log level 1 : warning
#undef CAMITK_WARNING
#define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG)
#define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if ((B)) { \
CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
} \
}
// enable log level 2 : debug
#undef CAMITK_DEBUG
#define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) Log("DEBUG", CLASSNAME, METHODNAME, MSG)
#define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG) \
{ \
if ((B)) { \
CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) \
} \
}
#endif // CAMITK_LOG_DEBUG
/// log macro
#define Log(TYPE, CLASSNAME, METHODNAME, MSG) \
{ \
(*camitk::Log::getLogStream()) << (TYPE); \
if (camitk::Log::getShowUser()) { \
(*camitk::Log::getLogStream()) << " " << camitk::Log::getUserInformation(); \
} \
if (camitk::Log::getShowTime()) { \
(*camitk::Log::getLogStream()) << " " << QDateTime::currentDateTime().toString(Qt::ISODate).toStdString(); \
} \
(*camitk::Log::getLogStream()) << " | " << (CLASSNAME) << "::" << (METHODNAME) << std::endl; \
(*camitk::Log::getLogStream()) << MSG << std::endl; \
(*camitk::Log::getLogStream()) << "-----------------------------" << std::endl; \
camitk::Log::getLogStream()->flush(); \
} \
/**
(*camitk::Log::getLogStream()) << (TYPE); \
if (camitk::Log::getShowUser()) { \
(*camitk::Log::getLogStream()) << " " << camitk::Log::getUserInformation(); \
} \
if (camitk::Log::getShowTime()) { \
(*camitk::Log::getLogStream()) << " " << QDateTime::currentDateTime().toString(Qt::ISODate).toStdString(); \
} \
(*camitk::Log::getLogStream()) << " | " << (CLASSNAME) << "::" << (METHODNAME) << std::endl; \
(*camitk::Log::getLogStream()) << MSG << std::endl; \
(*camitk::Log::getLogStream()) << "-----------------------------" << std::endl; \
camitk::Log::getLogStream()->flush(); \
}
/**
* @ingroup group_sdk_libraries_core_utils
*
*
* @brief
* This class is a log utility. It helps you to log messages anywhere in your code for different
* levels: CAMITK_INFO, CAMITK_ERROR, CAMITK_WARNING and CAMITK_DEBUG.
* Log macro CAMITK_INFO is always enabled.
*
* Log macros CAMITK_INFO and CAMITK_ERROR are always enabled.
* Log macros CAMITK_WARNING and CAMITK_DEBUG are two optional macro, disabled by default.
*
* Logs are defined by macros, which can be switch off at compile time.
* The log behaviour is defined directly by the value of 2 cmake variables: CAMITK_LOG_FILE and CAMITK_LOG_LEVEL.
*
* For CAMITK_LOG_LEVEL consider the following table:
* <table>
* <tr><td>CAMITK_LOG_LEVEL</td><td>Enabled macros</td></tr>
* <tr><td>0</td><td>CAMITK_ERROR</td></tr>
* <tr><td>1</td><td>CAMITK_ERROR / CAMITK_WARNING </td></tr>
* <tr><td>2</td><td>CAMITK_ERROR / CAMITK_WARNING / CAMITK_DEBUG </td> </tr>
* </table>
*
*
* For CAMITK_LOG_FILE:
* You can choose to save logs into "log.txt" file in the executable directory.
* You can choose to save logs into "log.txt" file in the executable directory.
* If this file does not exist, it is automatically created when the application is executed.
* This option is configured by cmake variable CAMITK_LOG_FILE.
*
* This option is configured by cmake variable CAMITK_LOG_FILE.
*
* How to use the macro in the source:
* - Be sure that the file Log.h is correctly include in the working file.
* - insert the MACRO that you want to use, it will be enabled depending of the log level
* defined at compile time.
*
*
* Example :
* CAMITK_INFO("class used", "method used", "message" << std::endl);
*
*
* CAMITK_INFO("class used", "method used", "message" << std::endl);
*
*
*/
class CAMITK_API Log {
public :
/// show date/time information in logs
static void showTime(bool);
/// get show time information
static bool getShowTime();
/// show or not the user information
static void showUser(bool);
/// get the status of show user information
static bool getShowUser();
/// Method used to open the log File
static void openLogFile();
/// Method used to close the log File
static void closeLogFile();
/// get the logFile (singleton) @return the currently opened ofstream or cout if the log file has not yet be opened
static std::ostream * getLogStream();
/// get the user information
static std::string getUserInformation();
private :
/// the log file
static std::ofstream * logFilePtr;
/// show time info
static bool showTimeInfo;
/// show user info
static bool showUserInfo;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment