mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
Other: added timestamp to bridge-gui logs.
Changed format to be closer to logrus output.
This commit is contained in:
committed by
Romain LE JEUNE
parent
227e9df419
commit
a949a113cf
@ -30,7 +30,7 @@ namespace
|
|||||||
Log *qtHandlerLog { nullptr }; ///< The log instance handling qt logs.
|
Log *qtHandlerLog { nullptr }; ///< The log instance handling qt logs.
|
||||||
QMutex qtHandlerMutex; ///< A mutex used to access qtHandlerLog.
|
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.
|
// Mapping of log levels to string. Maybe used to lookup using both side a key, so a list of pair is more convenient that a map.
|
||||||
QList<QPair<Log::Level, QString>> const logLevelStrings {
|
QList<QPair<Log::Level, QString>> const logLevelStrings {
|
||||||
{ Log::Level::Panic, "panic", },
|
{ Log::Level::Panic, "panic", },
|
||||||
{ Log::Level::Fatal, "fatal", },
|
{ Log::Level::Fatal, "fatal", },
|
||||||
@ -96,15 +96,15 @@ void qtMessageHandler(QtMsgType type, QMessageLogContext const &, QString const
|
|||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
/// \brief return a string representing the log entry
|
/// \brief return a string representing the log entry, in a format similar to the one used by logrus.
|
||||||
///
|
///
|
||||||
/// \param[in] level The log entry level.
|
/// \param[in] level The log entry level.
|
||||||
/// \param[in] message The log entry message.
|
/// \param[in] message The log entry message.
|
||||||
/// \return The string for the log entry
|
/// \return The string for the log entry
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
QString Log::logEntryToString(Log::Level level, QString const &message)
|
QString Log::logEntryToString(Log::Level level, QDateTime const &dateTime, QString const &message)
|
||||||
{
|
{
|
||||||
return QString("[%1] %2").arg(levelToString(level).toUpper(), message);
|
return QString("%1[%2] %3").arg(levelToString(level).left(4).toUpper(), dateTime.toString("MMM dd HH:mm:ss.zzz"), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -303,15 +303,17 @@ void Log::trace(QString const &message)
|
|||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
void Log::addEntry(Log::Level level, QString const &message)
|
void Log::addEntry(Log::Level level, QString const &message)
|
||||||
{
|
{
|
||||||
|
QDateTime const dateTime = QDateTime::currentDateTime();
|
||||||
QMutexLocker locker(&mutex_);
|
QMutexLocker locker(&mutex_);
|
||||||
if (qint32(level) > qint32(level_))
|
if (qint32(level) > qint32(level_))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit entryAdded(level, message);
|
emit entryAdded(level, message);
|
||||||
|
|
||||||
if (!(echoInConsole_ || file_))
|
if (!(echoInConsole_ || file_))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString const entryStr = logEntryToString(level, message) + "\n";
|
QString const entryStr = logEntryToString(level, dateTime, message) + "\n";
|
||||||
if (echoInConsole_)
|
if (echoInConsole_)
|
||||||
{
|
{
|
||||||
QTextStream &stream = (qint32(level) <= (qint32(Level::Warn))) ? stderr_ : stdout_;
|
QTextStream &stream = (qint32(level) <= (qint32(Level::Warn))) ? stderr_ : stdout_;
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public: // data types.
|
|||||||
};
|
};
|
||||||
|
|
||||||
public: // static member functions.
|
public: // static member functions.
|
||||||
static QString logEntryToString(Log::Level level, QString const &message); ///< Return a string describing a log entry.
|
static QString logEntryToString(Log::Level level, QDateTime const &dateTime, QString const &message); ///< Return a string describing a log entry.
|
||||||
static QString levelToString(Log::Level level); ///< return the string for a level.
|
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.
|
static bool stringToLevel(QString const &str, Log::Level& outLevel); ///< parse a level from a string.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user