Skip to content

feat: expose C API logging callback (audiocpp_log_set) - #1235

Merged
0xShug0 merged 2 commits into
0xShug0:mainfrom
kikaitachi:expose-log-callback
Nov 8, 2026
Merged

0xShug0 merged 2 commits into
0xShug0:mainfrom
kikaitachi:expose-log-callback

Conversation

@kikaitachi

Copy link
Copy Markdown
Contributor

Rationale

When embedding libaudiocpp in-process via the C ABI, underlying compute and backend libraries (such as GGML) write log, status, and debug messages directly to stderr by default using internal fallback callbacks.

In host applications that embed libaudiocpp alongside their own logging frameworks (e.g. Quill, spdlog, Android logcat, or GUI/service sinks), these unformatted stderr writes cannot be intercepted, redirected, formatted, or filtered by log level.

This PR adds an explicit logging callback API (audiocpp_log_set) modeled after the established pattern in llama.cpp (llama_log_set). It allows embedding applications to register a custom log handler with arbitrary user_data, or pass NULL to restore the default stderr behavior.

Changes

  • include/audiocpp.h:
    • Bumped AUDIOCPP_ABI_VERSION_MINOR from 2 to 3.
    • Added audiocpp_log_level enum (NONE, INFO, WARN, ERROR, DEBUG, CONT).
    • Added audiocpp_log_callback typedef.
    • Added audiocpp_log_set(audiocpp_log_callback log_callback, void * user_data).
  • src/capi/audiocpp.cpp:
    • Implemented audiocpp_log_set with thread-safe callback state forwarding to ggml_log_set.
  • tests/capi/path_test.c:
    • Added registration and reset test for audiocpp_log_set.
  • docs/c_api.md:
    • Added ## Logging usage documentation and ABI version check example for 0.3.
    • Updated export count to reflect 70 symbols.

Validation

Tested on Linux aarch64:

  • audiocpp_c_api_exports: Passed (exact match of declared symbols, 0 leaked).
  • audiocpp_c_api_path: Passed (asserts ABI contract and log callback registration/reset).

AI usage disclosure

Generated by Gemini Flash 3.8 Medium.

@0xShug0

0xShug0 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

@kikaitachi Thanks for the PR! Two minor issues: (1) GGML errors reach the custom callback as DEBUG messages. You can reproduce this through the C API by registering a log callback and loading an invalid GGUF. (2) The API documentation overpromises: it says both engine and GGML logs are redirected, but only GGML logging is wired up.

@kikaitachi

Copy link
Copy Markdown
Contributor Author

@0xShug0 Thank you for catching both of these!

  1. Enum alignment & mapping: Aligned audiocpp_log_level values with GGML (DEBUG=1, INFO=2, WARN=3, ERROR=4, CONT=5) and implemented explicit switch mapping functions (ggml_to_audiocpp_log_level and engine_to_audiocpp_log_level) rather than casting raw integer values. Added an assertion in tests/capi/path_test.c verifying that loading a corrupt GGUF invokes the callback with AUDIOCPP_LOG_LEVEL_ERROR.
  2. Engine debug logging: Added engine::debug::set_log_callback() in trace.h / trace.cpp and wired it up in audiocpp_log_set(), so internal engine debug logs and GGML backend logs are both routed to the registered callback.

@0xShug0
0xShug0 merged commit 3e2a4f4 into 0xShug0:main Nov 8, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

@kikaitachi PR merged. Thanks!

@kikaitachi
kikaitachi deleted the expose-log-callback branch November 9, 2026 12:57
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