AuroraRuntime/Source/Console/ConsoleFIO/ConsoleFIO.cpp

106 lines
2.1 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.writeLogsToUserDir) || (!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(), AuLog::DirectoryLogger {(AuUInt32)gRuntimeConfig.console.fio.maxLogsBeforeCompress, (AuUInt32)gRuntimeConfig.console.fio.maxLogs, gRuntimeConfig.console.fio.maxSizeMB});
return static_cast<bool>(gFileSink);
}
void FIOCleanup()
{
//CleanupOldLogs();
//CompressLogs();
}
void Init()
{
if (!gLogConfig.enableLogging)
{
return;
}
if (!OpenLogFile())
{
return;
}
Console::AddDefaultLogger(AuUnsafeRaiiToShared(gFileSink));
}
void Pump()
{
}
void Exit()
{
Flush();
gFileSink.reset();
}
}