Degugging format, better.
This commit is contained in:
parent
c11a104959
commit
de1d63b12e
|
@ -108,6 +108,9 @@
|
|||
#define APP_CFG_PATH "data/config"
|
||||
#define APP_CFG_FILE "config.ini"
|
||||
|
||||
#define APP_LOG_PATH "data/log"
|
||||
#define APP_LOG_FILE "log.txt"
|
||||
|
||||
#if defined(Q_OS_OSX)
|
||||
#define APP_PREFIX "@CMAKE_INSTALL_PREFIX@/@APP_LOW_NAME@.app/Contents/Resources"
|
||||
#else
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include "definitions/definitions.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QPixmap>
|
||||
#include <QMenu>
|
||||
|
||||
|
|
|
@ -24,49 +24,50 @@
|
|||
#include <cstdio>
|
||||
#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::debugHandler(QtMsgType type,
|
||||
const QMessageLogContext &placement,
|
||||
const QString &message) {
|
||||
#ifndef QT_NO_DEBUG_OUTPUT
|
||||
const char *file = qPrintable(QString(placement.file).section(QDir::separator(),
|
||||
-1));
|
||||
void Debugging::performLog(const char *message, QtMsgType type, const char *file, const char *function, int line) {
|
||||
const char *type_string = typeToString(type);
|
||||
|
||||
// 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) {
|
||||
case QtDebugMsg:
|
||||
DEBUG_OUTPUT_WORKER("INFO", file, placement.line, message);
|
||||
break;
|
||||
return "DEBUG";
|
||||
|
||||
case QtWarningMsg:
|
||||
DEBUG_OUTPUT_WORKER("WARNING", file, placement.line, message);
|
||||
break;
|
||||
return "WARNING";
|
||||
|
||||
case QtCriticalMsg:
|
||||
DEBUG_OUTPUT_WORKER("CRITICAL", file, placement.line, message);
|
||||
break;
|
||||
return "CRITICAL";
|
||||
|
||||
case QtFatalMsg:
|
||||
DEBUG_OUTPUT_WORKER("FATAL", file, placement.line, message);
|
||||
qApp->exit(EXIT_FAILURE);
|
||||
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
|
||||
Q_UNUSED(type)
|
||||
Q_UNUSED(placement)
|
||||
|
@ -75,29 +76,11 @@ void Debugging::debugHandler(QtMsgType type,
|
|||
}
|
||||
#else
|
||||
void Debugging::debugHandler(QtMsgType type, const char *message) {
|
||||
#ifndef QT_NO_DEBUG_OUTPUT
|
||||
switch (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;
|
||||
}
|
||||
#ifndef QT_NO_DEBUG_OUTPUT
|
||||
performLog(message, type);
|
||||
#else
|
||||
Q_UNUSED(type)
|
||||
Q_UNUSED(message)
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
Debugging::Debugging() {
|
||||
}
|
||||
|
|
|
@ -26,14 +26,14 @@ class Debugging {
|
|||
// Specifies format of output console messages.
|
||||
// NOTE: QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!!
|
||||
#if QT_VERSION >= 0x050000
|
||||
static void debugHandler(QtMsgType type,
|
||||
const QMessageLogContext &placement,
|
||||
const QString &message);
|
||||
static void debugHandler(QtMsgType type, const QMessageLogContext &placement, const QString &message);
|
||||
#else
|
||||
static void debugHandler(QtMsgType type,
|
||||
const char *message);
|
||||
static void debugHandler(QtMsgType type, const char *message);
|
||||
#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:
|
||||
// Constructor.
|
||||
explicit Debugging();
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
#include "miscellaneous/settingsproperties.h"
|
||||
|
||||
|
||||
#include <QPointer>
|
||||
#include <QNetworkProxy>
|
||||
|
||||
#define KEY extern const char*
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include <QPointer>
|
||||
#include <QMetaType>
|
||||
#include <QHash>
|
||||
#include <QPair>
|
||||
|
|
Loading…
Reference in New Issue