Skip to content

Logging: route setLogger through a common_log sink (patch 0014); quiet agent console - #447

Merged
bernardladenthin merged 2 commits into
mainfrom
claude/jolly-noether-jlebto
Sep 21, 2026
Merged

bernardladenthin merged 2 commits into
mainfrom
claude/jolly-noether-jlebto

Conversation

@bernardladenthin

Copy link
Copy Markdown
Owner

Summary

  • LlamaModel.setLogger was silently overridden by every model load and never received the server's own srv … / slot … lines. common_init() (run on each load) re-points llama_log_set() at llama.cpp's default callback, so a logger set before new LlamaModel(…) was dropped; and the SRV_*/SLT_* macros write straight into common_log, which llama_log_set() never carried. New patches/0014-common-log-callback-sink.patch adds common_log_set_callback() to common/log.{h,cpp}; setLogger now installs that sink (plus llama_log_set(common_log_default_callback)), so it survives loads, receives every line, replaces the console instead of duplicating it, and setLogger(format, null) is a synchronous drain. The trampoline attaches/detaches the unowned log worker thread per call; the sink swap happens outside g_log_mutex (the pause joins the worker).
  • llama-atmosphere-agent: --log-verbosity <n> (default 2) and --verbose/-v for --model mode, so llama.cpp's per-request INFO lines (stderr) no longer interleave with the streamed answer (stdout). .mvn/jvm.config pins -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8: on Windows common_init() switches the console to UTF-8 after the JVM fixed its stdout code page, which rendered umlauts/emoji as /?.
  • Docs corrected: setLogger Javadoc and README "Logging" claimed JSON-to-stdout as the default (it is text on stderr); enableLogPrefix()/enableLogTimestamps() documented as the no-ops common_init() makes them, setLogFile as additive, setLogVerbosity with the -lv scale; 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

  • Affected unit / integration tests pass locally — real native build (b11069 + all 9 patches) in the sandbox: ctest 558/558 (6 new in test_common_log_callback.cpp); model-free LlamaLoggerTest 3/3 against the fresh libjllama (logger set before a deliberately failing load sees the srv … loading model INFO 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.
  • CI is green on this branch — the re-enabled LlamaModelTest#testLogText / #testLogJSON and the new #testLoggerSetBeforeLoadSurvivesTheLoad need the 7B model and run only in CI.
  • Docs / CHANGELOG updated where applicable

Related issues / PRs

Follow-up to #444 / #445 / #446 (the Atmosphere agent), where the interleaved slot print_timing lines were noticed.

Checklist

  • I have read CONTRIBUTING.md and CODE_OF_CONDUCT.md
  • My commits follow Conventional Commits
  • No security-sensitive changes (if there are, I have notified the maintainer privately per SECURITY.md)

🤖 Generated with Claude Code

https://claude.ai/code/session_01UVwj2UuMPybiK1bHyG9toH


Generated by Claude Code

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
bernardladenthin merged commit 1580a00 into main Sep 21, 2026
7 of 16 checks passed
@bernardladenthin
bernardladenthin deleted the claude/jolly-noether-jlebto branch September 21, 2026 17:04

This branch had an error being deployed

1 failed deployment
maven-central 218609aa Deployed Sep 21, 2026 by bernardladenthin via Verify GPG signing key (no secrets printed) #979
startgate 218609aa Deployed Sep 21, 2026 by bernardladenthin via Start gate (abort window) #979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants