12 #include <source_location>
14 #include <string_view>
19 #ifdef PWN_LOG_USE_COLOR
20 #define PWN_COLOR_RESET "\033[0m "
21 #define PWN_COLOR_BOLD "\033[1m "
22 #define PWN_COLOR_UNDERLINE "\033[4m "
23 #define PWN_COLOR_FG_BLACK "\033[30m "
24 #define PWN_COLOR_FG_RED "\033[31m "
25 #define PWN_COLOR_FG_GREEN "\033[32m "
26 #define PWN_COLOR_FG_YELLOW "\033[33m "
27 #define PWN_COLOR_FG_BLUE "\033[34m "
28 #define PWN_COLOR_FG_MAGENTA "\033[35m "
29 #define PWN_COLOR_FG_CYAN "\033[36m "
30 #define PWN_COLOR_FG_WHITE "\033[37m "
32 #define PWN_COLOR_RESET ""
33 #define PWN_COLOR_BOLD ""
34 #define PWN_COLOR_UNDERLINE ""
35 #define PWN_COLOR_FG_BLACK ""
36 #define PWN_COLOR_FG_RED ""
37 #define PWN_COLOR_FG_GREEN ""
38 #define PWN_COLOR_FG_YELLOW ""
39 #define PWN_COLOR_FG_BLUE ""
40 #define PWN_COLOR_FG_MAGENTA ""
41 #define PWN_COLOR_FG_CYAN ""
42 #define PWN_COLOR_FG_WHITE ""
45 #define PWN_LOG_STRINGS_DEBUG "[ DEBUG ] "
46 #define PWN_LOG_STRINGS_INFO "[ INFO ] "
47 #define PWN_LOG_STRINGS_SUCCESS "[ SUCCESS ] "
48 #define PWN_LOG_STRINGS_WARN "[ WARN ] "
49 #define PWN_LOG_STRINGS_ERROR "[ ERROR ] "
50 #define PWN_LOG_STRINGS_CRITICAL "[ CRITICAL ] "
89 Log(
const LogLevel level, std::source_location
const& location, std::ostringstream& msg);
101 template<
typename... Args>
103 Log(
const LogLevel level, std::source_location
const& location, std::string_view
const& fmt, Args&&... args)
105 std::ostringstream msg;
106 msg << std::vformat(fmt, std::make_format_args(args...)) <<
'\n';
107 Log(level, location, msg);
119 Log(
const LogLevel level, std::source_location
const& location, std::wostringstream& msg);
131 template<
typename... Args>
133 Log(
const LogLevel level, std::source_location
const& location, std::wstring_view
const& fmt, Args&&... args)
135 std::wostringstream msg;
136 msg << std::vformat(fmt, std::make_wformat_args(args...)) << std::endl;
137 Log::Log(level, location, msg);
141 #ifdef PWN_BUILD_FOR_WINDOWS
149 template<
typename T = std::w
string>
151 FormatLastError(
const u32 gle) -> T
153 if constexpr ( std::is_same_v<T, std::wstring> )
155 wchar_t msg[1024] {0};
157 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
160 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
164 return std::wstring(msg);
167 if constexpr ( std::is_same_v<T, std::string> )
171 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
174 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
178 return std::string(msg);
181 throw std::bad_variant_access();
190 perror(
const std::wstring_view& prefix);
199 perror(
const std::string_view& prefix);
209 ntperror(
const std::wstring_view& prefix, NTSTATUS Status);
219 ntperror(
const std::string_view& prefix, NTSTATUS Status);
229 #define dbg(...) Log::Log(Log::LogLevel::Debug, std::source_location::current(), ##__VA_ARGS__)
230 #define info(...) Log::Log(Log::LogLevel::Info, std::source_location::current(), ##__VA_ARGS__)
231 #define ok(...) Log::Log(Log::LogLevel::Success, std::source_location::current(), ##__VA_ARGS__)
232 #define warn(...) Log::Log(Log::LogLevel::Warning, std::source_location::current(), ##__VA_ARGS__)
233 #define err(...) Log::Log(Log::LogLevel::Error, std::source_location::current(), ##__VA_ARGS__)
void Log(const LogLevel level, std::source_location const &location, std::ostringstream &msg)
Print an output string stream as a log message.
LogLevel
Define the logging level.
Definition: Log.hpp:60
@ Warning
Warning logging level
@ Critical
Critical logging level
@ Debug
Debug logging level