aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util/log.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-13 20:52:08 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-13 20:52:08 +0200
commitf9aa198eef7b85eeba3bac4c4fe2d4578b836bbf (patch)
tree3d374caa0510aa6389bd5901b83fe5b5b81d6dc1 /src/crepe/util/log.cpp
parent5d041cce13da66aa3457d236579a9ac90ebf7618 (diff)
WIP behavior script (problems)
Diffstat (limited to 'src/crepe/util/log.cpp')
-rw-r--r--src/crepe/util/log.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp
index f91d52c..b46620d 100644
--- a/src/crepe/util/log.cpp
+++ b/src/crepe/util/log.cpp
@@ -4,6 +4,7 @@
#include <string>
#include "log.h"
+#include "fmt.h"
using namespace crepe::util;
@@ -14,37 +15,27 @@ static const char * const LOG_PREFIX[] = {
[log_level::ERROR] = "[ERR] ",
};
-static void va_logf(enum log_level level, va_list args, const std::string fmt) {
- va_list args_copy;
- va_copy(args_copy, args);
-
- // prepend log level and ensure newline
- std::string format_fixed = LOG_PREFIX[level] + fmt;
- if (!format_fixed.ends_with("\n")) format_fixed += "\n";
-
- size_t sz = vsnprintf(NULL, 0, format_fixed.c_str(), args_copy) + 1;
- char * msg = (char *) malloc(sz);
- va_end(args_copy);
-
- vsnprintf(msg, sz, format_fixed.c_str(), args);
+static void log(enum log_level level, const std::string msg) {
+ using namespace std;
+ string final = string(LOG_PREFIX[level]) + msg;
+ if (!final.ends_with("\n")) final += "\n";
// TODO: also log to file or smth
- printf("%s", msg);
+ printf("%s", final.c_str());
fflush(stdout);
-
- free(msg);
}
void crepe::util::logf(const char * fmt, ...) {
va_list args;
va_start(args, fmt);
- va_logf(crepe::util::log_level::DEBUG, args, fmt);
+ log(log_level::DEBUG, va_stringf(args, fmt));
va_end(args);
}
void crepe::util::logf(log_level level, const char * fmt, ...) {
va_list args;
va_start(args, fmt);
- va_logf(level, args, fmt);
+ log(level, va_stringf(args, fmt));
va_end(args);
}
+