summaryrefslogtreecommitdiff
path: root/src/debug/log.hpp
blob: 71a958ea6af5b1c50f628970d14eb26479001a77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include "../io/IOManager.hpp"
#include "format.hpp"
#include <print>
#include <string>

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 <typename... Args>
void log(FILE *_stream, eFormatType type, std::format_string<Args...> 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>(args)...)});
	else
		std::println(_stream, "{}", NFormatter::fmt(type, fmt, std::forward<Args>(args)...));
}

inline void log(eFormatType type, std::string str) {
	log(type == ERR ? stderr : stdout, type, str);
}

template <typename... Args>
void log(eFormatType type, std::format_string<Args...> fmt, Args &&...args) {
	log(type == ERR ? stderr : stdout, type, fmt, std::forward<Args>(args)...);
}