172 lines
3.3 KiB
C++
Executable File
172 lines
3.3 KiB
C++
Executable File
// License: Modified MIT (NON-AI)
|
|
// See the LICENSE file in the root directory for license information.
|
|
// Copyright 2025 Timothy Prepscius
|
|
|
|
#if defined(TJP_CORE_HEADER_ONLY)
|
|
#pragma once
|
|
#endif
|
|
|
|
#include "Log.h"
|
|
#include <fstream>
|
|
|
|
#include "../system/System.h"
|
|
|
|
#if defined(SYS_IOS) || defined(SYS_MAC)
|
|
// #define USE_OSX_LOG
|
|
#endif
|
|
|
|
#if defined(USE_OSX_LOG)
|
|
#include <os/log.h>
|
|
#endif
|
|
|
|
namespace tjp::core::log {
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void ActivateStory (const Story &s)
|
|
{
|
|
getManager().stories.activate(s);
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void setExternalDebugPrint(TimPrepsciusCoreLogExternalPrintPtr f)
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
manager.external.debugger = f;
|
|
});
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void setExternalLogPrint(TimPrepsciusCoreLogExternalPrintPtr f)
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
manager.external.log = f;
|
|
});
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void setExternalConsolePrint(TimPrepsciusCoreLogExternalPrintPtr f)
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
manager.external.console = f;
|
|
});
|
|
}
|
|
|
|
// ------------------------------
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void Start ()
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
if (manager.settings.LogToFileActivated)
|
|
manager.file.start();
|
|
});
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void RotateTo(const std::string_view &fileName)
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
if (manager.settings.LogToFileActivated)
|
|
manager.file.rotateTo(fileName);
|
|
});
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void Rotate()
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
if (manager.settings.LogToFileActivated)
|
|
manager.file.rotate();
|
|
});
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void ActivateStory_(const Story &s)
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
manager.stories.activate(s);
|
|
});
|
|
}
|
|
|
|
//---------------------------------------------------
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void ActivateStories (const std::string &filename)
|
|
{
|
|
std::ifstream in(filename.c_str());
|
|
|
|
if (!in)
|
|
return;
|
|
|
|
while (!in.eof())
|
|
{
|
|
char line[80];
|
|
in.getline(line, 80);
|
|
line[79]='\0';
|
|
|
|
for (int i=0;i<80; i++)
|
|
{
|
|
if (line[i] == '\r' || line[i]=='\n' || line[i]=='#' || line[i] =='\0')
|
|
{
|
|
line[i] = '\0';
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (line[0] == 0)
|
|
continue;
|
|
|
|
xLogActivateStory(line);
|
|
}
|
|
}
|
|
|
|
// ---
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void Initialize (const Settings &settings_)
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
manager.settings = settings_;
|
|
});
|
|
|
|
Start();
|
|
}
|
|
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void Initialize (const std::string &fileName)
|
|
{
|
|
getManager().with_lock([&](auto &manager) {
|
|
auto &settings = manager.settings;
|
|
|
|
settings.LogFileName = fileName;
|
|
settings.LogToFileActivated = !fileName.empty();
|
|
settings.LogToConsoleActivated = !settings.LogToFileActivated;
|
|
settings.LogToDebuggerActivated = false;
|
|
|
|
settings.LogInExecutableDirectory = false;
|
|
});
|
|
|
|
Start();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void setExternalDebuggerPrint(TimPrepsciusCoreLogExternalPrintPtr f)
|
|
{
|
|
tjp::core::log::setExternalDebugPrint(f);
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void setExternalLogPrint(TimPrepsciusCoreLogExternalPrintPtr f)
|
|
{
|
|
tjp::core::log::setExternalLogPrint(f);
|
|
}
|
|
|
|
TJP_CORE_HEADER_ONLY_INLINE
|
|
void setExternalConsolePrint(TimPrepsciusCoreLogExternalPrintPtr f)
|
|
{
|
|
tjp::core::log::setExternalConsolePrint(f);
|
|
}
|