Degugging format, better.

This commit is contained in:
Martin Rotter 2015-03-22 10:25:13 +01:00
parent c11a104959
commit de1d63b12e
6 changed files with 44 additions and 62 deletions

View file

@ -108,6 +108,9 @@
#define APP_CFG_PATH "data/config" #define APP_CFG_PATH "data/config"
#define APP_CFG_FILE "config.ini" #define APP_CFG_FILE "config.ini"
#define APP_LOG_PATH "data/log"
#define APP_LOG_FILE "log.txt"
#if defined(Q_OS_OSX) #if defined(Q_OS_OSX)
#define APP_PREFIX "@CMAKE_INSTALL_PREFIX@/@APP_LOW_NAME@.app/Contents/Resources" #define APP_PREFIX "@CMAKE_INSTALL_PREFIX@/@APP_LOW_NAME@.app/Contents/Resources"
#else #else

1
src/gui/systemtrayicon.h Normal file → Executable file
View file

@ -22,7 +22,6 @@
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include <QPointer>
#include <QPixmap> #include <QPixmap>
#include <QMenu> #include <QMenu>

View file

@ -24,49 +24,50 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#ifndef QT_NO_DEBUG_OUTPUT
#if QT_VERSION >= 0x050000
#define DEBUG_OUTPUT_WORKER(type_string, file, line, message) \
fprintf(stderr, "[%s] %s (%s:%d): %s\n", \
APP_LOW_NAME, \
type_string, \
file, \
line, \
qPrintable(message));
#else
#define DEBUG_OUTPUT_WORKER(type_string, message) \
fprintf(stderr, "[%s] %s: %s\n", \
APP_LOW_NAME, \
type_string, \
message);
#endif
#endif
Debugging::Debugging() {
}
#if QT_VERSION >= 0x050000 void Debugging::performLog(const char *message, QtMsgType type, const char *file, const char *function, int line) {
void Debugging::debugHandler(QtMsgType type, const char *type_string = typeToString(type);
const QMessageLogContext &placement,
const QString &message) {
#ifndef QT_NO_DEBUG_OUTPUT
const char *file = qPrintable(QString(placement.file).section(QDir::separator(),
-1));
// Write to console.
if (file == 0 || function == 0 || line < 0) {
fprintf(stderr, "[%s] %s: %s\n", APP_LOW_NAME, type_string, message);
}
else {
fprintf(stderr, "[%s] %s\n Type: %s\n File: %s (line %d)\n Function: %s\n\n",
APP_LOW_NAME, message, type_string, file, line, function);
}
// TODO: Write to file here.
if (type == QtFatalMsg) {
qApp->exit(EXIT_FAILURE);
}
}
const char *Debugging::typeToString(QtMsgType type) {
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:
DEBUG_OUTPUT_WORKER("INFO", file, placement.line, message); return "DEBUG";
break;
case QtWarningMsg: case QtWarningMsg:
DEBUG_OUTPUT_WORKER("WARNING", file, placement.line, message); return "WARNING";
break;
case QtCriticalMsg: case QtCriticalMsg:
DEBUG_OUTPUT_WORKER("CRITICAL", file, placement.line, message); return "CRITICAL";
break;
case QtFatalMsg: case QtFatalMsg:
DEBUG_OUTPUT_WORKER("FATAL", file, placement.line, message);
qApp->exit(EXIT_FAILURE);
default: default:
break; return "FATAL (terminating application)";
} }
}
#if QT_VERSION >= 0x050000
void Debugging::debugHandler(QtMsgType type, const QMessageLogContext &placement, const QString &message) {
#ifndef QT_NO_DEBUG_OUTPUT
performLog(qPrintable(message), type, placement.file, placement.function, placement.line);
#else #else
Q_UNUSED(type) Q_UNUSED(type)
Q_UNUSED(placement) Q_UNUSED(placement)
@ -76,28 +77,10 @@ void Debugging::debugHandler(QtMsgType type,
#else #else
void Debugging::debugHandler(QtMsgType type, const char *message) { void Debugging::debugHandler(QtMsgType type, const char *message) {
#ifndef QT_NO_DEBUG_OUTPUT #ifndef QT_NO_DEBUG_OUTPUT
switch (type) { performLog(message, type);
case QtDebugMsg:
DEBUG_OUTPUT_WORKER("INFO", message);
break;
case QtWarningMsg:
DEBUG_OUTPUT_WORKER("WARNING", message);
break;
case QtCriticalMsg:
DEBUG_OUTPUT_WORKER("CRITICAL", message);
break;
case QtFatalMsg:
DEBUG_OUTPUT_WORKER("FATAL", message);
qApp->exit(EXIT_FAILURE);
default:
break;
}
#else #else
Q_UNUSED(type) Q_UNUSED(type)
Q_UNUSED(message) Q_UNUSED(message)
#endif #endif
} }
#endif #endif
Debugging::Debugging() {
}

10
src/miscellaneous/debugging.h Normal file → Executable file
View file

@ -26,14 +26,14 @@ class Debugging {
// Specifies format of output console messages. // Specifies format of output console messages.
// NOTE: QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!! // NOTE: QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!!
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
static void debugHandler(QtMsgType type, static void debugHandler(QtMsgType type, const QMessageLogContext &placement, const QString &message);
const QMessageLogContext &placement,
const QString &message);
#else #else
static void debugHandler(QtMsgType type, static void debugHandler(QtMsgType type, const char *message);
const char *message);
#endif #endif
static void performLog(const char *message, QtMsgType type, const char *file = 0, const char *function = 0, int line = -1);
static const char *typeToString(QtMsgType type);
private: private:
// Constructor. // Constructor.
explicit Debugging(); explicit Debugging();

View file

@ -24,8 +24,6 @@
#include "miscellaneous/settingsproperties.h" #include "miscellaneous/settingsproperties.h"
#include <QPointer>
#include <QNetworkProxy> #include <QNetworkProxy>
#define KEY extern const char* #define KEY extern const char*

1
src/miscellaneous/systemfactory.h Normal file → Executable file
View file

@ -20,7 +20,6 @@
#include <QObject> #include <QObject>
#include <QPointer>
#include <QMetaType> #include <QMetaType>
#include <QHash> #include <QHash>
#include <QPair> #include <QPair>