From 53b8f1ee0b675f50e2cf3b2b9482721a54b4e588 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 9 Aug 2024 23:58:30 -0700 Subject: [PATCH] core/log: add read-log --no-time --- src/core/logging.cpp | 4 ++-- src/core/logging.hpp | 2 +- src/core/main.cpp | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/logging.cpp b/src/core/logging.cpp index 7a8426b8..649eb947 100644 --- a/src/core/logging.cpp +++ b/src/core/logging.cpp @@ -641,7 +641,7 @@ bool EncodedLogReader::registerCategory() { return true; } -bool readEncodedLogs(QIODevice* device, const QString& rulespec) { +bool readEncodedLogs(QIODevice* device, bool timestamps, const QString& rulespec) { using namespace qt_logging_registry; QList rules; @@ -700,7 +700,7 @@ bool readEncodedLogs(QIODevice* device, const QString& rulespec) { } if (filter.shouldDisplay(message.type)) { - LogMessage::formatMessage(stream, message, color, true); + LogMessage::formatMessage(stream, message, color, timestamps); stream << '\n'; } } diff --git a/src/core/logging.hpp b/src/core/logging.hpp index 5462144f..88fd6716 100644 --- a/src/core/logging.hpp +++ b/src/core/logging.hpp @@ -98,7 +98,7 @@ private: LoggingThreadProxy threadProxy; }; -bool readEncodedLogs(QIODevice* device, const QString& rulespec); +bool readEncodedLogs(QIODevice* device, bool timestamps, const QString& rulespec); } // namespace qs::log diff --git a/src/core/main.cpp b/src/core/main.cpp index 23eb2124..c785f2f0 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -142,6 +142,8 @@ int qs_main(int argc, char** argv) { /// --- QStringOption logPath; QStringOption logFilter; + auto logNoTime = false; + auto* readLog = app.add_subcommand("read-log", "Read a quickshell log file."); readLog->add_option("path", logPath, "Path to the log file to read")->required(); @@ -151,6 +153,7 @@ int qs_main(int argc, char** argv) { "Logging categories to display. (same syntax as QT_LOGGING_RULES)" ); + readLog->add_flag("--no-time", logNoTime, "Do not print timestamps of log messages."); readLog->add_flag("--no-color", noColor, "Do not color the log output. (Env:NO_COLOR)"); CLI11_PARSE(app, argc, argv); @@ -169,7 +172,7 @@ int qs_main(int argc, char** argv) { qInfo() << "Reading log" << *logPath; } - return qs::log::readEncodedLogs(&file, *logFilter) ? 0 : -1; + return qs::log::readEncodedLogs(&file, !logNoTime, *logFilter) ? 0 : -1; } else { // NOLINTBEGIN