initialise a memory structure or smth

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-09-11 10:23:46 +05:30
parent 84c68a4e00
commit 332f0b87d6
26 changed files with 763 additions and 163 deletions

42
src/util/log.hh Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include <iomanip>
#include <iostream>
#include <source_location>
#include <streambuf>
namespace logging {
enum class Level {
Debug,
Info,
Warn,
Error,
};
class Logger {
public:
Logger(std::ostream& os = std::clog);
template<typename... Args>
void print(Level level, Args&&... args) {
set_level(level);
(os << ... << args);
reset_level();
os << std::endl;
}
private:
std::ostream& os;
void set_level(Level level);
void reset_level();
};
}
extern logging::Logger logger;
#define log_debug(...) logger.print(logging::Level::Debug, __VA_ARGS__)
#define log_info(...) logger.print(logging::Level::Info, __VA_ARGS__)
#define log_warn(...) logger.print(logging::Level::Warn, __VA_ARGS__)
#define log_error(...) logger.print(logging::Level::Error, __VA_ARGS__)
#define log(...) log_info(__VA_ARGS__)
#define debug(value) log_debug(#value, " = ", value)