mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Add time to logs. Redirect OSG log to OpenMW log.
This commit is contained in:
parent
e2213cbdb1
commit
5734551ff3
2 changed files with 68 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
#include "debugging.hpp"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include <components/crashcatcher/crashcatcher.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -60,15 +62,40 @@ namespace Debug
|
|||
|
||||
std::streamsize DebugOutputBase::write(const char *str, std::streamsize size)
|
||||
{
|
||||
if (size <= 0)
|
||||
return size;
|
||||
std::string_view msg{str, size_t(size)};
|
||||
|
||||
// Skip debug level marker
|
||||
Level level = getLevelMarker(str);
|
||||
if (level != NoLevel)
|
||||
msg = msg.substr(1);
|
||||
|
||||
char prefix[32];
|
||||
int prefixSize;
|
||||
{
|
||||
writeImpl(str+1, size-1, level);
|
||||
return size;
|
||||
prefix[0] = '[';
|
||||
uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
std::time_t t = ms / 1000;
|
||||
prefixSize = std::strftime(prefix + 1, sizeof(prefix) - 1, "%T", std::localtime(&t)) + 1;
|
||||
char levelLetter = " EWIVD*"[int(level)];
|
||||
prefixSize += snprintf(prefix + prefixSize, sizeof(prefix) - prefixSize,
|
||||
".%03u %c] ", static_cast<unsigned>(ms % 1000), levelLetter);
|
||||
}
|
||||
|
||||
while (!msg.empty())
|
||||
{
|
||||
if (msg[0] == 0)
|
||||
break;
|
||||
size_t lineSize = 1;
|
||||
while (lineSize < msg.size() && msg[lineSize - 1] != '\n')
|
||||
lineSize++;
|
||||
writeImpl(prefix, prefixSize, level);
|
||||
writeImpl(msg.data(), lineSize, level);
|
||||
msg = msg.substr(lineSize);
|
||||
}
|
||||
|
||||
writeImpl(str, size, NoLevel);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -172,6 +199,7 @@ int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, c
|
|||
// Restore cout and cerr
|
||||
std::cout.rdbuf(cout_rdbuf);
|
||||
std::cerr.rdbuf(cerr_rdbuf);
|
||||
Debug::CurrentDebugLevel = Debug::NoLevel;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue