feat: add LLAMA_CPP_LOG_LEVEL to control log level of llama.cpp (#436)

release-0.2 v0.1.0
Meng Zhang 2023-09-12 22:41:39 +08:00 committed by GitHub
parent 1e7ecce697
commit 30afa19bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -100,8 +100,21 @@ class TextInferenceEngineImpl : public TextInferenceEngine {
owned<llama_context> ctx_; owned<llama_context> ctx_;
}; };
static int g_llama_cpp_log_level = 0;
static void llama_log_callback(llama_log_level level, const char * text, void * user_data) {
(void)user_data;
if (level < g_llama_cpp_log_level) {
fputs(text, stderr);
fflush(stderr);
}
}
struct BackendInitializer { struct BackendInitializer {
BackendInitializer() { BackendInitializer() {
if (const char* level = std::getenv("LLAMA_CPP_LOG_LEVEL")) {
g_llama_cpp_log_level = std::stoi(level);
}
llama_log_set(llama_log_callback, nullptr);
llama_backend_init(false); llama_backend_init(false);
} }