diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-01-12 22:18:26 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-01-12 22:18:26 +0100 |
commit | 0be0e822e49ec89e29cac29ea67fe8e6e26cc08f (patch) | |
tree | be1b9a6b6ad3844131e625b698bda4dff8a9defd /logger/QsLog.cpp | |
parent | 55e5322fbeda2d07264cd9d9a910c7714aa5d025 (diff) | |
download | MultiMC-0be0e822e49ec89e29cac29ea67fe8e6e26cc08f.tar MultiMC-0be0e822e49ec89e29cac29ea67fe8e6e26cc08f.tar.gz MultiMC-0be0e822e49ec89e29cac29ea67fe8e6e26cc08f.tar.lz MultiMC-0be0e822e49ec89e29cac29ea67fe8e6e26cc08f.tar.xz MultiMC-0be0e822e49ec89e29cac29ea67fe8e6e26cc08f.zip |
GH-720 Add timestamps (since mmc start) to log
Diffstat (limited to 'logger/QsLog.cpp')
-rw-r--r-- | logger/QsLog.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/logger/QsLog.cpp b/logger/QsLog.cpp index 87d7a412..68493963 100644 --- a/logger/QsLog.cpp +++ b/logger/QsLog.cpp @@ -37,11 +37,7 @@ namespace QsLogging { typedef QList<Destination *> DestinationList; -static const char *LevelStrings[] = {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" - "UNKNOWN"}; - -// not using Qt::ISODate because we need the milliseconds too -static const QString fmtDateTime("hhhh:mm:ss.zzz"); +static const char *LevelStrings[] = {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "UNKNOWN"}; static const char *LevelToText(Level theLevel) { @@ -62,10 +58,12 @@ public: QMutex logMutex; Level level; DestinationList destList; + QDateTime startTime; }; Logger::Logger() : d(new LoggerImpl) { + d->startTime = QDateTime::currentDateTime(); } Logger::~Logger() @@ -89,13 +87,32 @@ Level Logger::loggingLevel() const return d->level; } +QDateTime Logger::timeOfStart() const +{ + return d->startTime; +} + +qint64 Logger::timeSinceStart() const +{ + return d->startTime.msecsTo(QDateTime::currentDateTime()); +} + + //! creates the complete log message and passes it to the logger void Logger::Helper::writeToLog() { const char *const levelName = LevelToText(level); - const QString completeMessage(QString("%1\t%2").arg(levelName, 5).arg(buffer)); - Logger &logger = Logger::instance(); + qint64 msecstotal = logger.timeSinceStart(); + qint64 seconds = msecstotal / 1000; + qint64 msecs = msecstotal % 1000; + QString foo; + char buf[1024]; + + ::snprintf(buf, 1024, "%5lld.%03lld", seconds, msecs); + + const QString completeMessage(QString("%1\t%2\t%3").arg(buf).arg(levelName, 5).arg(buffer)); + QMutexLocker lock(&logger.d->logMutex); logger.write(completeMessage); } |