From 6f7b994684032060f0a2d7af82f4f3572293b8d6 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 12 Jun 2025 21:41:41 +0800 Subject: internal!: organized internal structure, using cmake now --- src/debug/log.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/debug/log.hpp (limited to 'src/debug/log.hpp') diff --git a/src/debug/log.hpp b/src/debug/log.hpp new file mode 100644 index 0000000..71a958e --- /dev/null +++ b/src/debug/log.hpp @@ -0,0 +1,37 @@ +#pragma once +#include "../io/IOManager.hpp" +#include "format.hpp" +#include +#include + +inline void log(FILE *_stream, eFormatType type, std::string str) { +#ifndef DEBUG + if (type == TRACE) + return; +#endif + if (g_pIOManager) + g_pIOManager->addLog({.type = type, .log = str}); + else + std::println(_stream, "{}", NFormatter::fmt(type, str)); +} + +template +void log(FILE *_stream, eFormatType type, std::format_string fmt, Args &&...args) { +#ifndef DEBUG + if (type == TRACE) + return; +#endif + if (g_pIOManager) + g_pIOManager->addLog({.type = type, .log = NFormatter::fmt(NONEWLINE, fmt, std::forward(args)...)}); + else + std::println(_stream, "{}", NFormatter::fmt(type, fmt, std::forward(args)...)); +} + +inline void log(eFormatType type, std::string str) { + log(type == ERR ? stderr : stdout, type, str); +} + +template +void log(eFormatType type, std::format_string fmt, Args &&...args) { + log(type == ERR ? stderr : stdout, type, fmt, std::forward(args)...); +} -- cgit v1.2.3