mirror of
https://github.com/liuk7071/ChonkyStation.git
synced 2024-05-20 12:57:52 -04:00
38 lines
1 KiB
C++
38 lines
1 KiB
C++
#pragma once
|
|
#include <cstdarg>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
namespace Log {
|
|
// Our logger class
|
|
template <bool enabled>
|
|
class Logger {
|
|
public:
|
|
Logger(std::string prepend = "") : prepend(prepend) {}
|
|
|
|
std::string prepend;
|
|
|
|
void log(const char* fmt, ...) {
|
|
if constexpr (!enabled) return;
|
|
|
|
std::fputs(prepend.c_str(), stdout);
|
|
std::va_list args;
|
|
va_start(args, fmt);
|
|
std::vprintf(fmt, args);
|
|
va_end(args);
|
|
}
|
|
};
|
|
|
|
// Our loggers here. Enable/disable by toggling the template param
|
|
static auto cpuTraceLogger = Logger<false>("[CPU TRACE] ");
|
|
static auto dmaLogger = Logger<false>("[ DMA ] ");
|
|
static auto gpuLogger = Logger<false>("[ GPU ] ");
|
|
static auto cdromLogger = Logger<true> ("[ CDROM ] ");
|
|
|
|
|
|
#define MAKE_LOG_FUNCTION(functionName, logger) \
|
|
template <typename... Args> \
|
|
void functionName(const char* fmt, Args... args) { \
|
|
Log::logger.log(fmt, args...); \
|
|
}
|
|
} |