mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 22:16:58 +02:00
cleanup time in log prefix
This commit is contained in:
parent
02b8ef2a05
commit
705d3da089
1 changed files with 8 additions and 12 deletions
|
@ -10,8 +10,6 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#define getpid _getpid
|
#define getpid _getpid
|
||||||
|
@ -21,6 +19,7 @@
|
||||||
#include <unistd.h> // for getpid() on linux
|
#include <unistd.h> // for getpid() on linux
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <qdatetime.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qtimer.h>
|
#include <qtimer.h>
|
||||||
|
|
||||||
|
@ -38,6 +37,10 @@ LogHandler::LogHandler() :
|
||||||
QTimer* logFlushTimer = new QTimer(this);
|
QTimer* logFlushTimer = new QTimer(this);
|
||||||
connect(logFlushTimer, &QTimer::timeout, this, &LogHandler::flushRepeatedMessages);
|
connect(logFlushTimer, &QTimer::timeout, this, &LogHandler::flushRepeatedMessages);
|
||||||
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
||||||
|
|
||||||
|
// when the log handler is first setup we should print our timezone
|
||||||
|
QString timezoneString = "Time zone: " + QDateTime::currentDateTime().toString("t");
|
||||||
|
printf("%s\n", qPrintable(timezoneString));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* stringForLogType(LogMsgType msgType) {
|
const char* stringForLogType(LogMsgType msgType) {
|
||||||
|
@ -57,8 +60,8 @@ const char* stringForLogType(LogMsgType msgType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the following will produce 2000-10-02 13:55:36 -0700
|
// the following will produce 11/18 13:55:36
|
||||||
const char DATE_STRING_FORMAT[] = "%Y-%m-%d %H:%M:%S %z";
|
const QString DATE_STRING_FORMAT = "MM/dd hh:mm:ss";
|
||||||
|
|
||||||
void LogHandler::flushRepeatedMessages() {
|
void LogHandler::flushRepeatedMessages() {
|
||||||
QHash<QString, int>::iterator message = _repeatMessageCountHash.begin();
|
QHash<QString, int>::iterator message = _repeatMessageCountHash.begin();
|
||||||
|
@ -112,14 +115,7 @@ QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& cont
|
||||||
|
|
||||||
QString prefixString = QString("[%1]").arg(stringForLogType(type));
|
QString prefixString = QString("[%1]").arg(stringForLogType(type));
|
||||||
|
|
||||||
time_t rawTime;
|
prefixString.append(QString(" [%1]").arg(QDateTime::currentDateTime().toString(DATE_STRING_FORMAT)));
|
||||||
time(&rawTime);
|
|
||||||
struct tm* localTime = localtime(&rawTime);
|
|
||||||
|
|
||||||
char dateString[100];
|
|
||||||
strftime(dateString, sizeof(dateString), DATE_STRING_FORMAT, localTime);
|
|
||||||
|
|
||||||
prefixString.append(QString(" [%1]").arg(dateString));
|
|
||||||
|
|
||||||
if (_shouldOutputPID) {
|
if (_shouldOutputPID) {
|
||||||
prefixString.append(QString(" [%1").arg(getpid()));
|
prefixString.append(QString(" [%1").arg(getpid()));
|
||||||
|
|
Loading…
Reference in a new issue