127 lines
2.1 KiB
C++
Executable File
127 lines
2.1 KiB
C++
Executable File
// License: Modified MIT (NON-AI)
|
|
// See the LICENSE file in the root directory for license information.
|
|
// Copyright 2025 Timothy Prepscius
|
|
|
|
#pragma once
|
|
|
|
#include "../header_only/compile.h"
|
|
|
|
#include "../string/String.hpp"
|
|
#include "../string/StringView.hpp"
|
|
#include "../types/Types.h"
|
|
|
|
#include "../containers/List.hpp"
|
|
#include "../containers/Set.hpp"
|
|
|
|
#include "../const_hash/Hash.hpp"
|
|
|
|
#include <mutex>
|
|
|
|
namespace tjp::core::log::detail {
|
|
|
|
struct Manager;
|
|
|
|
struct Story
|
|
{
|
|
using Hash = u32;
|
|
Hash hash;
|
|
StringView name;
|
|
|
|
constexpr Story(const char *s) :
|
|
hash(hash_compile<Hash>(s)),
|
|
name(s)
|
|
{}
|
|
} ;
|
|
|
|
struct Settings
|
|
{
|
|
String LogFileName = "log.txt";
|
|
bool AppendToLogFile = false;
|
|
bool LogToFileActivated = false;
|
|
bool LogToDebuggerActivated = false;
|
|
bool LogToConsoleActivated = true;
|
|
bool LogInExecutableDirectory = false;
|
|
|
|
// zero for never rotate
|
|
u64 RotateSize = 10 * (1024 * 1024);
|
|
} ;
|
|
|
|
typedef void (*TimPrepsciusCoreLogExternalPrintPtr)(const StringView &);
|
|
|
|
|
|
struct External
|
|
{
|
|
TimPrepsciusCoreLogExternalPrintPtr debugger = nullptr;
|
|
TimPrepsciusCoreLogExternalPrintPtr log = nullptr;
|
|
TimPrepsciusCoreLogExternalPrintPtr console = nullptr;
|
|
} ;
|
|
|
|
struct Stories
|
|
{
|
|
bool all = false;
|
|
|
|
Set<Story> activated;
|
|
List<String> names;
|
|
|
|
void clear();
|
|
void activate(const Story &s);
|
|
bool isActivated (const Story &s);
|
|
} ;
|
|
|
|
struct File
|
|
{
|
|
struct I;
|
|
|
|
Manager *manager;
|
|
Settings &getSettings();
|
|
|
|
File (Manager *);
|
|
~File();
|
|
|
|
I *i;
|
|
u64 sizeWritten = 0;
|
|
|
|
void start();
|
|
void write(const StringView &s);
|
|
|
|
void checkRotate();
|
|
void rotate();
|
|
void rotateTo(const std::string_view &name);
|
|
} ;
|
|
|
|
struct Manager
|
|
{
|
|
using Mutex = std::mutex;
|
|
Mutex mutex;
|
|
|
|
External external;
|
|
Settings settings;
|
|
Stories stories;
|
|
File file;
|
|
|
|
bool termSupportsColor = false;
|
|
|
|
Manager();
|
|
|
|
void start();
|
|
void rotate();
|
|
void rotateTo(const StringView &);
|
|
|
|
void writeToLog(const StringView &);
|
|
void writeToDebugger(const StringView &);
|
|
void writeToConsole(const StringView &);
|
|
|
|
template<typename F>
|
|
auto with_lock(F &&f)
|
|
{
|
|
std::lock_guard<Mutex> lock(mutex);
|
|
f(*this);
|
|
}
|
|
} ;
|
|
|
|
Manager &getManager();
|
|
|
|
std::string methodName(const char *prettyFunction);
|
|
|
|
} // namespace
|