/*** 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 #include "ConsoleFIO.hpp" #include "../Console.hpp" #include 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) { if (auto optProfileDomain = AuIOFS::GetProfileDomain()) { path = *optProfileDomain; } else { path = "."; } } else { path = "."; } path += "/" + type + "/"; if (auto pProcessName = Process::GetProcessName()) { path += *pProcessName; 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(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(); } }