changeset 709:718e2e543cd1

Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@978 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Tue, 14 Jul 2009 22:27:15 +0000
parents 80144dc972a1
children e5f77ab5e2fa
files src/UiGuiLogger.cpp src/UiGuiLogger.h src/main.cpp
diffstat 3 files changed, 29 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/UiGuiLogger.cpp	Tue Jul 14 21:51:48 2009 +0000
+++ b/src/UiGuiLogger.cpp	Tue Jul 14 22:27:15 2009 +0000
@@ -33,24 +33,35 @@
 /*!
     \brief Returns the only existing instance of UiGuiLogger. If the instance doesn't exist, it will be created.
  */
-UiGuiLogger* UiGuiLogger::getInstance() {
+UiGuiLogger* UiGuiLogger::getInstance(int verboseLevel) {
     if ( instance == NULL )
-        instance = new UiGuiLogger();
+        instance = new UiGuiLogger(verboseLevel);
 
     return instance;
 }
 
+/*!
+    \brief Returns the only existing instance of UiGuiLogger. If the instance doesn't exist, it will be created.
+ */
+UiGuiLogger* UiGuiLogger::getInstance() {
+#ifdef _DEBUG
+    return UiGuiLogger::getInstance(QtDebugMsg);
+#else
+    return UiGuiLogger::getInstance(QtWarningMsg);
+#endif
+}
+
 
 /*!
     \brief Initializes the dialog and sets the path to the log file in the systems temporary directory.
     Sets the default verbose level to warning level.
  */
-UiGuiLogger::UiGuiLogger() : QDialog() {
+UiGuiLogger::UiGuiLogger(int verboseLevel) : QDialog() {
     setupUi(this);
 #ifdef _DEBUG
-    verboseLevel = QtDebugMsg;
+    this->verboseLevel = QtDebugMsg;
 #else
-    verboseLevel = QtWarningMsg;
+    this->verboseLevel = QtMsgType(verboseLevel);
 #endif
 
     logFileInitState = NOTINITIALZED;
@@ -70,7 +81,7 @@
  */
 void UiGuiLogger::messageHandler(QtMsgType type, const char *msg) {
     if ( instance == NULL )
-        instance = new UiGuiLogger();
+        instance = UiGuiLogger::getInstance();
 
     // Only log messages that have a higher or equal priority than set with the verbose level.
     if ( type < instance->verboseLevel )
--- a/src/UiGuiLogger.h	Tue Jul 14 21:51:48 2009 +0000
+++ b/src/UiGuiLogger.h	Tue Jul 14 22:27:15 2009 +0000
@@ -45,6 +45,7 @@
     Q_OBJECT
 
 public:
+    static UiGuiLogger* getInstance(int verboseLevel);
     static UiGuiLogger* getInstance();
     static void messageHandler(QtMsgType type, const char *msg);
     static void deleteInstance();
@@ -52,7 +53,7 @@
 
 private:
     enum LogFileInitState { NOTINITIALZED, INITIALIZING, INITIALZED } logFileInitState;
-    UiGuiLogger();
+    UiGuiLogger(int verboseLevel);
     void writeToLogFile(const QString message);
 
     static UiGuiLogger* instance;
--- a/src/main.cpp	Tue Jul 14 21:51:48 2009 +0000
+++ b/src/main.cpp	Tue Jul 14 22:27:15 2009 +0000
@@ -48,16 +48,6 @@
     MainWindow *mainWindow = NULL;
     IndentHandler *indentHandler = NULL;
 
-    // Init and install the logger function.
-    // Setting UTF-8 as default 8-Bit encoding to ensure that qDebug does no false string conversion.
-    QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF-8") );
-    QTextCodec::setCodecForLocale( QTextCodec::codecForName("UTF-8") );
-    // Force creation of an UiGuiLogger instance here, to avoid recursion with SettingsPaths init function.
-    UiGuiLogger::getInstance();
-    qInstallMsgHandler( UiGuiLogger::messageHandler );
-    UiGuiLogger::messageHandler( UiGuiInfoMsg, QString("Starting UiGUI Version %1 %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii() );
-    UiGuiLogger::messageHandler( UiGuiInfoMsg, QString("Running on %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii() );
-
     // Parse command line arguments. First parameter is the executable itself.
     for ( int i = 1; i < argc; i++ ) {
         QString currentArg = argv[i];
@@ -111,12 +101,19 @@
         }
     }
 
-    // Set the verbose level for the logger. If not in debug, use the value given via command line or default to 1.
+    // Init and install the logger function.
+    // Setting UTF-8 as default 8-Bit encoding to ensure that qDebug does no false string conversion.
+    QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF-8") );
+    QTextCodec::setCodecForLocale( QTextCodec::codecForName("UTF-8") );
+    // Force creation of an UiGuiLogger instance here, to avoid recursion with SettingsPaths init function.
 #ifdef _DEBUG
-    UiGuiLogger::getInstance()->setVerboseLevel(0);
+    UiGuiLogger::getInstance(0);
 #else
-    UiGuiLogger::getInstance()->setVerboseLevel( verboseLevel );
+    UiGuiLogger::getInstance(verboseLevel);
 #endif
+    qInstallMsgHandler( UiGuiLogger::messageHandler );
+    UiGuiLogger::messageHandler( UiGuiInfoMsg, QString("Starting UiGUI Version %1 %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii() );
+    UiGuiLogger::messageHandler( UiGuiInfoMsg, QString("Running on %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii() );
 
     // Set default values for all by UniversalIndentGUI used settings objects.
     QCoreApplication::setOrganizationName("UniversalIndentGUI");