提交 5e178c12 编写于 作者: J jp9000

UI: Insert timestamps after log newlines

It was a bit weird seeing lines in the log without the associated
timestamps, so it should just insert it after every newline instead.
上级 7bb430ef
......@@ -185,6 +185,37 @@ string CurrentDateTimeString()
return buf;
}
static inline void LogString(fstream &logFile, const char *timeString,
char *str)
{
logFile << timeString << str << endl;
}
static inline void LogStringChunk(fstream &logFile, char *str)
{
char *nextLine = str;
string timeString = CurrentTimeString();
timeString += ": ";
while (*nextLine) {
char *nextLine = strchr(str, '\n');
if (!nextLine)
break;
if (nextLine != str && nextLine[-1] == '\r') {
nextLine[-1] = 0;
} else {
nextLine[0] = 0;
}
LogString(logFile, timeString.c_str(), str);
nextLine++;
str = nextLine;
}
LogString(logFile, timeString.c_str(), str);
}
static void do_log(int log_level, const char *msg, va_list args, void *param)
{
fstream &logFile = *static_cast<fstream*>(param);
......@@ -205,7 +236,7 @@ static void do_log(int log_level, const char *msg, va_list args, void *param)
#endif
if (log_level <= LOG_INFO)
logFile << CurrentTimeString() << ": " << str << endl;
LogStringChunk(logFile, str);
#ifdef _WIN32
if (log_level <= LOG_ERROR && IsDebuggerPresent())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册