diff options
author | Christian Kamm <mail@ckamm.de> | 2019-03-15 14:12:13 +0300 |
---|---|---|
committer | Christian Kamm <mail@ckamm.de> | 2019-04-09 14:15:05 +0300 |
commit | fcf2af3be6964fce7988d050d837255bd308cac8 (patch) | |
tree | 34f83d3a21b74e736e26029890757013f1cec97f | |
parent | 2b0f32c6459bfcde4c8e94fe086e861aee6c56e5 (diff) |
LogWindow: Remove output, add "go to log folder" button #6475
-rw-r--r-- | docs/modules/ROOT/assets/images/log_output_window.png | bin | 21828 -> 73395 bytes | |||
-rw-r--r-- | docs/modules/ROOT/pages/troubleshooting.adoc | 5 | ||||
-rw-r--r-- | src/gui/logbrowser.cpp | 188 | ||||
-rw-r--r-- | src/gui/logbrowser.h | 31 | ||||
-rw-r--r-- | src/libsync/logger.cpp | 9 | ||||
-rw-r--r-- | src/libsync/logger.h | 2 |
6 files changed, 37 insertions, 198 deletions
diff --git a/docs/modules/ROOT/assets/images/log_output_window.png b/docs/modules/ROOT/assets/images/log_output_window.png Binary files differindex ca23ab0d0..15e718f9e 100644 --- a/docs/modules/ROOT/assets/images/log_output_window.png +++ b/docs/modules/ROOT/assets/images/log_output_window.png diff --git a/docs/modules/ROOT/pages/troubleshooting.adoc b/docs/modules/ROOT/pages/troubleshooting.adoc index 64f38ff05..4350367a0 100644 --- a/docs/modules/ROOT/pages/troubleshooting.adoc +++ b/docs/modules/ROOT/pages/troubleshooting.adoc @@ -86,9 +86,8 @@ The Log Output window opens. + image:log_output_window.png[image] + -. Enable the btn:[Permanently save logs] checkbox. -. Look at its tooltip and take note of the directory the logs will be saved to. -. Navigate to this directory. +. Enable the btn:[Enable logging to temporary folder] checkbox. +. Later, to find the log files, click the btn:[Open folder] button. . Select the logs for the time frame in which the issue occurred. NOTE: That the choice to enable logging will be persist across client restarts. diff --git a/src/gui/logbrowser.cpp b/src/gui/logbrowser.cpp index 7abfeb22d..b102c674f 100644 --- a/src/gui/logbrowser.cpp +++ b/src/gui/logbrowser.cpp @@ -18,17 +18,16 @@ #include <iostream> #include <QDialogButtonBox> -#include <QTextDocument> #include <QLayout> #include <QPushButton> #include <QLabel> -#include <QFileDialog> #include <QDir> #include <QTextStream> #include <QMessageBox> #include <QCoreApplication> #include <QSettings> #include <QAction> +#include <QDesktopServices> #include "configfile.h" #include "logger.h" @@ -37,21 +36,8 @@ namespace OCC { // ============================================================================== -LogWidget::LogWidget(QWidget *parent) - : QPlainTextEdit(parent) -{ - setReadOnly(true); - QFont font; - font.setFamily(QLatin1String("Courier New")); - font.setFixedPitch(true); - document()->setDefaultFont(font); -} - -// ============================================================================== - LogBrowser::LogBrowser(QWidget *parent) : QDialog(parent) - , _logWidget(new LogWidget(parent)) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setObjectName("LogBrowser"); // for save/restoreGeometry() @@ -59,79 +45,52 @@ LogBrowser::LogBrowser(QWidget *parent) setMinimumWidth(600); QVBoxLayout *mainLayout = new QVBoxLayout; - // mainLayout->setMargin(0); - - mainLayout->addWidget(_logWidget); - - QHBoxLayout *toolLayout = new QHBoxLayout; - mainLayout->addLayout(toolLayout); - // Search input field - QLabel *lab = new QLabel(tr("&Search:") + " "); - _findTermEdit = new QLineEdit; - lab->setBuddy(_findTermEdit); - toolLayout->addWidget(lab); - toolLayout->addWidget(_findTermEdit); + auto label = new QLabel( + tr("The client can write debug logs to a temporary folder. " + "These logs are very helpful for diagnosing problems.\n" + "Since log files can get large, the client will start a new one for each sync " + "run and compress older ones. It will also delete log files after a couple " + "of hours to avoid consuming too much disk space.\n" + "If enabled, logs will be written to %1") + .arg(Logger::instance()->temporaryFolderLogDirPath())); + label->setWordWrap(true); + label->setTextInteractionFlags(Qt::TextSelectableByMouse); + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding); + mainLayout->addWidget(label); - // find button - QPushButton *findBtn = new QPushButton; - findBtn->setText(tr("&Find")); - connect(findBtn, &QAbstractButton::clicked, this, &LogBrowser::slotFind); - toolLayout->addWidget(findBtn); - - // stretch - toolLayout->addStretch(1); - _statusLabel = new QLabel; - toolLayout->addWidget(_statusLabel); - toolLayout->addStretch(5); - - // Debug logging - _logDebugCheckBox = new QCheckBox(tr("&Capture debug messages") + " "); - connect(_logDebugCheckBox, &QCheckBox::stateChanged, this, &LogBrowser::slotDebugCheckStateChanged); - toolLayout->addWidget(_logDebugCheckBox); + // button to permanently save logs + auto enableLoggingButton = new QCheckBox; + enableLoggingButton->setText(tr("Enable logging to temporary folder")); + enableLoggingButton->setChecked(ConfigFile().automaticLogDir()); + connect(enableLoggingButton, &QCheckBox::toggled, this, &LogBrowser::togglePermanentLogging); + mainLayout->addWidget(enableLoggingButton); + + label = new QLabel( + tr("This setting persists across client restarts.\n" + "Note that using any logging command line options will override this setting.")); + label->setWordWrap(true); + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding); + mainLayout->addWidget(label); + + auto openFolderButton = new QPushButton; + openFolderButton->setText(tr("Open folder")); + connect(openFolderButton, &QPushButton::clicked, this, []() { + QDesktopServices::openUrl(Logger::instance()->temporaryFolderLogDirPath()); + }); + mainLayout->addWidget(openFolderButton); QDialogButtonBox *btnbox = new QDialogButtonBox; QPushButton *closeBtn = btnbox->addButton(QDialogButtonBox::Close); connect(closeBtn, &QAbstractButton::clicked, this, &QWidget::close); + mainLayout->addStretch(); mainLayout->addWidget(btnbox); - // button to permanently save logs - _permanentLogging = new QCheckBox; - _permanentLogging->setText(tr("Permanently save logs")); - _permanentLogging->setToolTip( - tr("When this option is enabled and no other logging is configured, " - "logs will be written to a temporary folder and expire after a few hours. " - "This setting persists across client restarts.\n" - "\n" - "Logs will be written to %1") - .arg(Logger::instance()->temporaryFolderLogDirPath())); - _permanentLogging->setChecked(ConfigFile().automaticLogDir()); - btnbox->addButton(_permanentLogging, QDialogButtonBox::ActionRole); - connect(_permanentLogging, &QCheckBox::toggled, this, &LogBrowser::togglePermanentLogging); - - // clear button - _clearBtn = new QPushButton; - _clearBtn->setText(tr("Clear")); - _clearBtn->setToolTip(tr("Clear the log display.")); - btnbox->addButton(_clearBtn, QDialogButtonBox::ActionRole); - connect(_clearBtn, &QAbstractButton::clicked, this, &LogBrowser::slotClearLog); - - // save Button - _saveBtn = new QPushButton; - _saveBtn->setText(tr("S&ave")); - _saveBtn->setToolTip(tr("Save the log file to a file on disk for debugging.")); - btnbox->addButton(_saveBtn, QDialogButtonBox::ActionRole); - connect(_saveBtn, &QAbstractButton::clicked, this, &LogBrowser::slotSave); - setLayout(mainLayout); setModal(false); - Logger::instance()->setLogWindowActivated(true); - // Direct connection for log coming from this thread, and queued for the one in a different thread - connect(Logger::instance(), &Logger::logWindowLog, this, &LogBrowser::slotNewLog, Qt::AutoConnection); - QAction *showLogWindow = new QAction(this); showLogWindow->setShortcut(QKeySequence("F12")); connect(showLogWindow, &QAction::triggered, this, &QWidget::close); @@ -139,97 +98,18 @@ LogBrowser::LogBrowser(QWidget *parent) ConfigFile cfg; cfg.restoreGeometry(this); - int lines = cfg.maxLogLines(); - _logWidget->document()->setMaximumBlockCount(lines); } LogBrowser::~LogBrowser() { } -void LogBrowser::showEvent(QShowEvent *) -{ - // This could have been changed through the --logdebug argument passed through the single application. - _logDebugCheckBox->setCheckState(Logger::instance()->logDebug() ? Qt::Checked : Qt::Unchecked); -} - void LogBrowser::closeEvent(QCloseEvent *) { ConfigFile cfg; cfg.saveGeometry(this); } - -void LogBrowser::slotNewLog(const QString &msg) -{ - if (_logWidget->isVisible()) { - _logWidget->appendPlainText(msg); - } -} - - -void LogBrowser::slotFind() -{ - QString searchText = _findTermEdit->text(); - - if (searchText.isEmpty()) - return; - - search(searchText); -} - -void LogBrowser::slotDebugCheckStateChanged(int checkState) -{ - Logger::instance()->setLogDebug(checkState == Qt::Checked); -} - -void LogBrowser::search(const QString &str) -{ - QList<QTextEdit::ExtraSelection> extraSelections; - - _logWidget->moveCursor(QTextCursor::Start); - QColor color = QColor(Qt::gray).lighter(130); - _statusLabel->clear(); - - while (_logWidget->find(str)) { - QTextEdit::ExtraSelection extra; - extra.format.setBackground(color); - - extra.cursor = _logWidget->textCursor(); - extraSelections.append(extra); - } - - QString stat = QString::fromLatin1("Search term %1 with %2 search results.").arg(str).arg(extraSelections.count()); - _statusLabel->setText(stat); - - _logWidget->setExtraSelections(extraSelections); -} - -void LogBrowser::slotSave() -{ - _saveBtn->setEnabled(false); - - QString saveFile = QFileDialog::getSaveFileName(this, tr("Save log file"), QDir::homePath()); - - if (!saveFile.isEmpty()) { - QFile file(saveFile); - - if (file.open(QIODevice::WriteOnly)) { - QTextStream stream(&file); - stream << _logWidget->toPlainText(); - file.close(); - } else { - QMessageBox::critical(this, tr("Error"), tr("Could not write to log file %1").arg(saveFile)); - } - } - _saveBtn->setEnabled(true); -} - -void LogBrowser::slotClearLog() -{ - _logWidget->clear(); -} - void LogBrowser::togglePermanentLogging(bool enabled) { ConfigFile().setAutomaticLogDir(enabled); diff --git a/src/gui/logbrowser.h b/src/gui/logbrowser.h index b7e2d58ac..129cc4cc7 100644 --- a/src/gui/logbrowser.h +++ b/src/gui/logbrowser.h @@ -30,19 +30,6 @@ namespace OCC { /** - * @brief The LogWidget class - * @ingroup gui - */ -class LogWidget : public QPlainTextEdit -{ - Q_OBJECT -public: - explicit LogWidget(QWidget *parent = 0); - -signals: -}; - -/** * @brief The LogBrowser class * @ingroup gui */ @@ -53,29 +40,11 @@ public: explicit LogBrowser(QWidget *parent = 0); ~LogBrowser(); - void setLogFile(const QString &, bool); - protected: - void showEvent(QShowEvent *) Q_DECL_OVERRIDE; void closeEvent(QCloseEvent *) Q_DECL_OVERRIDE; protected slots: - void slotNewLog(const QString &msg); - void slotFind(); - void slotDebugCheckStateChanged(int); - void search(const QString &); - void slotSave(); - void slotClearLog(); void togglePermanentLogging(bool enabled); - -private: - LogWidget *_logWidget; - QLineEdit *_findTermEdit; - QCheckBox *_logDebugCheckBox; - QCheckBox *_permanentLogging; - QPushButton *_saveBtn; - QPushButton *_clearBtn; - QLabel *_statusLabel; }; } // namespace diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index afbb1fc25..cbee25c63 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -57,7 +57,6 @@ Logger *Logger::instance() Logger::Logger(QObject *parent) : QObject(parent) , _showTime(true) - , _logWindowActivated(false) , _doFileFlush(false) , _logExpire(0) , _logDebug(false) @@ -114,7 +113,7 @@ void Logger::log(Log log) bool Logger::isNoop() const { QMutexLocker lock(&_mutex); - return !_logstream && !_logWindowActivated; + return !_logstream; } bool Logger::isLoggingToFile() const @@ -145,12 +144,6 @@ void Logger::mirallLog(const QString &message) Logger::instance()->log(log_); } -void Logger::setLogWindowActivated(bool activated) -{ - QMutexLocker locker(&_mutex); - _logWindowActivated = activated; -} - void Logger::setLogFile(const QString &name) { QMutexLocker locker(&_mutex); diff --git a/src/libsync/logger.h b/src/libsync/logger.h index 90edcc8ec..9ba7dbad2 100644 --- a/src/libsync/logger.h +++ b/src/libsync/logger.h @@ -57,7 +57,6 @@ public: void postOptionalGuiLog(const QString &title, const QString &message); void postGuiMessage(const QString &title, const QString &message); - void setLogWindowActivated(bool activated); void setLogFile(const QString &name); void setLogExpire(int expire); void setLogDir(const QString &dir); @@ -97,7 +96,6 @@ private: ~Logger(); QList<Log> _logs; bool _showTime; - bool _logWindowActivated; QFile _logFile; bool _doFileFlush; int _logExpire; |