diff --git a/src/mumble/CMakeLists.txt b/src/mumble/CMakeLists.txt index 1ee09a5cd5..64a7b2a3c4 100644 --- a/src/mumble/CMakeLists.txt +++ b/src/mumble/CMakeLists.txt @@ -170,6 +170,7 @@ set(MUMBLE_SOURCES "Log.cpp" "Log.h" "Log.ui" + "Logger.cpp" "LookConfig.cpp" "LookConfig.h" "LookConfig.ui" diff --git a/src/mumble/DeveloperConsole.cpp b/src/mumble/DeveloperConsole.cpp index 47e08a2bea..ea1054ce46 100644 --- a/src/mumble/DeveloperConsole.cpp +++ b/src/mumble/DeveloperConsole.cpp @@ -5,43 +5,20 @@ #include "DeveloperConsole.h" -#include "LogEmitter.h" -#include "Global.h" - +#include #include -DeveloperConsole::DeveloperConsole(QObject *parent) : QObject(parent) { - connect(Global::get().le.data(), SIGNAL(newLogEntry(const QString &)), this, SLOT(addLogMessage(const QString &))); +DeveloperConsole::DeveloperConsole(QTextBrowser *textBox, QObject *parent) + : QObject(parent), m_window(std::make_unique< QMainWindow >()) { + m_window->resize(675, 300); + m_window->setCentralWidget(textBox); + m_window->setWindowTitle(tr("Developer Console")); } DeveloperConsole::~DeveloperConsole() { - QMainWindow *mw = m_window.data(); - delete mw; } void DeveloperConsole::show() { - if (m_window.isNull()) { - QMainWindow *mw = new QMainWindow(); - mw->setAttribute(Qt::WA_DeleteOnClose); - QTextBrowser *tb = new QTextBrowser(); - mw->resize(675, 300); - mw->setCentralWidget(tb); - mw->setWindowTitle(tr("Developer Console")); - - connect(Global::get().le.data(), SIGNAL(newLogEntry(const QString &)), tb, SLOT(append(const QString &))); - - foreach (const QString &m, m_logEntries) - tb->append(m); - m_window = QPointer< QMainWindow >(mw); - } - - m_window.data()->show(); - m_window.data()->activateWindow(); -} - -void DeveloperConsole::addLogMessage(const QString &msg) { - if (m_logEntries.count() >= 1000) - m_logEntries.removeFirst(); - - m_logEntries.append(msg); + m_window->show(); + m_window->activateWindow(); } diff --git a/src/mumble/DeveloperConsole.h b/src/mumble/DeveloperConsole.h index e24fa94f40..9d3cde69af 100644 --- a/src/mumble/DeveloperConsole.h +++ b/src/mumble/DeveloperConsole.h @@ -6,26 +6,26 @@ #ifndef MUMBLE_MUMBLE_DEVELOPERCONSOLE_H_ #define MUMBLE_MUMBLE_DEVELOPERCONSOLE_H_ +#include + #include -#include -#include -#include + +class QMainWindow; +class QTextBrowser; class DeveloperConsole : public QObject { private: Q_OBJECT Q_DISABLE_COPY(DeveloperConsole) -protected: - QPointer< QMainWindow > m_window; - QStringList m_logEntries; -public slots: - void addLogMessage(const QString &); - public: - DeveloperConsole(QObject *parent = nullptr); + DeveloperConsole(QTextBrowser *textBox, QObject *parent = nullptr); ~DeveloperConsole(); + void show(); + +private: + std::unique_ptr< QMainWindow > m_window; }; #endif diff --git a/src/mumble/Global.h b/src/mumble/Global.h index 54bc3d82ac..255946bee3 100644 --- a/src/mumble/Global.h +++ b/src/mumble/Global.h @@ -31,7 +31,6 @@ class Overlay; class LCD; class Zeroconf; class OverlayClient; -class LogEmitter; class DeveloperConsole; class TalkingUI; class TrayIcon; @@ -69,7 +68,6 @@ struct Global Q_DECL_FINAL { LCD *lcd; Zeroconf *zeroconf; QNetworkAccessManager *nam; - QSharedPointer< LogEmitter > le; DeveloperConsole *c; TalkingUI *talkingUI; int iPushToTalk; diff --git a/src/mumble/main.cpp b/src/mumble/main.cpp index aabac41dc1..d999e3fe76 100644 --- a/src/mumble/main.cpp +++ b/src/mumble/main.cpp @@ -17,7 +17,7 @@ #endif #include "LCD.h" #include "Log.h" -#include "LogEmitter.h" +#include "Logger.h" #include "MainWindow.h" #include "ServerHandler.h" #ifdef USE_ZEROCONF @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -79,6 +80,8 @@ void throw_exception(std::exception const &) { } // namespace boost #endif +using namespace mumble; + extern void os_init(); extern char *os_lang; @@ -191,8 +194,9 @@ int main(int argc, char **argv) { Global::g_global_struct = new Global(); } - Global::get().le = QSharedPointer< LogEmitter >(new LogEmitter()); - Global::get().c = new DeveloperConsole(); + auto logBox = new QTextBrowser(); + log::init(logBox); + Global::get().c = new DeveloperConsole(logBox); os_init(); @@ -842,6 +846,8 @@ int main(int argc, char **argv) { } } + log::prepareToExit(); + QCoreApplication::processEvents(); // Only start deleting items once all pending events have been processed (Audio::stop deletes the audio @@ -880,7 +886,6 @@ int main(int argc, char **argv) { #endif delete Global::get().c; - Global::get().le.clear(); DeferInit::run_destroyers(); diff --git a/src/mumble/os_macx.mm b/src/mumble/os_macx.mm index 239991c7c0..ef5de8a5db 100644 --- a/src/mumble/os_macx.mm +++ b/src/mumble/os_macx.mm @@ -3,7 +3,6 @@ // that can be found in the LICENSE file at the root of the // Mumble source tree or at . -#include "LogEmitter.h" #include "MainWindow.h" #ifdef USE_OVERLAY # include "Overlay.h" @@ -14,9 +13,6 @@ #include char *os_lang = nullptr; -static FILE *fConsole = nullptr; - -static QSharedPointer le; #define PATH_MAX 1024 static char crashhandler_fn[PATH_MAX]; @@ -24,44 +20,6 @@ static void crashhandler_signals_restore(); static void crashhandler_handle_crash(); -static void mumbleMessageOutputQString(QtMsgType type, const QString &msg) { - char c; - - switch (type) { - case QtDebugMsg: - c='D'; - break; - case QtWarningMsg: - c='W'; - break; - case QtFatalMsg: - c='F'; - break; - default: - c='X'; - } - - QString date = QDateTime::currentDateTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss.zzz")); - QString fmsg = QString::fromLatin1("<%1>%2 %3").arg(c).arg(date).arg(msg); - fprintf(stderr, "%s\n", qPrintable(fmsg)); - fprintf(fConsole, "%s\n", qPrintable(fmsg)); - fflush(fConsole); - - le->addLogEntry(fmsg); - - if (type == QtFatalMsg) { - CFStringRef csMsg = CFStringCreateWithFormat(kCFAllocatorDefault, nullptr, CFSTR("%s\n\nThe error has been logged. Please submit your log file to the Mumble project if the problem persists."), qPrintable(msg)); - CFUserNotificationDisplayAlert(0, 0, nullptr, nullptr, nullptr, CFSTR("Mumble has encountered a fatal error"), csMsg, CFSTR("OK"), nullptr, nullptr, nullptr); - CFRelease(csMsg); - exit(0); - } -} - -static void mumbleMessageOutputWithContext(QtMsgType type, const QMessageLogContext &ctx, const QString &msg) { - Q_UNUSED(ctx); - mumbleMessageOutputQString(type, msg); -} - void query_language() { CFPropertyListRef cfaLangs; CFStringRef cfsLang; @@ -129,28 +87,6 @@ static void crashhandler_handle_crash() { void os_init() { crashhandler_init(); - const char *home = getenv("HOME"); - const char *logpath = "/Library/Logs/Mumble.log"; - - // Make a copy of the global LogEmitter, such that - // os_macx.mm doesn't have to consider the deletion - // of the Global object and its LogEmitter object. - le = Global::get().le; - - if (home) { - size_t len = strlen(home) + strlen(logpath) + 1; - static std::vector buffer; - buffer.resize(len); - char *buff = buffer.data(); - memset(buff, 0, len); - strcat(buff, home); - strcat(buff, logpath); - fConsole = fopen(buff, "a+"); - if (fConsole) { - qInstallMessageHandler(mumbleMessageOutputWithContext); - } - } - /* Query for language setting. OS X's LANG environment variable is determined from the region selected * in SystemPrefs -> International -> Formats -> Region instead of the system language. We override this * by always using the system language, to get rid of all sorts of nasty language inconsistencies. */ diff --git a/src/mumble/os_unix.cpp b/src/mumble/os_unix.cpp index 4695f1a7fd..108e49b0b8 100644 --- a/src/mumble/os_unix.cpp +++ b/src/mumble/os_unix.cpp @@ -2,49 +2,6 @@ // Use of this source code is governed by a BSD-style license // that can be found in the LICENSE file at the root of the // Mumble source tree or at . -#include "LogEmitter.h" -#include "Global.h" - -static QSharedPointer< LogEmitter > le; - -static void mumbleMessageOutputQString(QtMsgType type, const QString &msg) { - char c; - - switch (type) { - case QtDebugMsg: - c = 'D'; - break; - case QtWarningMsg: - c = 'W'; - break; - case QtFatalMsg: - c = 'F'; - break; - default: - c = 'X'; - } - - QString date = QDateTime::currentDateTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss.zzz")); - QString fmsg = QString::fromLatin1("<%1>%2 %3").arg(c).arg(date).arg(msg); - fprintf(stderr, "%s\n", qPrintable(fmsg)); - - le->addLogEntry(fmsg); - - if (type == QtFatalMsg) { - exit(1); - } -} - -static void mumbleMessageOutputWithContext(QtMsgType type, const QMessageLogContext &ctx, const QString &msg) { - Q_UNUSED(ctx); - mumbleMessageOutputQString(type, msg); -} void os_init() { - // Make a copy of the global LogEmitter, such that - // os_unix.cpp doesn't have to consider the deletion - // of the Global object and its LogEmitter object. - le = Global::get().le; - - qInstallMessageHandler(mumbleMessageOutputWithContext); } diff --git a/src/mumble/os_win.cpp b/src/mumble/os_win.cpp index 625342a8de..1278cc2880 100644 --- a/src/mumble/os_win.cpp +++ b/src/mumble/os_win.cpp @@ -3,7 +3,6 @@ // that can be found in the LICENSE file at the root of the // Mumble source tree or at . -#include "LogEmitter.h" #include "MumbleApplication.h" #ifdef _MSC_VER @@ -45,13 +44,10 @@ void mumble_speex_init(); #define DUMP_BUFFER_SIZE 1024 static wchar_t wcCrashDumpPath[DUMP_BUFFER_SIZE]; -static FILE *fConsole = nullptr; static wchar_t wcComment[DUMP_BUFFER_SIZE] = L""; static MINIDUMP_USER_STREAM musComment; -static QSharedPointer< LogEmitter > le; - static int cpuinfo[4]; bool bIsWin7 = false; @@ -59,38 +55,6 @@ bool bIsVistaSP1 = false; HWND mumble_mw_hwnd = 0; -static void mumbleMessageOutputQString(QtMsgType type, const QString &msg) { - char c; - switch (type) { - case QtDebugMsg: - c = 'D'; - break; - case QtWarningMsg: - c = 'W'; - break; - case QtFatalMsg: - c = 'F'; - break; - default: - c = 'X'; - } - QString date = QDateTime::currentDateTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss.zzz")); - QString fmsg = QString::fromLatin1("<%1>%2 %3").arg(c).arg(date).arg(msg); - fprintf(fConsole, "%s\n", qPrintable(fmsg)); - fflush(fConsole); - OutputDebugStringA(qPrintable(fmsg)); - le->addLogEntry(fmsg); - if (type == QtFatalMsg) { - ::MessageBoxA(nullptr, qPrintable(msg), "Mumble", MB_OK | MB_ICONERROR); - exit(0); - } -} - -static void mumbleMessageOutputWithContext(QtMsgType type, const QMessageLogContext &ctx, const QString &msg) { - Q_UNUSED(ctx); - mumbleMessageOutputQString(type, msg); -} - static LONG WINAPI MumbleUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo) { MINIDUMP_EXCEPTION_INFORMATION i; i.ThreadId = GetCurrentThreadId(); @@ -255,19 +219,7 @@ void os_init() { enableCrashOnCrashes(); mumble_speex_init(); - // Make a copy of the global LogEmitter, such that - // os_win.cpp doesn't have to consider the deletion - // of the Global object and its LogEmitter object. - le = Global::get().le; - #ifdef QT_NO_DEBUG - QString console = Global::get().qdBasePath.filePath(QLatin1String("Console.txt")); - fConsole = _wfsopen(console.toStdWString().c_str(), L"a+", _SH_DENYWR); - - if (fConsole) { - qInstallMessageHandler(mumbleMessageOutputWithContext); - } - QString hash; QFile f(qApp->applicationFilePath()); if (!f.open(QIODevice::ReadOnly)) {