VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ConsoleLogger.cpp
Go to the documentation of this file.
2
3#include <Color.h>
4#include <string_view>
5#include <tier0/dbg.h>
6#include <utility>
7
8namespace VoltMod
9{
10
12{
13 return [prefix = std::move(prefix)](LogLevel level, std::string_view message) {
14 switch (level)
15 {
16 case LogLevel::Info:
17 ConColorMsg(::Color(0, 255, 0, 255), "[%s] ", prefix.c_str());
18 break;
19 case LogLevel::Warn:
20 ConColorMsg(::Color(255, 255, 0, 255), "[%s] WARN: ", prefix.c_str());
21 break;
22 case LogLevel::Error:
23 ConColorMsg(::Color(255, 0, 0, 255), "[%s] ERROR: ", prefix.c_str());
24 break;
25 }
26 // string_view is not guaranteed null-terminated, so bound the format explicitly.
27 Msg("%.*s\n", static_cast<int>(message.size()), message.data());
28 };
29}
30
31} // namespace VoltMod
std::function< void(LogLevel level, std::string_view message)> Handler
Where log lines end up.
Definition Log.hpp:30
Log::Handler MakeConsoleHandler(std::string prefix)
The default handler: tier0 ConColorMsg/Msg, one colour per level.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
LogLevel
Definition Log.hpp:13