15std::ofstream g_logFile;
18bool g_explicitInit =
false;
20std::string nowStamp() {
21 using clock = std::chrono::system_clock;
22 const auto t = clock::to_time_t(clock::now());
30 std::strftime(buf,
sizeof(buf),
"%Y-%m-%d %H:%M:%S", &tm);
34std::string resolvePath(
const std::string& logDir) {
35 std::string
dir = logDir;
37 const char* env = std::getenv(
"EVE_LOG_DIR");
40 if (
dir.empty())
return "eve.log";
41 const char last =
dir.back();
42 return (last ==
'/' || last ==
'\\') ?
dir +
"eve.log" :
dir +
"/eve.log";
45void openLocked(
const std::string&
path,
bool explicitInit) {
46 g_logFile.open(
path, std::ios::app);
47 if (!g_logFile)
return;
49 g_explicitInit = explicitInit;
57void ensureOpenLocked() {
58 if (g_open || g_explicitInit)
return;
59 openLocked(resolvePath({}),
false);
65 std::lock_guard<std::mutex> lock(g_logMutex);
67 openLocked(resolvePath(logDir),
true);
71 std::lock_guard<std::mutex> lock(g_logMutex);
73 if (!g_open || !g_logFile)
return;
74 g_logFile <<
"[" << nowStamp() <<
"] " <<
level <<
" | " <<
message <<
"\n";
79 std::unique_lock<std::mutex> lock(g_logMutex, std::try_to_lock);
80 if (!lock.owns_lock())
return;
82 if (!g_open || !g_logFile)
return;
83 g_logFile <<
"[" << nowStamp() <<
"] crash | ";
84 g_logFile.write(report.data(),
static_cast<std::streamsize
>(report.size()));
85 if (report.empty() || report.back() !=
'\n') g_logFile <<
"\n";
90 std::lock_guard<std::mutex> lock(g_logMutex);
95 std::lock_guard<std::mutex> lock(g_logMutex);
97 if (!g_open || !g_logFile)
return;
Persistent, thread-safe record of engine crash and problem events.
Build metadata (engine git commit, build time, third-party version).
void recordSessionEnd(int exitCode)
Appends the session-end marker carrying the process exit code.
constexpr const char * kSessionStartMarker
Marker text that opens a session block in eve.log.
constexpr const char * kSessionEndMarker
Marker text that closes a session block (followed by the exit code). @ownership Borrowed pointer to a...
void recordSessionStart()
Appends a session-start marker.
void initSystemLogging(const std::string &logDir)
Opens (append) the crash/error log file and records a session marker.
void recordCrashEvent(const std::string &report)
Records a crash report, safe to call from a crash/exception handler.
std::string crashLogPath()
Path of the open crash/error log file.
void recordLogEvent(const std::string &level, const std::string &message)
Appends a timestamped event line to the crash/error log.