diff --git a/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt b/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt index f7779dad..3ce35bd0 100644 --- a/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt +++ b/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt @@ -110,6 +110,7 @@ endif(UNIX) add_executable(bridge-gui Resources.qrc AppController.cpp AppController.h + CommandLine.cpp CommandLine.h EventStreamWorker.cpp EventStreamWorker.h main.cpp Pch.h diff --git a/internal/frontend/bridge-gui/bridge-gui/CommandLine.cpp b/internal/frontend/bridge-gui/bridge-gui/CommandLine.cpp new file mode 100644 index 00000000..0e05ad3a --- /dev/null +++ b/internal/frontend/bridge-gui/bridge-gui/CommandLine.cpp @@ -0,0 +1,129 @@ +// Copyright (c) 2022 Proton AG +// +// This file is part of Proton Mail Bridge. +// +// Proton Mail Bridge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Proton Mail Bridge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Proton Mail Bridge. If not, see . + + +#include "Pch.h" +#include "CommandLine.h" + + +using namespace bridgepp; + + +namespace +{ + + +QString const launcherFlag = "--launcher"; ///< launcher flag parameter used for bridge. + + +//**************************************************************************************************************************************************** +/// \brief parse a command-line string argument as expected by go's CLI package. +/// \param[in] argc The number of arguments passed to the application. +/// \param[in] argv The list of arguments passed to the application. +/// \param[in] paramNames the list of names for the parameter +//**************************************************************************************************************************************************** +QString parseGoCLIStringArgument(int argc, char *argv[], QStringList paramNames) +{ + // go cli package is pretty permissive when it comes to parsing arguments. For each name 'param', all the following seems to be accepted: + // -param value + // --param value + // -param=value + // --param=value + + for (QString const ¶mName: paramNames) + for (qsizetype i = 1; i < argc; ++i) + { + QString const arg(QString::fromLocal8Bit(argv[i])); + if ((i < argc - 1) && ((arg == "-" + paramName) || (arg == "--" + paramName))) + return QString(argv[i + 1]); + + QRegularExpressionMatch match = QRegularExpression(QString("^-{1,2}%1=(.+)$").arg(paramName)).match(arg); + if (match.hasMatch()) + return match.captured(1); + } + + return QString(); +} + + +//**************************************************************************************************************************************************** +/// \brief Parse the log level from the command-line arguments. +/// +/// \param[in] argc The number of arguments passed to the application. +/// \param[in] argv The list of arguments passed to the application. +/// \return The log level. if not specified on the command-line, the default log level is returned. +//**************************************************************************************************************************************************** +Log::Level parseLogLevel(int argc, char *argv[]) +{ + QString levelStr = parseGoCLIStringArgument(argc, argv, { "l", "log-level" }); + if (levelStr.isEmpty()) + return Log::defaultLevel; + + Log::Level level = Log::defaultLevel; + Log::stringToLevel(levelStr, level); + return level; +} + + +} // anonymous namespace + + +//**************************************************************************************************************************************************** +/// \param[in] argc number of arguments passed to the application. +/// \param[in] argv list of arguments passed to the application. +/// \param[out] args list of arguments passed to the application as a QStringList. +/// \param[out] launcher launcher used in argument, forced to self application if not specify. +/// \param[out] outAttach The value for the 'attach' command-line parameter. +/// \param[out] outLogLevel The parsed log level. If not found, the default log level is returned. +//**************************************************************************************************************************************************** +void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QString& launcher, bool &outAttach, Log::Level& outLogLevel) { + bool flagFound = false; + launcher = QString::fromLocal8Bit(argv[0]); + // for unknown reasons, on Windows QCoreApplication::arguments() frequently returns an empty list, which is incorrect, so we rebuild the argument + // list from the original argc and argv values. + for (int i = 1; i < argc; i++) { + QString const &arg = QString::fromLocal8Bit(argv[i]); + // we can't use QCommandLineParser here since it will fail on unknown options. + // Arguments may contain some bridge flags. + if (arg == launcherFlag) + { + args.append(arg); + launcher = QString::fromLocal8Bit(argv[++i]); + args.append(launcher); + flagFound = true; + } +#ifdef QT_DEBUG + else if (arg == "--attach" || arg == "-a") + { + // we don't keep the attach mode within the args since we don't need it for Bridge. + outAttach = true; + } +#endif + else + { + args.append(arg); + } + } + if (!flagFound) + { + // add bridge-gui as launcher + args.append(launcherFlag); + args.append(launcher); + } + + outLogLevel = parseLogLevel(argc, argv); +} diff --git a/internal/frontend/bridge-gui/bridge-gui/CommandLine.h b/internal/frontend/bridge-gui/bridge-gui/CommandLine.h new file mode 100644 index 00000000..e32f8bfd --- /dev/null +++ b/internal/frontend/bridge-gui/bridge-gui/CommandLine.h @@ -0,0 +1,29 @@ +// Copyright (c) 2022 Proton AG +// +// This file is part of Proton Mail Bridge. +// +// Proton Mail Bridge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Proton Mail Bridge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Proton Mail Bridge. If not, see . + + +#ifndef BRIDGE_GUI_COMMAND_LINE_H +#define BRIDGE_GUI_COMMAND_LINE_H + + +#include + + +void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QString& launcher, bool &outAttach, bridgepp::Log::Level& outLogLevel); ///< Parse the command-line arguments + + +#endif //BRIDGE_GUI_COMMAND_LINE_H diff --git a/internal/frontend/bridge-gui/bridge-gui/UserList.cpp b/internal/frontend/bridge-gui/bridge-gui/UserList.cpp index 9492c75c..b657ada8 100644 --- a/internal/frontend/bridge-gui/bridge-gui/UserList.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/UserList.cpp @@ -161,12 +161,9 @@ bridgepp::SPUser UserList::getUserWithID(QString const &userID) const User *UserList::get(int row) const { if ((row < 0) || (row >= users_.count())) - { - app().log().error(QString("Requesting invalid user at row %1 (user userCount = %2)").arg(row).arg(users_.count())); return nullptr; - } - app().log().debug(QString("Retrieving user at row %1 (user userCount = %2)").arg(row).arg(users_.count())); + app().log().trace(QString("Retrieving user at row %1 (user userCount = %2)").arg(row).arg(users_.count())); return users_[row].get(); } @@ -185,7 +182,7 @@ void UserList::onUserChanged(QString const &userID) { if (index >= 0) // user exists here but not in the go backend. we delete it. { - app().log().debug(QString("Removing user from user list: %1").arg(userID)); + app().log().trace(QString("Removing user from user list: %1").arg(userID)); this->removeUserAt(index); } return; @@ -193,12 +190,12 @@ void UserList::onUserChanged(QString const &userID) if (index < 0) { - app().log().debug(QString("Adding user in user list: %1").arg(userID)); + app().log().trace(QString("Adding user in user list: %1").arg(userID)); this->appendUser(user); return; } - app().log().debug(QString("Updating user in user list: %1").arg(userID)); + app().log().trace(QString("Updating user in user list: %1").arg(userID)); this->updateUserAtRow(index, *user); } diff --git a/internal/frontend/bridge-gui/bridge-gui/main.cpp b/internal/frontend/bridge-gui/bridge-gui/main.cpp index 68f52cfa..bef0c101 100644 --- a/internal/frontend/bridge-gui/bridge-gui/main.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/main.cpp @@ -16,6 +16,8 @@ // along with Proton Mail Bridge. If not, see . +#include "Pch.h" +#include "CommandLine.h" #include "QMLBackend.h" #include "Version.h" #include @@ -23,10 +25,6 @@ #include #include -#include -#include -#include -#include using namespace bridgepp; @@ -41,7 +39,6 @@ namespace QString const exeSuffix; #endif - QString const launcherFlag = "--launcher"; ///< launcher flag parameter used for bridge. QString const bridgeLock = "bridge-gui.lock"; ///< file name used for the lock file. QString const exeName = "bridge" + exeSuffix; ///< The bridge executable file name.* } @@ -81,8 +78,6 @@ void initQtApplication() Log &initLog() { Log &log = app().log(); - log.setEchoInConsole(true); - log.setLevel(Log::Level::Debug); log.registerAsQtMessageHandler(); return log; } @@ -141,7 +136,7 @@ bool checkSingleInstance(QLockFile &lock) //**************************************************************************************************************************************************** -/// \return QUrl to reqch the bridge API. +/// \return QUrl to reach the bridge API. //**************************************************************************************************************************************************** QUrl getApiUrl() { @@ -189,50 +184,6 @@ void focusOtherInstance() } -//**************************************************************************************************************************************************** -/// \param [in] argc number of arguments passed to the application. -/// \param [in] argv list of arguments passed to the application. -/// \param [out] args list of arguments passed to the application as a QStringList. -/// \param [out] launcher launcher used in argument, forced to self application if not specify. -/// \param[out] outAttach The value for the 'attach' command-line parameter. -//**************************************************************************************************************************************************** -void parseArguments(int argc, char *argv[], QStringList& args, QString& launcher, bool &outAttach) { - bool flagFound = false; - launcher = QString::fromLocal8Bit(argv[0]); - // for unknown reasons, on Windows QCoreApplication::arguments() frequently returns an empty list, which is incorrect, so we rebuild the argument - // list from the original argc and argv values. - for (int i = 1; i < argc; i++) { - QString const &arg = QString::fromLocal8Bit(argv[i]); - // we can't use QCommandLineParser here since it will fail on unknown options. - // Arguments may contain some bridge flags. - if (arg == launcherFlag) - { - args.append(arg); - launcher = QString::fromLocal8Bit(argv[++i]); - args.append(launcher); - flagFound = true; - } -#ifdef QT_DEBUG - else if (arg == "--attach" || arg == "-a") - { - // we don't keep the attach mode within the args since we don't need it for Bridge. - outAttach = true; - } -#endif - else - { - args.append(arg); - } - } - if (!flagFound) - { - // add bridge-gui as launcher - args.append(launcherFlag); - args.append(launcher); - } -} - - //**************************************************************************************************************************************************** /// \param [in] args list of arguments to pass to bridge. //**************************************************************************************************************************************************** @@ -300,7 +251,14 @@ int main(int argc, char *argv[]) QStringList args; QString launcher; bool attach = false; - parseArguments(argc, argv, args, launcher, attach); + Log::Level logLevel = Log::defaultLevel; + parseCommandLineArguments(argc, argv, args, launcher, attach, logLevel); + + // In attached mode, we do not intercept stderr and stdout of bridge, as we did not launch it ourselves, so we output the log to the console. + // When not in attached mode, log entries are forwarded to bridge, which output it on stdout/stderr. bridge-gui's process monitor intercept + // these outputs and output them on the command-line. + log.setEchoInConsole(attach); + log.setLevel(logLevel); if (!attach) launchBridge(args); @@ -344,7 +302,7 @@ int main(int argc, char *argv[]) int result = 0; if (!startError) { - // we succeed to run the bridge so we can be set as mainExecutable. + // we succeeded in launching bridge, so we can be set as mainExecutable. app().grpc().setMainExecutable(QString::fromLocal8Bit(argv[0])); result = QGuiApplication::exec(); } diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp index a6b6006f..47e3c3c0 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp @@ -897,10 +897,10 @@ grpc::Status GRPCClient::stopEventStreamReader() //**************************************************************************************************************************************************** /// \param[in] message The event message. //**************************************************************************************************************************************************** -void GRPCClient::logDebug(QString const &message) +void GRPCClient::logTrace(QString const &message) { if (log_) - log_->debug(message); + log_->trace(message); } @@ -1102,31 +1102,31 @@ void GRPCClient::processAppEvent(AppEvent const &event) switch (event.event_case()) { case AppEvent::kInternetStatus: - this->logDebug("App event received: InternetStatus."); + this->logTrace("App event received: InternetStatus."); emit internetStatus(event.internetstatus().connected()); break; case AppEvent::kToggleAutostartFinished: - this->logDebug("App event received: AutostartFinished."); + this->logTrace("App event received: AutostartFinished."); emit toggleAutostartFinished(); break; case AppEvent::kResetFinished: - this->logDebug("App event received: ResetFinished."); + this->logTrace("App event received: ResetFinished."); emit resetFinished(); break; case AppEvent::kReportBugFinished: - this->logDebug("App event received: ReportBugFinished."); + this->logTrace("App event received: ReportBugFinished."); emit reportBugFinished(); break; case AppEvent::kReportBugSuccess: - this->logDebug("App event received: ReportBugSuccess."); + this->logTrace("App event received: ReportBugSuccess."); emit reportBugSuccess(); break; case AppEvent::kReportBugError: - this->logDebug("App event received: ReportBugError."); + this->logTrace("App event received: ReportBugError."); emit reportBugError(); break; case AppEvent::kShowMainWindow: - this->logDebug("App event received: ShowMainWindow."); + this->logTrace("App event received: ShowMainWindow."); emit showMainWindow(); break; default: @@ -1144,7 +1144,7 @@ void GRPCClient::processLoginEvent(LoginEvent const &event) { case LoginEvent::kError: { - this->logDebug("Login event received: Error."); + this->logTrace("Login event received: Error."); LoginErrorEvent const &error = event.error(); switch (error.type()) { @@ -1176,19 +1176,19 @@ void GRPCClient::processLoginEvent(LoginEvent const &event) break; } case LoginEvent::kTfaRequested: - this->logDebug("Login event received: TfaRequested."); + this->logTrace("Login event received: TfaRequested."); emit login2FARequested(QString::fromStdString(event.tfarequested().username())); break; case LoginEvent::kTwoPasswordRequested: - this->logDebug("Login event received: TwoPasswordRequested."); + this->logTrace("Login event received: TwoPasswordRequested."); emit login2PasswordRequested(); break; case LoginEvent::kFinished: - this->logDebug("Login event received: Finished."); + this->logTrace("Login event received: Finished."); emit loginFinished(QString::fromStdString(event.finished().userid())); break; case LoginEvent::kAlreadyLoggedIn: - this->logDebug("Login event received: AlreadyLoggedIn."); + this->logTrace("Login event received: AlreadyLoggedIn."); emit loginAlreadyLoggedIn(QString::fromStdString(event.finished().userid())); break; default: @@ -1207,7 +1207,7 @@ void GRPCClient::processUpdateEvent(UpdateEvent const &event) { case UpdateEvent::kError: { - this->logDebug("Update event received: Error."); + this->logTrace("Update event received: Error."); UpdateErrorEvent const &errorEvent = event.error(); switch (errorEvent.type()) @@ -1228,31 +1228,31 @@ void GRPCClient::processUpdateEvent(UpdateEvent const &event) break; } case UpdateEvent::kManualReady: - this->logDebug("Update event received: ManualReady."); + this->logTrace("Update event received: ManualReady."); emit updateManualReady(QString::fromStdString(event.manualready().version())); break; case UpdateEvent::kManualRestartNeeded: - this->logDebug("Update event received: kManualRestartNeeded."); + this->logTrace("Update event received: kManualRestartNeeded."); emit updateManualRestartNeeded(); break; case UpdateEvent::kForce: - this->logDebug("Update event received: kForce."); + this->logTrace("Update event received: kForce."); emit updateForce(QString::fromStdString(event.force().version())); break; case UpdateEvent::kSilentRestartNeeded: - this->logDebug("Update event received: kSilentRestartNeeded."); + this->logTrace("Update event received: kSilentRestartNeeded."); emit updateSilentRestartNeeded(); break; case UpdateEvent::kIsLatestVersion: - this->logDebug("Update event received: kIsLatestVersion."); + this->logTrace("Update event received: kIsLatestVersion."); emit updateIsLatestVersion(); break; case UpdateEvent::kCheckFinished: - this->logDebug("Update event received: kCheckFinished."); + this->logTrace("Update event received: kCheckFinished."); emit checkUpdatesFinished(); break; case UpdateEvent::kVersionChanged: - this->logDebug("Update event received: kVersionChanged."); + this->logTrace("Update event received: kVersionChanged."); emit updateVersionChanged(); break; default: @@ -1293,22 +1293,22 @@ void GRPCClient::processCacheEvent(CacheEvent const &event) } case CacheEvent::kLocationChangedSuccess: - this->logDebug("Cache event received: LocationChangedSuccess."); + this->logTrace("Cache event received: LocationChangedSuccess."); emit cacheLocationChangeSuccess(); break; case CacheEvent::kChangeLocalCacheFinished: emit changeLocalCacheFinished(event.changelocalcachefinished().willrestart()); - this->logDebug("Cache event received: ChangeLocalCacheFinished."); + this->logTrace("Cache event received: ChangeLocalCacheFinished."); break; case CacheEvent::kIsCacheOnDiskEnabledChanged: - this->logDebug("Cache event received: IsCacheOnDiskEnabledChanged."); + this->logTrace("Cache event received: IsCacheOnDiskEnabledChanged."); emit isCacheOnDiskEnabledChanged(event.iscacheondiskenabledchanged().enabled()); break; case CacheEvent::kDiskCachePathChanged: - this->logDebug("Cache event received: DiskCachePathChanged."); + this->logTrace("Cache event received: DiskCachePathChanged."); emit diskCachePathChanged(QUrl::fromLocalFile(QString::fromStdString(event.diskcachepathchanged().path()))); break; @@ -1326,7 +1326,7 @@ void GRPCClient::processMailSettingsEvent(MailSettingsEvent const &event) switch (event.event_case()) { case MailSettingsEvent::kError: - this->logDebug("MailSettings event received: Error."); + this->logTrace("MailSettings event received: Error."); switch (event.error().type()) { case IMAP_PORT_ISSUE: @@ -1341,11 +1341,11 @@ void GRPCClient::processMailSettingsEvent(MailSettingsEvent const &event) } case MailSettingsEvent::kUseSslForSmtpFinished: - this->logDebug("MailSettings event received: UseSslForSmtpFinished."); + this->logTrace("MailSettings event received: UseSslForSmtpFinished."); emit toggleUseSSLFinished(); break; case MailSettingsEvent::kChangePortsFinished: - this->logDebug("MailSettings event received: ChangePortsFinished."); + this->logTrace("MailSettings event received: ChangePortsFinished."); emit changePortFinished(); break; default: @@ -1362,15 +1362,15 @@ void GRPCClient::processKeychainEvent(KeychainEvent const &event) switch (event.event_case()) { case KeychainEvent::kChangeKeychainFinished: - this->logDebug("Keychain event received: ChangeKeychainFinished."); + this->logTrace("Keychain event received: ChangeKeychainFinished."); emit changeKeychainFinished(); break; case KeychainEvent::kHasNoKeychain: - this->logDebug("Keychain event received: HasNoKeychain."); + this->logTrace("Keychain event received: HasNoKeychain."); emit hasNoKeychain(); break; case KeychainEvent::kRebuildKeychain: - this->logDebug("Keychain event received: RebuildKeychain."); + this->logTrace("Keychain event received: RebuildKeychain."); emit rebuildKeychain(); break; default: @@ -1387,20 +1387,20 @@ void GRPCClient::processMailEvent(MailEvent const &event) switch (event.event_case()) { case MailEvent::kNoActiveKeyForRecipientEvent: - this->logDebug("Mail event received: kNoActiveKeyForRecipientEvent."); + this->logTrace("Mail event received: kNoActiveKeyForRecipientEvent."); emit noActiveKeyForRecipient(QString::fromStdString(event.noactivekeyforrecipientevent().email())); break; case MailEvent::kAddressChanged: - this->logDebug("Mail event received: AddressChanged."); + this->logTrace("Mail event received: AddressChanged."); emit addressChanged(QString::fromStdString(event.addresschanged().address())); break; case MailEvent::kAddressChangedLogout: - this->logDebug("Mail event received: AddressChangedLogout."); + this->logTrace("Mail event received: AddressChangedLogout."); emit addressChangedLogout(QString::fromStdString(event.addresschangedlogout().address())); break; case MailEvent::kApiCertIssue: emit apiCertIssue(); - this->logDebug("Mail event received: ApiCertIssue."); + this->logTrace("Mail event received: ApiCertIssue."); break; default: this->logError("Unknown Mail event received."); @@ -1418,21 +1418,21 @@ void GRPCClient::processUserEvent(UserEvent const &event) case UserEvent::kToggleSplitModeFinished: { QString const userID = QString::fromStdString(event.togglesplitmodefinished().userid()); - this->logDebug(QString("User event received: ToggleSplitModeFinished (userID = %1).").arg(userID)); + this->logTrace(QString("User event received: ToggleSplitModeFinished (userID = %1).").arg(userID)); emit toggleSplitModeFinished(userID); break; } case UserEvent::kUserDisconnected: { QString const username = QString::fromStdString(event.userdisconnected().username()); - this->logDebug(QString("User event received: UserDisconnected (username = %1).").arg(username)); + this->logTrace(QString("User event received: UserDisconnected (username = %1).").arg(username)); emit userDisconnected(username); break; } case UserEvent::kUserChanged: { QString const userID = QString::fromStdString(event.userchanged().userid()); - this->logDebug(QString("User event received: UserChanged (userID = %1).").arg(userID)); + this->logTrace(QString("User event received: UserChanged (userID = %1).").arg(userID)); emit userChanged(userID); break; } diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h index ce16491c..20cff84d 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h @@ -203,7 +203,7 @@ private slots: void configFolderChanged(); private: - void logDebug(QString const &message); ///< Log an event. + void logTrace(QString const &message); ///< Log an event. void logError(QString const &message); ///< Log an event. grpc::Status logGRPCCallStatus(grpc::Status const &status, QString const &callName, QList allowedErrors = {}); ///< Log the status of a gRPC code. grpc::Status simpleMethod(SimpleMethod method); ///< perform a gRPC call to a bool setter. diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.cpp index 38c429e8..480ff509 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.cpp @@ -29,6 +29,18 @@ namespace Log *qtHandlerLog { nullptr }; ///< The log instance handling qt logs. QMutex qtHandlerMutex; ///< A mutex used to access qtHandlerLog. +// Mapping of log levels to string. Maybe used to lookup using both side a a key, so a list of pair is more convenient that a map. +QList> const logLevelStrings { + { Log::Level::Panic, "panic", }, + { Log::Level::Fatal, "fatal", }, + { Log::Level::Error, "error", }, + { Log::Level::Warn, "warn", }, + { Log::Level::Info, "info", }, + { Log::Level::Debug, "debug", }, + { Log::Level::Trace, "trace", }, +}; + + //**************************************************************************************************************************************************** /// \param[in] log The log handling qt log entries. Can be null. //**************************************************************************************************************************************************** @@ -79,36 +91,6 @@ void qtMessageHandler(QtMsgType type, QMessageLogContext const &, QString const break; } } - - -//**************************************************************************************************************************************************** -/// \param[in] level The level. -/// \return A string describing the level. -//**************************************************************************************************************************************************** -QString logLevelToString(Log::Level level) -{ - switch (level) - { - case Log::Level::Panic: - return "PANIC"; - case Log::Level::Fatal: - return "FATAL"; - case Log::Level::Error: - return "ERROR"; - case Log::Level::Warn: - return "WARN"; - case Log::Level::Info: - return "INFO"; - case Log::Level::Debug: - return "DEBUG"; - case Log::Level::Trace: - return "TRACE"; - default: - return "UNKNOWN"; - } -} - - } // anonymous namespace @@ -121,7 +103,43 @@ QString logLevelToString(Log::Level level) //**************************************************************************************************************************************************** QString Log::logEntryToString(Log::Level level, QString const &message) { - return QString("[%1] %2").arg(logLevelToString(level), message); + return QString("[%1] %2").arg(levelToString(level).toUpper(), message); +} + + +//**************************************************************************************************************************************************** +/// \param[in] level The level. +/// \return A string describing the level. +//**************************************************************************************************************************************************** +QString Log::levelToString(Log::Level level) +{ + QList>::const_iterator it = std::find_if(logLevelStrings.begin(), logLevelStrings.end(), + [&level](QPair const &pair) -> bool { + return pair.first == level; + }); + return (it == logLevelStrings.end()) ? QString() : it->second; +} + + +//**************************************************************************************************************************************************** +/// The matching is case-insensitive. +/// +/// \param[in] str The string +/// \param[out] outLevel The log level parsed. if not found, the value of the variable is not modified. +/// \return true iff parsing was successful. +//**************************************************************************************************************************************************** +bool Log::stringToLevel(QString const &str, Log::Level &outLevel) +{ + QList>::const_iterator it = std::find_if(logLevelStrings.begin(), logLevelStrings.end(), + [&str](QPair const &pair) -> bool { + return 0 == QString::compare(str, pair.second, Qt::CaseInsensitive); + }); + + bool const found = (it != logLevelStrings.end()); + if (found) + outLevel = it->first; + + return found; } @@ -162,7 +180,7 @@ void Log::setLevel(Log::Level level) Log::Level Log::level() const { QMutexLocker locker(&mutex_); - return Log::Level::Debug; + return level_; } diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.h index 95ba2f1c..039e8bc6 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/Log/Log.h @@ -45,7 +45,11 @@ public: // data types. public: // static member functions. static QString logEntryToString(Log::Level level, QString const &message); ///< Return a string describing a log entry. + static QString levelToString(Log::Level level); ///< return the string for a level. + static bool stringToLevel(QString const &str, Log::Level& outLevel); ///< parse a level from a string. +public: // static data member. + static const Level defaultLevel { Level::Info }; ///< The default log level (the same as logrus). public: // member functions. Log(); ///< Default constructor. @@ -77,8 +81,8 @@ signals: private: // data members mutable QMutex mutex_; ///< The mutex. - Level level_{Level::Debug}; ///< The log level - bool echoInConsole_{false}; ///< Set if the log messages should be sent to STDOUT/STDERR. + Level level_ { defaultLevel }; ///< The log level + bool echoInConsole_ { false }; ///< Set if the log messages should be sent to STDOUT/STDERR. QTextStream stdout_; ///< The stdout stream. QTextStream stderr_; ///< The stderr stream. diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/ProcessMonitor.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/ProcessMonitor.cpp index 59db0e47..359eb6f4 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/ProcessMonitor.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/ProcessMonitor.cpp @@ -58,11 +58,23 @@ void ProcessMonitor::run() status_.running = true; status_.pid = p.processId(); + QTextStream out(stdout), err(stderr); + QByteArray array; while (!p.waitForFinished(100)) { - // we discard output from bridge, it's logged to file on bridge side. - p.readAllStandardError(); - p.readAllStandardOutput(); + array = p.readAllStandardError(); + if (!array.isEmpty()) + { + err << array; + err.flush(); + } + + array = p.readAllStandardOutput(); + if (!array.isEmpty()) + { + out << array; + out.flush(); + } } status_.running = false; diff --git a/internal/frontend/grpc/service_methods.go b/internal/frontend/grpc/service_methods.go index e849909b..6edfcb2b 100644 --- a/internal/frontend/grpc/service_methods.go +++ b/internal/frontend/grpc/service_methods.go @@ -66,7 +66,7 @@ func (s *Service) AddLogEntry(_ context.Context, request *AddLogEntryRequest) (* // GuiReady implement the GuiReady gRPC service call. func (s *Service) GuiReady(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { - s.log.Info("GuiReady") + s.log.Debug("GuiReady") // sync.one s.initializationDone.Do(s.initializing.Done) return &emptypb.Empty{}, nil @@ -74,7 +74,7 @@ func (s *Service) GuiReady(context.Context, *emptypb.Empty) (*emptypb.Empty, err // Quit implement the Quit gRPC service call. func (s *Service) Quit(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empty, error) { - s.log.Info("Quit") + s.log.Debug("Quit") // Windows is notably slow at Quitting. We do it in a goroutine to speed things up a bit. go func() { @@ -94,19 +94,19 @@ func (s *Service) Quit(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empt // Restart implement the Restart gRPC service call. func (s *Service) Restart(ctx context.Context, empty *emptypb.Empty) (*emptypb.Empty, error) { - s.log.Info("Restart") + s.log.Debug("Restart") s.restarter.SetToRestart() return s.Quit(ctx, empty) } func (s *Service) ShowOnStartup(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("ShowOnStartup") + s.log.Debug("ShowOnStartup") return wrapperspb.Bool(s.showOnStartup), nil } func (s *Service) ShowSplashScreen(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("ShowSplashScreen") + s.log.Debug("ShowSplashScreen") if s.bridge.IsFirstStart() { return wrapperspb.Bool(false), nil @@ -124,13 +124,13 @@ func (s *Service) ShowSplashScreen(context.Context, *emptypb.Empty) (*wrapperspb } func (s *Service) IsFirstGuiStart(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("IsFirstGuiStart") + s.log.Debug("IsFirstGuiStart") return wrapperspb.Bool(s.bridge.GetBool(settings.FirstStartGUIKey)), nil } func (s *Service) SetIsAutostartOn(_ context.Context, isOn *wrapperspb.BoolValue) (*emptypb.Empty, error) { - s.log.WithField("show", isOn.Value).Info("SetIsAutostartOn") + s.log.WithField("show", isOn.Value).Debug("SetIsAutostartOn") defer func() { _ = s.SendEvent(NewToggleAutostartFinishedEvent()) }() @@ -156,13 +156,13 @@ func (s *Service) SetIsAutostartOn(_ context.Context, isOn *wrapperspb.BoolValue } func (s *Service) IsAutostartOn(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("IsAutostartOn") + s.log.Debug("IsAutostartOn") return wrapperspb.Bool(s.bridge.IsAutostartEnabled()), nil } func (s *Service) SetIsBetaEnabled(_ context.Context, isEnabled *wrapperspb.BoolValue) (*emptypb.Empty, error) { - s.log.WithField("isEnabled", isEnabled.Value).Info("SetIsBetaEnabled") + s.log.WithField("isEnabled", isEnabled.Value).Debug("SetIsBetaEnabled") channel := updater.StableChannel if isEnabled.Value { @@ -176,13 +176,13 @@ func (s *Service) SetIsBetaEnabled(_ context.Context, isEnabled *wrapperspb.Bool } func (s *Service) IsBetaEnabled(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("IsBetaEnabled") + s.log.Debug("IsBetaEnabled") return wrapperspb.Bool(s.bridge.GetUpdateChannel() == updater.EarlyChannel), nil } func (s *Service) SetIsAllMailVisible(_ context.Context, isVisible *wrapperspb.BoolValue) (*emptypb.Empty, error) { - s.log.WithField("isVisible", isVisible.Value).Info("SetIsAllMailVisible") + s.log.WithField("isVisible", isVisible.Value).Debug("SetIsAllMailVisible") s.bridge.SetIsAllMailVisible(isVisible.Value) @@ -190,18 +190,18 @@ func (s *Service) SetIsAllMailVisible(_ context.Context, isVisible *wrapperspb.B } func (s *Service) IsAllMailVisible(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("IsAllMailVisible") + s.log.Debug("IsAllMailVisible") return wrapperspb.Bool(s.bridge.IsAllMailVisible()), nil } func (s *Service) GoOs(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("GoOs") // TO-DO We can probably get rid of this and use QSysInfo::product name + s.log.Debug("GoOs") // TO-DO We can probably get rid of this and use QSysInfo::product name return wrapperspb.String(runtime.GOOS), nil } func (s *Service) TriggerReset(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { - s.log.Info("TriggerReset") + s.log.Debug("TriggerReset") go func() { defer s.panicHandler.HandlePanic() s.triggerReset() @@ -210,12 +210,12 @@ func (s *Service) TriggerReset(context.Context, *emptypb.Empty) (*emptypb.Empty, } func (s *Service) Version(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("Version") + s.log.Debug("Version") return wrapperspb.String(constants.Version), nil } func (s *Service) LogsPath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("LogsPath") + s.log.Debug("LogsPath") path, err := s.bridge.ProvideLogsPath() if err != nil { s.log.WithError(err).Error("Cannot determine logs path") @@ -225,7 +225,7 @@ func (s *Service) LogsPath(context.Context, *emptypb.Empty) (*wrapperspb.StringV } func (s *Service) LicensePath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("LicensePath") + s.log.Debug("LicensePath") return wrapperspb.String(s.bridge.GetLicenseFilePath()), nil } @@ -242,7 +242,7 @@ func (s *Service) LandingPageLink(context.Context, *emptypb.Empty) (*wrapperspb. } func (s *Service) SetColorSchemeName(_ context.Context, name *wrapperspb.StringValue) (*emptypb.Empty, error) { - s.log.WithField("ColorSchemeName", name.Value).Info("SetColorSchemeName") + s.log.WithField("ColorSchemeName", name.Value).Debug("SetColorSchemeName") if !theme.IsAvailable(theme.Theme(name.Value)) { s.log.WithField("scheme", name.Value).Warn("Color scheme not available") @@ -255,7 +255,7 @@ func (s *Service) SetColorSchemeName(_ context.Context, name *wrapperspb.StringV } func (s *Service) ColorSchemeName(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("ColorSchemeName") + s.log.Debug("ColorSchemeName") current := s.bridge.Get(settings.ColorScheme) if !theme.IsAvailable(theme.Theme(current)) { @@ -267,7 +267,7 @@ func (s *Service) ColorSchemeName(context.Context, *emptypb.Empty) (*wrapperspb. } func (s *Service) CurrentEmailClient(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("CurrentEmailClient") + s.log.Debug("CurrentEmailClient") return wrapperspb.String(s.bridge.GetCurrentUserAgent()), nil } @@ -280,7 +280,7 @@ func (s *Service) ReportBug(_ context.Context, report *ReportBugRequest) (*empty "address": report.Address, "emailClient": report.EmailClient, "includeLogs": report.IncludeLogs, - }).Info("ReportBug") + }).Debug("ReportBug") go func() { defer func() { _ = s.SendEvent(NewReportBugFinishedEvent()) }() @@ -306,7 +306,7 @@ func (s *Service) ReportBug(_ context.Context, report *ReportBugRequest) (*empty } func (s *Service) ForceLauncher(_ context.Context, launcher *wrapperspb.StringValue) (*emptypb.Empty, error) { - s.log.WithField("launcher", launcher.Value).Info("ForceLauncher") + s.log.WithField("launcher", launcher.Value).Debug("ForceLauncher") go func() { defer s.panicHandler.HandlePanic() s.restarter.ForceLauncher(launcher.Value) @@ -315,7 +315,7 @@ func (s *Service) ForceLauncher(_ context.Context, launcher *wrapperspb.StringVa } func (s *Service) SetMainExecutable(_ context.Context, exe *wrapperspb.StringValue) (*emptypb.Empty, error) { - s.log.WithField("executable", exe.Value).Info("SetMainExecutable") + s.log.WithField("executable", exe.Value).Debug("SetMainExecutable") go func() { defer s.panicHandler.HandlePanic() s.restarter.SetMainExecutable(exe.Value) @@ -324,7 +324,7 @@ func (s *Service) SetMainExecutable(_ context.Context, exe *wrapperspb.StringVal } func (s *Service) Login(_ context.Context, login *LoginRequest) (*emptypb.Empty, error) { - s.log.WithField("username", login.Username).Info("Login") + s.log.WithField("username", login.Username).Debug("Login") go func() { defer s.panicHandler.HandlePanic() @@ -370,7 +370,7 @@ func (s *Service) Login(_ context.Context, login *LoginRequest) (*emptypb.Empty, } func (s *Service) Login2FA(_ context.Context, login *LoginRequest) (*emptypb.Empty, error) { - s.log.WithField("username", login.Username).Info("Login2FA") + s.log.WithField("username", login.Username).Debug("Login2FA") go func() { defer s.panicHandler.HandlePanic() @@ -423,7 +423,7 @@ func (s *Service) Login2FA(_ context.Context, login *LoginRequest) (*emptypb.Emp } func (s *Service) Login2Passwords(_ context.Context, login *LoginRequest) (*emptypb.Empty, error) { - s.log.WithField("username", login.Username).Info("Login2Passwords") + s.log.WithField("username", login.Username).Debug("Login2Passwords") go func() { defer s.panicHandler.HandlePanic() @@ -445,7 +445,7 @@ func (s *Service) Login2Passwords(_ context.Context, login *LoginRequest) (*empt } func (s *Service) LoginAbort(_ context.Context, loginAbort *LoginAbortRequest) (*emptypb.Empty, error) { - s.log.WithField("username", loginAbort.Username).Info("LoginAbort") + s.log.WithField("username", loginAbort.Username).Debug("LoginAbort") go func() { defer s.panicHandler.HandlePanic() @@ -456,7 +456,7 @@ func (s *Service) LoginAbort(_ context.Context, loginAbort *LoginAbortRequest) ( } func (s *Service) CheckUpdate(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { - s.log.Info("CheckUpdate") + s.log.Debug("CheckUpdate") go func() { defer s.panicHandler.HandlePanic() @@ -466,7 +466,7 @@ func (s *Service) CheckUpdate(context.Context, *emptypb.Empty) (*emptypb.Empty, } func (s *Service) InstallUpdate(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { - s.log.Info("InstallUpdate") + s.log.Debug("InstallUpdate") go func() { defer s.panicHandler.HandlePanic() @@ -477,7 +477,7 @@ func (s *Service) InstallUpdate(context.Context, *emptypb.Empty) (*emptypb.Empty } func (s *Service) SetIsAutomaticUpdateOn(_ context.Context, isOn *wrapperspb.BoolValue) (*emptypb.Empty, error) { - s.log.WithField("isOn", isOn.Value).Info("SetIsAutomaticUpdateOn") + s.log.WithField("isOn", isOn.Value).Debug("SetIsAutomaticUpdateOn") currentlyOn := s.bridge.GetBool(settings.AutoUpdateKey) if currentlyOn == isOn.Value { @@ -495,25 +495,25 @@ func (s *Service) SetIsAutomaticUpdateOn(_ context.Context, isOn *wrapperspb.Boo } func (s *Service) IsAutomaticUpdateOn(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("IsAutomaticUpdateOn") + s.log.Debug("IsAutomaticUpdateOn") return wrapperspb.Bool(s.bridge.GetBool(settings.AutoUpdateKey)), nil } func (s *Service) IsCacheOnDiskEnabled(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("IsCacheOnDiskEnabled") + s.log.Debug("IsCacheOnDiskEnabled") return wrapperspb.Bool(s.bridge.GetBool(settings.CacheEnabledKey)), nil } func (s *Service) DiskCachePath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("DiskCachePath") + s.log.Debug("DiskCachePath") return wrapperspb.String(s.bridge.Get(settings.CacheLocationKey)), nil } func (s *Service) ChangeLocalCache(ctx context.Context, change *ChangeLocalCacheRequest) (*emptypb.Empty, error) { s.log.WithField("enableDiskCache", change.EnableDiskCache). WithField("diskCachePath", change.DiskCachePath). - Info("DiskCachePath") + Debug("DiskCachePath") restart := false defer func(willRestart *bool) { @@ -565,7 +565,7 @@ func (s *Service) ChangeLocalCache(ctx context.Context, change *ChangeLocalCache } func (s *Service) SetIsDoHEnabled(_ context.Context, isEnabled *wrapperspb.BoolValue) (*emptypb.Empty, error) { - s.log.WithField("isEnabled", isEnabled.Value).Info("SetIsDohEnabled") + s.log.WithField("isEnabled", isEnabled.Value).Debug("SetIsDohEnabled") s.bridge.SetProxyAllowed(isEnabled.Value) @@ -573,13 +573,13 @@ func (s *Service) SetIsDoHEnabled(_ context.Context, isEnabled *wrapperspb.BoolV } func (s *Service) IsDoHEnabled(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { - s.log.Info("IsDohEnabled") + s.log.Debug("IsDohEnabled") return wrapperspb.Bool(s.bridge.GetProxyAllowed()), nil } func (s *Service) SetUseSslForSmtp(ctx context.Context, useSsl *wrapperspb.BoolValue) (*emptypb.Empty, error) { //nolint:revive,stylecheck - s.log.WithField("useSsl", useSsl.Value).Info("SetUseSslForSmtp") + s.log.WithField("useSsl", useSsl.Value).Debug("SetUseSslForSmtp") if s.bridge.GetBool(settings.SMTPSSLKey) == useSsl.Value { return &emptypb.Empty{}, nil @@ -593,31 +593,31 @@ func (s *Service) SetUseSslForSmtp(ctx context.Context, useSsl *wrapperspb.BoolV } func (s *Service) UseSslForSmtp(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error) { //nolint:revive,stylecheck - s.log.Info("UseSslForSmtp") + s.log.Debug("UseSslForSmtp") return wrapperspb.Bool(s.bridge.GetBool(settings.SMTPSSLKey)), nil } func (s *Service) Hostname(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("Hostname") + s.log.Debug("Hostname") return wrapperspb.String(bridge.Host), nil } func (s *Service) ImapPort(context.Context, *emptypb.Empty) (*wrapperspb.Int32Value, error) { - s.log.Info("ImapPort") + s.log.Debug("ImapPort") return wrapperspb.Int32(int32(s.bridge.GetInt(settings.IMAPPortKey))), nil } func (s *Service) SmtpPort(context.Context, *emptypb.Empty) (*wrapperspb.Int32Value, error) { //nolint:revive,stylecheck - s.log.Info("SmtpPort") + s.log.Debug("SmtpPort") return wrapperspb.Int32(int32(s.bridge.GetInt(settings.SMTPPortKey))), nil } func (s *Service) ChangePorts(ctx context.Context, ports *ChangePortsRequest) (*emptypb.Empty, error) { - s.log.WithField("imapPort", ports.ImapPort).WithField("smtpPort", ports.SmtpPort).Info("ChangePorts") + s.log.WithField("imapPort", ports.ImapPort).WithField("smtpPort", ports.SmtpPort).Debug("ChangePorts") s.bridge.SetInt(settings.IMAPPortKey, int(ports.ImapPort)) s.bridge.SetInt(settings.SMTPPortKey, int(ports.SmtpPort)) @@ -628,12 +628,12 @@ func (s *Service) ChangePorts(ctx context.Context, ports *ChangePortsRequest) (* } func (s *Service) IsPortFree(_ context.Context, port *wrapperspb.Int32Value) (*wrapperspb.BoolValue, error) { - s.log.Info("IsPortFree") + s.log.Debug("IsPortFree") return wrapperspb.Bool(ports.IsPortFree(int(port.Value))), nil } func (s *Service) AvailableKeychains(context.Context, *emptypb.Empty) (*AvailableKeychainsResponse, error) { - s.log.Info("AvailableKeychains") + s.log.Debug("AvailableKeychains") keychains := make([]string, 0, len(keychain.Helpers)) for chain := range keychain.Helpers { @@ -644,7 +644,7 @@ func (s *Service) AvailableKeychains(context.Context, *emptypb.Empty) (*Availabl } func (s *Service) SetCurrentKeychain(ctx context.Context, keychain *wrapperspb.StringValue) (*emptypb.Empty, error) { - s.log.WithField("keychain", keychain.Value).Info("SetCurrentKeyChain") // we do not check validity. + s.log.WithField("keychain", keychain.Value).Debug("SetCurrentKeyChain") // we do not check validity. defer func() { _, _ = s.Restart(ctx, &emptypb.Empty{}) }() defer func() { _ = s.SendEvent(NewKeychainChangeKeychainFinishedEvent()) }() @@ -658,7 +658,7 @@ func (s *Service) SetCurrentKeychain(ctx context.Context, keychain *wrapperspb.S } func (s *Service) CurrentKeychain(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { - s.log.Info("CurrentKeychain") + s.log.Debug("CurrentKeychain") return wrapperspb.String(s.bridge.GetKeychainApp()), nil } diff --git a/internal/frontend/grpc/service_stream.go b/internal/frontend/grpc/service_stream.go index 6acbd2a6..067131e1 100644 --- a/internal/frontend/grpc/service_stream.go +++ b/internal/frontend/grpc/service_stream.go @@ -28,7 +28,7 @@ import ( // RunEventStream implement the gRPC server->Client event stream. func (s *Service) RunEventStream(request *EventStreamRequest, server Bridge_RunEventStreamServer) error { - s.log.Info("Starting Event stream") + s.log.Debug("Starting Event stream") if s.eventStreamCh != nil { return status.Errorf(codes.AlreadyExists, "the service is already streaming") // TO-DO GODT-1667 decide if we want to kill the existing stream. @@ -50,13 +50,13 @@ func (s *Service) RunEventStream(request *EventStreamRequest, server Bridge_RunE for { select { case <-s.eventStreamDoneCh: - s.log.Info("Stop Event stream") + s.log.Debug("Stop Event stream") return nil case event := <-s.eventStreamCh: - s.log.WithField("event", event).Info("Sending event") + s.log.WithField("event", event).Debug("Sending event") if err := server.Send(event); err != nil { - s.log.Info("Stop Event stream") + s.log.Debug("Stop Event stream") return err } } diff --git a/internal/frontend/grpc/service_user.go b/internal/frontend/grpc/service_user.go index 9a6af477..19f2e62d 100644 --- a/internal/frontend/grpc/service_user.go +++ b/internal/frontend/grpc/service_user.go @@ -30,7 +30,7 @@ import ( ) func (s *Service) GetUserList(context.Context, *emptypb.Empty) (*UserListResponse, error) { - s.log.Info("GetUserList") + s.log.Debug("GetUserList") userIDs := s.bridge.GetUserIDs() userList := make([]*User, len(userIDs)) @@ -46,14 +46,14 @@ func (s *Service) GetUserList(context.Context, *emptypb.Empty) (*UserListRespons // If there are no active accounts. if len(userList) == 0 { - s.log.Info("No active accounts") + s.log.Debug("No active accounts") } return &UserListResponse{Users: userList}, nil } func (s *Service) GetUser(_ context.Context, userID *wrapperspb.StringValue) (*User, error) { - s.log.WithField("userID", userID).Info("GetUser") + s.log.WithField("userID", userID).Debug("GetUser") user, err := s.bridge.GetUserInfo(userID.Value) if err != nil { @@ -64,7 +64,7 @@ func (s *Service) GetUser(_ context.Context, userID *wrapperspb.StringValue) (*U } func (s *Service) SetUserSplitMode(_ context.Context, splitMode *UserSplitModeRequest) (*emptypb.Empty, error) { - s.log.WithField("UserID", splitMode.UserID).WithField("Active", splitMode.Active).Info("SetUserSplitMode") + s.log.WithField("UserID", splitMode.UserID).WithField("Active", splitMode.Active).Debug("SetUserSplitMode") user, err := s.bridge.GetUserInfo(splitMode.UserID) if err != nil { @@ -92,7 +92,7 @@ func (s *Service) SetUserSplitMode(_ context.Context, splitMode *UserSplitModeRe } func (s *Service) LogoutUser(_ context.Context, userID *wrapperspb.StringValue) (*emptypb.Empty, error) { - s.log.WithField("UserID", userID.Value).Info("LogoutUser") + s.log.WithField("UserID", userID.Value).Debug("LogoutUser") if _, err := s.bridge.GetUserInfo(userID.Value); err != nil { return nil, status.Errorf(codes.NotFound, "user not found %v", userID.Value) @@ -110,7 +110,7 @@ func (s *Service) LogoutUser(_ context.Context, userID *wrapperspb.StringValue) } func (s *Service) RemoveUser(_ context.Context, userID *wrapperspb.StringValue) (*emptypb.Empty, error) { - s.log.WithField("UserID", userID.Value).Info("RemoveUser") + s.log.WithField("UserID", userID.Value).Debug("RemoveUser") go func() { defer s.panicHandler.HandlePanic() @@ -125,7 +125,7 @@ func (s *Service) RemoveUser(_ context.Context, userID *wrapperspb.StringValue) } func (s *Service) ConfigureUserAppleMail(ctx context.Context, request *ConfigureAppleMailRequest) (*emptypb.Empty, error) { - s.log.WithField("UserID", request.UserID).WithField("Address", request.Address).Info("ConfigureUserAppleMail") + s.log.WithField("UserID", request.UserID).WithField("Address", request.Address).Debug("ConfigureUserAppleMail") restart, err := s.bridge.ConfigureAppleMail(request.UserID, request.Address) if err != nil {