AuroraRuntime/Source/Console/ConsoleFIO/ConsoleFIO.cpp
2023-07-09 21:21:49 +01:00

106 lines
2.0 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ConsoleFIO.cpp
Date: 2021-6-22
Author: Reece
Note: This file looks pretty grim now there is a FIO sink
***/
#include <Source/RuntimeInternal.hpp>
#include "ConsoleFIO.hpp"
#include "../Console.hpp"
#include <Source/Logging/Sinks/DirLogArchive.hpp>
namespace Aurora::Console::ConsoleFIO
{
static Logging::NewDirectorySinkUnique_t gFileSink;
static const auto & gLogConfig = gRuntimeConfig.console.fio;
static AuString GetLogDirectory(const AuString &type)
{
AuString path;
AuString procName;
if ((!gLogConfig.bWriteLogsToUserDir) || (!AuIOFS::GetProfileDomain(path)))
{
path = ".";
}
path += "/" + type + "/";
if (Process::GetProcName(procName))
{
path += procName;
path.push_back('/');
}
else
{
path += "Unknown/";
}
return path;
}
AuString GetLogDirectory()
{
return GetLogDirectory("Logs");
}
AuString GetTelemetryDirectory()
{
return GetLogDirectory("Telemetry");
}
static void CompressLogs()
{
// TODO: write XZ's
}
void Flush()
{
if (!gFileSink)
{
return;
}
gFileSink->OnFlush();
}
static bool OpenLogFile()
{
gFileSink = NewDirectorySinkUnique(GetLogDirectory(), gRuntimeConfig.console.fio.defaultFileLogger);
return static_cast<bool>(gFileSink);
}
void FIOCleanup()
{
//CleanupOldLogs();
//CompressLogs();
}
void Init()
{
if (!gLogConfig.bEnableLogging)
{
return;
}
if (!OpenLogFile())
{
return;
}
Console::AddDefaultLogger(AuUnsafeRaiiToShared(gFileSink));
}
void Pump()
{
}
void Exit()
{
Flush();
gFileSink.reset();
}
}