Files
SirHumza--orbisRPC/installer/dbglog.cpp
T
CyberMask367 55d8df0c28 Rebuild installer as a full setup app
Replace the standalone wizard with a graphical installer featuring settings, update checks, install and uninstall flows, and optional GoldHEN and nanoDNS configuration. Add the packaging and artwork pipeline, preserve user settings across config updates, and include additional custom title mappings.
2026-10-15 23:06:19 +01:00

69 lines
1.1 KiB
C++

#include "dbglog.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <SDL2/SDL.h>
namespace {
bool g_started = false;
// Opens for append, truncating on the first call of the run.
FILE *Open(bool truncate)
{
if (truncate)
return fopen(kLogPath, "w");
return fopen(kLogPath, "a");
}
} // namespace
namespace dbglog
{
void Begin()
{
FILE *f = Open(true);
if (!f)
{
// Worth surfacing: if this fails, nothing below will be readable either.
SDL_Log("dbglog: cannot open %s for writing: %s", kLogPath,
strerror(errno));
return;
}
g_started = true;
fprintf(f, "---- orbisRPC menu log, pid %d ----\n", (int)getpid());
fclose(f);
}
void Write(const char *fmt, ...)
{
char line[512];
va_list ap;
va_start(ap, fmt);
vsnprintf(line, sizeof line, fmt, ap);
va_end(ap);
SDL_Log("%s", line);
FILE *f = Open(false);
if (!f)
return;
fprintf(f, "%s\n", line);
// Closed rather than flushed so the line is definitely on disk even if the
// process dies on the next instruction.
fclose(f);
}
} // namespace dbglog