finish refactor, add docs and CI
This commit is contained in:
+42
-16
@@ -1,10 +1,10 @@
|
||||
#include <nxst/infra/sys/logger.hpp>
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <mutex>
|
||||
|
||||
#include <nxst/infra/sys/logger.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
std::mutex g_log_mutex;
|
||||
@@ -15,8 +15,7 @@ constexpr const char* kLogPath = "/switch/NXST/log.log";
|
||||
constexpr const char* kLogPath = "nxst.log";
|
||||
#endif
|
||||
|
||||
void writeEntry(const char* tag, const char* fmt, va_list args)
|
||||
{
|
||||
void writeEntry(const char* tag, const char* fmt, va_list args) {
|
||||
char msg[2048];
|
||||
vsnprintf(msg, sizeof(msg), fmt, args);
|
||||
|
||||
@@ -37,18 +36,25 @@ void writeEntry(const char* tag, const char* fmt, va_list args)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
namespace nxst::log {
|
||||
|
||||
void write(Level level, const char* fmt, ...)
|
||||
{
|
||||
void write(Level level, const char* fmt, ...) {
|
||||
const char* tag = "[INFO] ";
|
||||
switch (level) {
|
||||
case Level::Debug: tag = "[DEBUG]"; break;
|
||||
case Level::Info: tag = "[INFO] "; break;
|
||||
case Level::Warn: tag = "[WARN] "; break;
|
||||
case Level::Error: tag = "[ERROR]"; break;
|
||||
case Level::Debug:
|
||||
tag = "[DEBUG]";
|
||||
break;
|
||||
case Level::Info:
|
||||
tag = "[INFO] ";
|
||||
break;
|
||||
case Level::Warn:
|
||||
tag = "[WARN] ";
|
||||
break;
|
||||
case Level::Error:
|
||||
tag = "[ERROR]";
|
||||
break;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
@@ -56,9 +62,29 @@ void write(Level level, const char* fmt, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void debug(const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[DEBUG]", fmt, args); va_end(args); }
|
||||
void info (const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[INFO] ", fmt, args); va_end(args); }
|
||||
void warn (const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[WARN] ", fmt, args); va_end(args); }
|
||||
void error(const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[ERROR]", fmt, args); va_end(args); }
|
||||
void debug(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
writeEntry("[DEBUG]", fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
void info(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
writeEntry("[INFO] ", fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
void warn(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
writeEntry("[WARN] ", fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
void error(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
writeEntry("[ERROR]", fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
} // namespace nxst::log
|
||||
} // namespace nxst::log
|
||||
|
||||
Reference in New Issue
Block a user