mirror of
https://github.com/mumble-voip/mumble.git
synced 2025-10-26 11:19:16 +00:00
REFAC(client): Switch to new logging system
This commit is contained in:
parent
b8357e8a25
commit
c7cba4133f
@ -170,6 +170,7 @@ set(MUMBLE_SOURCES
|
||||
"Log.cpp"
|
||||
"Log.h"
|
||||
"Log.ui"
|
||||
"Logger.cpp"
|
||||
"LookConfig.cpp"
|
||||
"LookConfig.h"
|
||||
"LookConfig.ui"
|
||||
|
||||
@ -5,43 +5,20 @@
|
||||
|
||||
#include "DeveloperConsole.h"
|
||||
|
||||
#include "LogEmitter.h"
|
||||
#include "Global.h"
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QtWidgets/QTextBrowser>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -6,26 +6,26 @@
|
||||
#ifndef MUMBLE_MUMBLE_DEVELOPERCONSOLE_H_
|
||||
#define MUMBLE_MUMBLE_DEVELOPERCONSOLE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
|
||||
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
|
||||
|
||||
@ -31,7 +31,6 @@ class Overlay;
|
||||
class LCD;
|
||||
class Zeroconf;
|
||||
class OverlayClient;
|
||||
class LogEmitter;
|
||||
class DeveloperConsole;
|
||||
class TalkingUI;
|
||||
class TrayIcon;
|
||||
@ -69,7 +68,6 @@ public:
|
||||
LCD *lcd;
|
||||
Zeroconf *zeroconf;
|
||||
QNetworkAccessManager *nam;
|
||||
QSharedPointer< LogEmitter > le;
|
||||
DeveloperConsole *c;
|
||||
TalkingUI *talkingUI;
|
||||
int iPushToTalk;
|
||||
|
||||
@ -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 <QtCore/QProcess>
|
||||
#include <QtGui/QDesktopServices>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QtWidgets/QTextBrowser>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
// that can be found in the LICENSE file at the root of the
|
||||
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
|
||||
|
||||
#include "LogEmitter.h"
|
||||
#include "MainWindow.h"
|
||||
#ifdef USE_OVERLAY
|
||||
# include "Overlay.h"
|
||||
@ -14,9 +13,6 @@
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
char *os_lang = nullptr;
|
||||
static FILE *fConsole = nullptr;
|
||||
|
||||
static QSharedPointer<LogEmitter> le;
|
||||
|
||||
#define PATH_MAX 1024
|
||||
static char crashhandler_fn[PATH_MAX];
|
||||
@ -24,44 +20,6 @@ static char crashhandler_fn[PATH_MAX];
|
||||
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<char> 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. */
|
||||
|
||||
@ -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 <https://www.mumble.info/LICENSE>.
|
||||
#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);
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
// that can be found in the LICENSE file at the root of the
|
||||
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
|
||||
|
||||
#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)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user