Logging: route setLogger through a common_log sink (patch 0014); quiet agent console - #447
Merged
Merged
Conversation
setLogger was a llama_log_set() callback, which had two holes: every model load runs common_init(), which re-points llama_log_set() at llama.cpp's own default callback, so a logger set before `new LlamaModel(...)` was silently dropped; and the server's SRV_*/SLT_* lines (`slot print_timing` etc.) are LOG_INF macros writing straight into common_log, which llama_log_set() never carried, so they always went to stderr no matter what Java configured. That is why LlamaModelTest#testLogText/testLogJSON had been @disabled. Patch 0014 adds common_log_set_callback(log, cb, user_data) to common/log. While set, the worker hands every entry to the callback instead of printing it (a --log-file still receives them); swapping pauses the worker first, so queued entries reach the previous sink. setLogger now installs that sink plus llama_log_set(common_log_default_callback), so both the server's and the llama/ggml lines arrive, common_init()'s reset becomes a no-op, and setLogger(format, null) is a synchronous drain. The trampoline attaches the (unowned, re-created) worker thread per call and detaches again; the sink swap happens outside g_log_mutex because the pause joins the worker. Guards: six C++ tests over a private common_log instance (link on every platform, so a dropped patch reds C++ Tests), the model-free LlamaLoggerTest (a logger set before a deliberately failing load sees the srv INFO and llama ERROR lines, TEXT and JSON), the two re-enabled LlamaModelTest log tests and testLoggerSetBeforeLoadSurvivesTheLoad (vocab-only load). Docs: setLogger Javadoc + README "Logging" no longer claim JSON to stdout as the default (it is text on stderr); enableLogPrefix/enableLogTimestamps are documented as the no-ops common_init() makes them, setLogFile as additive, setLogVerbosity with the -lv scale; CLAUDE.md patch and test tables; TODO's common_log paragraph; CHANGELOG. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UVwj2UuMPybiK1bHyG9toH
llama.cpp writes its log to stderr, the console the streamed answer goes to on stdout, so at its default threshold (INFO) the per-request `slot print_timing` lines landed in the middle of the answer in --model mode. The in-process model is now loaded with --log-verbosity 2 (warnings and errors); `--log-verbosity <n>` and `--verbose`/`-v` override it. `--base-url` mode is unaffected (the server keeps its own -lv). Also add .mvn/jvm.config with -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8: on Windows, common_init() switches the console to UTF-8 after the JVM fixed its stdout encoding from the old code page, which turned umlauts and emoji in answers into "�" and "?". Tests: AgentOptionsTest (threshold parsing, the flag and its short form), LocalAgentTest (the flags that leave modelParameters(): the default stays below INFO, --verbose replaces the threshold). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UVwj2UuMPybiK1bHyG9toH
bernardladenthin
had a problem deploying
to
maven-central
September 21, 2026 16:57 — with
GitHub Actions
Failure
bernardladenthin
had a problem deploying
to
startgate
September 21, 2026 16:57 — with
GitHub Actions
Error
bernardladenthin
had a problem deploying
to
maven-central
September 21, 2026 16:57 — with
GitHub Actions
Failure
6 tasks
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LlamaModel.setLoggerwas silently overridden by every model load and never received the server's ownsrv …/slot …lines.common_init()(run on each load) re-pointsllama_log_set()at llama.cpp's default callback, so a logger set beforenew LlamaModel(…)was dropped; and theSRV_*/SLT_*macros write straight intocommon_log, whichllama_log_set()never carried. Newpatches/0014-common-log-callback-sink.patchaddscommon_log_set_callback()tocommon/log.{h,cpp};setLoggernow installs that sink (plusllama_log_set(common_log_default_callback)), so it survives loads, receives every line, replaces the console instead of duplicating it, andsetLogger(format, null)is a synchronous drain. The trampoline attaches/detaches the unowned log worker thread per call; the sink swap happens outsideg_log_mutex(the pause joins the worker).llama-atmosphere-agent:--log-verbosity <n>(default2) and--verbose/-vfor--modelmode, so llama.cpp's per-request INFO lines (stderr) no longer interleave with the streamed answer (stdout)..mvn/jvm.configpins-Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8: on Windowscommon_init()switches the console to UTF-8 after the JVM fixed its stdout code page, which rendered umlauts/emoji as�/?.setLoggerJavadoc and README "Logging" claimed JSON-to-stdout as the default (it is text on stderr);enableLogPrefix()/enableLogTimestamps()documented as the no-opscommon_init()makes them,setLogFileas additive,setLogVerbositywith the-lvscale; CLAUDE.md patch + test tables, TODO, CHANGELOG.Behaviour change to know: the verbosity threshold now applies before the callback (as on the console), so llama/ggml INFO lines reach a Java logger only from
setLogVerbosity(4)on.Test plan
ctest558/558 (6 new intest_common_log_callback.cpp); model-freeLlamaLoggerTest3/3 against the freshlibjllama(logger set before a deliberately failing load sees thesrv … loading modelINFO and llama's ERROR line, TEXT and JSON); core Java suite 1769 green / 272 model-gated skipped; agent suite 27 green / 3 model-gated skipped; spotless, spotbugs, javadoc, clang-format 23.1.1 clean.LlamaModelTest#testLogText/#testLogJSONand the new#testLoggerSetBeforeLoadSurvivesTheLoadneed the 7B model and run only in CI.Related issues / PRs
Follow-up to #444 / #445 / #446 (the Atmosphere agent), where the interleaved
slot print_timinglines were noticed.Checklist
CONTRIBUTING.mdandCODE_OF_CONDUCT.mdSECURITY.md)🤖 Generated with Claude Code
https://claude.ai/code/session_01UVwj2UuMPybiK1bHyG9toH
Generated by Claude Code