add debug logging
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 5 Apr 2008 13:02:12 +0000 (13:02 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 5 Apr 2008 13:02:12 +0000 (13:02 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@154 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/debug.cpp [new file with mode: 0644]
src/debug.h [new file with mode: 0644]
src/main.cpp
src/main.h
src/smoke.pro

diff --git a/src/debug.cpp b/src/debug.cpp
new file mode 100644 (file)
index 0000000..102b672
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// C++ Implementation: debug
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "debug.h"
+#include "main.h"
+
+#include <QCoreApplication>
+#include <QDateTime>
+#include <QDir>
+#include <QFile>
+
+static QFile*mylogFile=0;
+
+static void mymsghandler(QtMsgType, const char *msg)
+{
+        if(mylogFile){
+                mylogFile->write(msg,strlen(msg));
+                mylogFile->write("\n",1);
+                mylogFile->flush();
+        }
+#ifdef Q_OS_UNIX
+        fprintf(stderr,"%s\n",msg);
+#endif
+}
+
+void initDebug()
+{
+       QDir(dataDir).mkdir("debuglog");
+        mylogFile=new QFile(dataDir+"/debuglog/log-"+QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss.zzz")+".txt");
+        if(mylogFile->open(QIODevice::WriteOnly|QIODevice::Append|QIODevice::Text)){
+                qInstallMsgHandler(mymsghandler);
+        }else{
+                delete mylogFile;
+                mylogFile=0;
+                qDebug("Failed to install debuglog.");
+        }
+
+}
\ No newline at end of file
diff --git a/src/debug.h b/src/debug.h
new file mode 100644 (file)
index 0000000..ef0295e
--- /dev/null
@@ -0,0 +1,18 @@
+//
+// C++ Interface: debug
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_DEBUG_H
+#define MAGICSMOKE_DEBUG_H
+
+void initDebug();
+
+#endif
index 62a63ed..bc95b08 100644 (file)
@@ -24,6 +24,7 @@
 #include "mainwindow.h"
 #include "hmac.h"
 #include "main.h"
+#include "debug.h"
 
 QString choseLanguage(bool warn)
 {
@@ -107,6 +108,9 @@ int main(int argc,char**argv)
        //try to find data dir
        initDataDir();
        
+       //initialize log file
+       initDebug();
+       
        //check/generate host settings
        if(!QSettings().contains("hostkey")){
                MKeyGen mkg;
index de76588..fbbdcd9 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef MAGICSMOKE_MAIN_H
 #define MAGICSMOKE_MAIN_H
 
+#include <QString>
+
 QString choseLanguage(bool warn=true);
 
 extern QString dataDir;
index 6427df9..c66368c 100644 (file)
@@ -23,6 +23,7 @@ RCC_DIR = .ctmp
 
 SOURCES = \
        main.cpp \
+       debug.cpp \
        keygen.cpp \
        mainwindow.cpp \
        hmac.cpp \
@@ -46,6 +47,7 @@ SOURCES = \
 #some PHP files are listed below to scan them for translatable items:
 HEADERS = \
        keygen.h \
+       debug.h \
        mainwindow.h \
        hmac.h \
        webrequest.h \