From: konrad Date: Sat, 5 Apr 2008 13:02:12 +0000 (+0000) Subject: add debug logging X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=fb4a43da04b9e9d6dac4553d9a7753628b224f11;p=web%2Fkonrad%2Fsmoke.git add debug logging git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@154 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/debug.cpp b/src/debug.cpp new file mode 100644 index 0000000..102b672 --- /dev/null +++ b/src/debug.cpp @@ -0,0 +1,47 @@ +// +// C++ Implementation: debug +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "debug.h" +#include "main.h" + +#include +#include +#include +#include + +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 index 0000000..ef0295e --- /dev/null +++ b/src/debug.h @@ -0,0 +1,18 @@ +// +// C++ Interface: debug +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_DEBUG_H +#define MAGICSMOKE_DEBUG_H + +void initDebug(); + +#endif diff --git a/src/main.cpp b/src/main.cpp index 62a63ed..bc95b08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; diff --git a/src/main.h b/src/main.h index de76588..fbbdcd9 100644 --- a/src/main.h +++ b/src/main.h @@ -13,6 +13,8 @@ #ifndef MAGICSMOKE_MAIN_H #define MAGICSMOKE_MAIN_H +#include + QString choseLanguage(bool warn=true); extern QString dataDir; diff --git a/src/smoke.pro b/src/smoke.pro index 6427df9..c66368c 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -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 \