forked from kherud/java-llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog_helpers.hpp
More file actions
40 lines (34 loc) · 1.28 KB
/
Copy pathlog_helpers.hpp
File metadata and controls
40 lines (34 loc) · 1.28 KB
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
38
39
40
// SPDX-FileCopyrightText: 2026 Bernard Ladenthin <bernard.ladenthin@gmail.com>
// SPDX-FileCopyrightText: 2023-2025 Konstantin Herud
//
// SPDX-License-Identifier: MIT
#pragma once
// log_helpers.hpp — Pure log-formatting helpers.
//
// No JNI, no llama state. Depends only on the ggml_log_level enum (declared
// in ggml.h) and nlohmann/json. Unit-testable without a JVM or model.
#include "ggml.h"
#include "nlohmann/json.hpp"
#include <ctime>
#include <string>
// Returns the canonical short name for a ggml log level. INFO is the default
// fall-through to mirror llama.cpp's own log routing.
[[nodiscard]] inline const char *log_level_name(ggml_log_level level) {
switch (level) {
case GGML_LOG_LEVEL_ERROR: return "ERROR";
case GGML_LOG_LEVEL_WARN: return "WARN";
case GGML_LOG_LEVEL_DEBUG: return "DEBUG";
case GGML_LOG_LEVEL_INFO:
default: return "INFO";
}
}
// Pure variant taking an explicit timestamp so tests are deterministic.
[[nodiscard]] inline std::string format_log_as_json(
ggml_log_level level, const char *text, std::time_t timestamp) {
nlohmann::json log_obj = {
{"timestamp", timestamp},
{"level", log_level_name(level)},
{"message", text ? text : ""},
};
return log_obj.dump();
}