瀏覽代碼

Add a NO_MSG_HANDLER cmake option

This allows QDebug to output to stdout or OutputDebugString
to ease development.
Jocelyn Turcotte 11 年之前
父節點
當前提交
2ddaf5a06a
共有 2 個文件被更改,包括 11 次插入0 次删除
  1. 5 0
      CMakeLists.txt
  2. 6 0
      src/libsync/logger.cpp

+ 5 - 0
CMakeLists.txt

@@ -102,6 +102,11 @@ if(TOKEN_AUTH_ONLY)
    add_definitions(-DTOKEN_AUTH_ONLY=1)
    add_definitions(-DTOKEN_AUTH_ONLY=1)
 endif()
 endif()
 
 
+option(NO_MSG_HANDLER "Don't redirect QDebug outputs to the log window/file" OFF)
+if(NO_MSG_HANDLER)
+   add_definitions(-DNO_MSG_HANDLER=1)
+endif()
+
 # this option creates only libocsync and libowncloudsync
 # this option creates only libocsync and libowncloudsync
 option(BUILD_LIBRARIES_ONLY "BUILD_LIBRARIES_ONLY" OFF)
 option(BUILD_LIBRARIES_ONLY "BUILD_LIBRARIES_ONLY" OFF)
 
 

+ 6 - 0
src/libsync/logger.cpp

@@ -53,14 +53,20 @@ Logger *Logger::instance()
 Logger::Logger( QObject* parent) : QObject(parent),
 Logger::Logger( QObject* parent) : QObject(parent),
   _showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
   _showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
 {
 {
+#ifndef NO_MSG_HANDLER
 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
     qSetMessagePattern("%{time MM-dd hh:mm:ss:zzz} %{threadid} %{function}: %{message}");
     qSetMessagePattern("%{time MM-dd hh:mm:ss:zzz} %{threadid} %{function}: %{message}");
 #endif
 #endif
     qInstallMessageHandler(mirallLogCatcher);
     qInstallMessageHandler(mirallLogCatcher);
+#else
+    Q_UNUSED(mirallLogCatcher)
+#endif
 }
 }
 
 
 Logger::~Logger() {
 Logger::~Logger() {
+#ifndef NO_MSG_HANDLER
     qInstallMessageHandler(0);
     qInstallMessageHandler(0);
+#endif
 }
 }