mirror of https://github.com/mgba-emu/mgba.git
Qt: Add logging to file and console
This commit is contained in:
parent
4e39875e7b
commit
2a60d391fe
2
CHANGES
2
CHANGES
|
@ -1,4 +1,6 @@
|
|||
0.8.0: (Future)
|
||||
Features:
|
||||
- Improved logging configuration
|
||||
Bugfixes:
|
||||
- GBA: All IRQs have 7 cycle delay (fixes mgba.io/i/539, mgba.io/i/1208)
|
||||
- GBA: Reset now reloads multiboot ROMs
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
LogController* logger() { return m_controller; }
|
||||
|
||||
public slots:
|
||||
void reset();
|
||||
void save(ConfigController*);
|
||||
|
|
|
@ -41,6 +41,9 @@ LogController::Stream LogController::operator()(int category, int level) {
|
|||
|
||||
void LogController::load(const ConfigController* config) {
|
||||
mLogFilterLoad(&m_filter, config->config());
|
||||
setLogFile(config->getOption("logFile"));
|
||||
logToStdout(config->getOption("logToStdout").toInt());
|
||||
logToFile(config->getOption("logToFile").toInt());
|
||||
}
|
||||
|
||||
void LogController::save(ConfigController* config) const {
|
||||
|
@ -51,6 +54,17 @@ void LogController::postLog(int level, int category, const QString& string) {
|
|||
if (!mLogFilterTest(&m_filter, category, static_cast<mLogLevel>(level))) {
|
||||
return;
|
||||
}
|
||||
if (m_logToStdout || m_logToFile) {
|
||||
QString line = tr("[%1] %2: %3").arg(LogController::toString(level)).arg(mLogCategoryName(category)).arg(string);
|
||||
|
||||
if (m_logToStdout) {
|
||||
QTextStream out(stdout);
|
||||
out << line << endl;
|
||||
}
|
||||
if (m_logToFile && m_logStream) {
|
||||
*m_logStream << line << endl;
|
||||
}
|
||||
}
|
||||
emit logPosted(level, category, string);
|
||||
}
|
||||
|
||||
|
@ -94,6 +108,21 @@ void LogController::clearLevels(int category) {
|
|||
mLogFilterReset (&m_filter, id);
|
||||
}
|
||||
|
||||
void LogController::logToFile(bool log) {
|
||||
m_logToFile = log;
|
||||
}
|
||||
|
||||
void LogController::logToStdout(bool log) {
|
||||
m_logToStdout = log;
|
||||
}
|
||||
|
||||
void LogController::setLogFile(const QString& file) {
|
||||
m_logStream.reset();
|
||||
m_logFile = std::make_unique<QFile>(file);
|
||||
m_logFile->open(QIODevice::Append | QIODevice::Text);
|
||||
m_logStream = std::make_unique<QTextStream>(m_logFile.get());
|
||||
}
|
||||
|
||||
LogController* LogController::global() {
|
||||
return &s_global;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
#include <memory>
|
||||
|
||||
namespace QGBA {
|
||||
|
||||
|
@ -71,8 +73,16 @@ public slots:
|
|||
void disableLevels(int levels, int category);
|
||||
void clearLevels(int category);
|
||||
|
||||
void logToFile(bool);
|
||||
void logToStdout(bool);
|
||||
void setLogFile(const QString&);
|
||||
|
||||
private:
|
||||
mLogFilter m_filter;
|
||||
bool m_logToFile;
|
||||
bool m_logToStdout;
|
||||
std::unique_ptr<QFile> m_logFile;
|
||||
std::unique_ptr<QTextStream> m_logStream;
|
||||
|
||||
static LogController s_global;
|
||||
};
|
||||
|
|
|
@ -300,6 +300,13 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
|
|||
m_ui.loggingView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
m_ui.loggingView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
connect(m_ui.logFileBrowse, &QAbstractButton::pressed, [this] () {
|
||||
QString path = GBAApp::app()->getSaveFileName(this, "Select log file");
|
||||
if (!path.isNull()) {
|
||||
m_ui.logFile->setText(path);
|
||||
}
|
||||
});
|
||||
|
||||
ShortcutView* shortcutView = new ShortcutView();
|
||||
shortcutView->setController(shortcutController);
|
||||
shortcutView->setInputController(inputController);
|
||||
|
@ -379,6 +386,9 @@ void SettingsView::updateConfig() {
|
|||
saveSetting("cheatAutosave", m_ui.cheatAutosave);
|
||||
saveSetting("autoload", m_ui.autoload);
|
||||
saveSetting("autosave", m_ui.autosave);
|
||||
saveSetting("logToFile", m_ui.logToFile);
|
||||
saveSetting("logToStdout", m_ui.logToStdout);
|
||||
saveSetting("logFile", m_ui.logFile);
|
||||
|
||||
if (m_ui.fastForwardUnbounded->isChecked()) {
|
||||
saveSetting("fastForwardRatio", "-1");
|
||||
|
@ -438,6 +448,9 @@ void SettingsView::updateConfig() {
|
|||
}
|
||||
|
||||
m_logModel.save(m_controller);
|
||||
m_logModel.logger()->setLogFile(m_ui.logFile->text());
|
||||
m_logModel.logger()->logToFile(m_ui.logToFile->isChecked());
|
||||
m_logModel.logger()->logToStdout(m_ui.logToStdout->isChecked());
|
||||
|
||||
#ifdef M_CORE_GB
|
||||
GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
|
||||
|
@ -505,6 +518,9 @@ void SettingsView::reloadConfig() {
|
|||
loadSetting("cheatAutosave", m_ui.cheatAutosave, true);
|
||||
loadSetting("autoload", m_ui.autoload, true);
|
||||
loadSetting("autosave", m_ui.autosave, false);
|
||||
loadSetting("logToFile", m_ui.logToFile);
|
||||
loadSetting("logToStdout", m_ui.logToStdout);
|
||||
loadSetting("logFile", m_ui.logFile);
|
||||
|
||||
m_ui.libraryStyle->setCurrentIndex(loadSetting("libraryStyle").toInt());
|
||||
|
||||
|
|
|
@ -1211,8 +1211,8 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="logging">
|
||||
<layout class="QGridLayout" name="a">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTableView" name="loggingView">
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>0</number>
|
||||
|
@ -1222,6 +1222,38 @@
|
|||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_19">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="logToFile">
|
||||
<property name="text">
|
||||
<string>Log to file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="logToStdout">
|
||||
<property name="text">
|
||||
<string>Log to console</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_20">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="logFile"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="logFileBrowse">
|
||||
<property name="text">
|
||||
<string>Select Log File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="gb">
|
||||
|
|
Loading…
Reference in New Issue