mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-22 18:16:43 +00:00
GODT-1893: bridge-gui sends bridge's log to stdout, stderr.
WIP: bridge-gui now parses and self-apply log level from command-line. WIP: downgraded the log level of gRPC calls to debug.
This commit is contained in:
@ -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<QPair<Log::Level, QString>> 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<QPair<Log::Level, QString>>::const_iterator it = std::find_if(logLevelStrings.begin(), logLevelStrings.end(),
|
||||
[&level](QPair<Log::Level, QString> 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<QPair<Log::Level, QString>>::const_iterator it = std::find_if(logLevelStrings.begin(), logLevelStrings.end(),
|
||||
[&str](QPair<Log::Level, QString> 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_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user