Kaynağa Gözat

Add a NO_MSG_HANDLER cmake option

This allows QDebug to output to stdout or OutputDebugString
to ease development.
Jocelyn Turcotte 11 yıl önce
ebeveyn
işleme
2ddaf5a06a
2 değiştirilmiş dosya ile 11 ekleme ve 0 silme
  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)
 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
 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),
   _showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
 {
+#ifndef NO_MSG_HANDLER
 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
     qSetMessagePattern("%{time MM-dd hh:mm:ss:zzz} %{threadid} %{function}: %{message}");
 #endif
     qInstallMessageHandler(mirallLogCatcher);
+#else
+    Q_UNUSED(mirallLogCatcher)
+#endif
 }
 
 Logger::~Logger() {
+#ifndef NO_MSG_HANDLER
     qInstallMessageHandler(0);
+#endif
 }