|
VoltMod
C++23 framework for CS2 server plugins
|
Typedefs | |
| using | Handler = std::function< void(LogLevel level, std::string_view message)> |
| Where log lines end up. | |
Functions | |
| void | SetHandler (Handler handler) |
| bool | Enabled () |
| void | SetMinimumLevel (LogLevel level) |
| LogLevel | MinimumLevel () |
| bool | Wanted (LogLevel level) |
| void | Emit (LogLevel level, std::string message) |
| void | DeliverPending () |
| template<typename... Args> | |
| void | Info (std::format_string< Args... > fmt, Args &&... args) |
| template<typename... Args> | |
| void | Warn (std::format_string< Args... > fmt, Args &&... args) |
| template<typename... Args> | |
| void | Error (std::format_string< Args... > fmt, Args &&... args) |
Variables | |
| static Handler | g_handler |
| static std::thread::id | g_gameThread {} |
| static std::atomic< LogLevel > | g_minimumLevel {LogLevel::Info} |
| static std::mutex | g_deferredMutex |
| static std::deque< std::pair< LogLevel, std::string > > | g_deferred |
| static std::atomic< bool > | g_hasDeferred {false} |
| static constexpr size_t | MaxDeferred = 256 |
| void VoltMod::Log::DeliverPending | ( | ) |
Replay lines queued from worker threads. Game thread only; Runtime::OnGameFrame calls it.
Definition at line 69 of file Logger.cpp.
References g_deferred, g_deferredMutex, g_handler, g_hasDeferred, and VoltMod::ReadFile().
Referenced by VoltMod::Runtime::OnGameFrame(), and VoltMod::Runtime::~Runtime().
Route one formatted line to the handler.
The console handler reaches tier0's ConColorMsg/Msg, which is game-thread-only, but the database and HTTP workers log too. A line raised off the installing thread is queued instead and replayed by DeliverPending, so worker diagnostics still reach the console without a worker ever touching the engine.
Definition at line 47 of file Logger.cpp.
References g_deferred, g_deferredMutex, g_gameThread, g_handler, g_hasDeferred, MaxDeferred, and VoltMod::ReadFile().
Referenced by Error(), Info(), Warn(), and VoltMod::PluginContext::WriteLog().
| bool VoltMod::Log::Enabled | ( | ) |
True while a handler is installed. The gate the formatting helpers below check.
Definition at line 32 of file Logger.cpp.
References g_handler.
Referenced by Wanted().
| void VoltMod::Log::Error | ( | std::format_string< Args... > | fmt, |
| Args &&... | args | ||
| ) |
Definition at line 97 of file Log.hpp.
References Emit(), VoltMod::Error, VoltMod::ReadFile(), and Wanted().
Referenced by VoltMod::CommandRouter::Add(), VoltMod::AddonList(), VoltMod::Internal::HostCallback< Member >::Call(), VoltMod::Database::Connect(), VoltMod::InstalledPlugins::Discover(), VoltMod::EngineHooks::EngineHooks(), VoltMod::FindOptional(), VoltMod::FindPatternEx(), VoltMod::GameDataTable::GameDataTable(), VoltMod::EntitySystem::OnServerStartup(), VoltMod::ParsePattern(), VoltMod::PluginContext::RegisterCommand(), VoltMod::RunMigrations(), VoltMod::Json::Write(), and VoltMod::LazyHook::~LazyHook().
| void VoltMod::Log::Info | ( | std::format_string< Args... > | fmt, |
| Args &&... | args | ||
| ) |
Definition at line 79 of file Log.hpp.
References Emit(), VoltMod::Info, VoltMod::ReadFile(), and Wanted().
Referenced by VoltMod::PluginLoader::Defer(), VoltMod::EngineHooks::EngineHooks(), VoltMod::EntitySystem::EntitySystem(), VoltMod::HookFunction(), VoltMod::HookVirtual(), VoltMod::Translations::Load(), VoltMod::Options< TSettings, TSnapshot >::Load(), VoltMod::PluginLoader::LoadAll(), VoltMod::GameDataScanner::LogSummary(), VoltMod::EntitySystem::OnServerStartup(), VoltMod::GameEvents::OnServerStartup(), VoltMod::RunMigrations(), VoltMod::Host::Start(), VoltMod::WriteGameDataRecord(), VoltMod::Schema::WriteSchemaDump(), and VoltMod::Precache::WriteTo().
| LogLevel VoltMod::Log::MinimumLevel | ( | ) |
The level set by SetMinimumLevel; LogLevel::Info until one is.
Definition at line 42 of file Logger.cpp.
References g_minimumLevel.
Referenced by Wanted().
Install the process-wide handler and record the calling thread as the game thread.
Set once per load cycle by the plugin module, before anything else logs. A file-static rather than an injected service because logging must work from code that holds no runtime at all - static initializers, engine trampolines, and worker threads.
Definition at line 26 of file Logger.cpp.
References g_gameThread, g_handler, and VoltMod::ReadFile().
Referenced by VoltMod::Host::Start().
Drop lines below level.
The host decides what each plugin prints, and the SDK reads that back once a frame. Set here rather than checked per line so the formatting helpers can skip the whole std::format call.
Definition at line 37 of file Logger.cpp.
References g_minimumLevel, and VoltMod::ReadFile().
Whether a line at level would be printed at all.
Definition at line 56 of file Log.hpp.
References Enabled(), MinimumLevel(), and VoltMod::ReadFile().
| void VoltMod::Log::Warn | ( | std::format_string< Args... > | fmt, |
| Args &&... | args | ||
| ) |
Definition at line 88 of file Log.hpp.
References Emit(), VoltMod::ReadFile(), Wanted(), and VoltMod::Warn.
Referenced by VoltMod::WorkshopDownloads::Add(), VoltMod::ButtonPresses::ButtonPresses(), VoltMod::Map::ChangeLevel(), VoltMod::Map::ChangeToWorkshop(), VoltMod::Controller::ExecuteCommand(), VoltMod::ConVars::ExecuteServerCommand(), VoltMod::Validation::FallbackIfEmpty(), VoltMod::Validation::FallbackIfEmpty(), VoltMod::Validation::FilterValid(), VoltMod::FindPatternEx(), VoltMod::FindVirtualTable(), VoltMod::PlayerScreens::For(), VoltMod::GameEvents::GameEvents(), VoltMod::Pawn::GiveItem(), VoltMod::Map::IsValid(), VoltMod::Translations::Load(), VoltMod::GameDataScanner::LogSummary(), VoltMod::Validation::NormalizeTag(), VoltMod::GameEvents::OnServerStartup(), VoltMod::PlayerCommands::PlayerCommands(), VoltMod::PluginLoader::RequireLoaded(), VoltMod::RunMigrations(), VoltMod::HttpClient::Send(), VoltMod::VoteField(), VoltMod::WarnLeaks(), VoltMod::WriteGameDataRecord(), and VoltMod::Schema::WriteSchemaDump().
|
static |
Definition at line 17 of file Logger.cpp.
Referenced by DeliverPending(), and Emit().
|
static |
Definition at line 16 of file Logger.cpp.
Referenced by DeliverPending(), and Emit().
|
static |
Definition at line 12 of file Logger.cpp.
Referenced by Emit(), and SetHandler().
|
static |
Definition at line 11 of file Logger.cpp.
Referenced by DeliverPending(), Emit(), Enabled(), and SetHandler().
Read by DeliverPending every game frame, so the common empty case never takes the lock or builds a container. Only ever set true under g_deferredMutex.
Definition at line 20 of file Logger.cpp.
Referenced by DeliverPending(), and Emit().
|
static |
What the host wants from this module. Read on every log call, written once a frame.
Definition at line 14 of file Logger.cpp.
Referenced by MinimumLevel(), and SetMinimumLevel().
A worker that logs in a tight failure loop must not grow this without bound; past the cap the oldest lines go, because the first error is rarely the interesting one.
Definition at line 24 of file Logger.cpp.
Referenced by Emit().