Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AGenUI AGenUI IRuntimeLogger

From Leeroopedia
Knowledge Sources
Domains Cross_Platform, Logging
Last Updated 2026-10-24 17:21 GMT

Overview

Abstract logger interface and injection API for routing AGenUI SDK diagnostic logs to platform-native logging systems, provided by the AGenUI C++ core.

Description

The `IRuntimeLogger` interface defines the contract for runtime diagnostic logging in the AGenUI SDK. The C++ core depends on this abstraction, not on any concrete logging implementation. Platform layers (iOS, Android, HarmonyOS) implement the interface and inject their concrete instance via `IAGenUIEngine::setRuntimeLogger()`.

The interface has two key members:

  • `log(level, tag, func, line, format, ...)`: the variadic log method. Receives log level, tag, source function name, line number, and a printf-style format string.
  • `getMinLevel()`: returns the minimum log level to process. This is checked at the call site before variadic formatting, making it a hot-path performance optimization. Default returns `LOG_LEVEL_DEBUG` (no filtering).

If no custom logger is set, the SDK uses a built-in `DefaultLogger` that routes to platform-native logging (Android `Log`, Harmony `HiLog`, Apple `printf`).

The `AGenUIEngine` exposes `setRuntimeLogger(IRuntimeLogger*)` and `getRuntimeLogger()`. Passing `nullptr` restores the default logger.

Usage

  • Platform integration: implement `IRuntimeLogger` to bridge to Android `Log`, iOS `os_log`, or Harmony `HiLog`.
  • Telemetry routing: implement the interface to capture SDK logs for a crash reporter or analytics pipeline.
  • Log filtering: override `getMinLevel()` to return an atomic-backed field, enabling runtime level changes.
  • Restore default: call `engine->setRuntimeLogger(nullptr)` to revert to built-in logging.

Code Reference

Source Location

  • Repository: AGenUI
  • Interface: `core/include/agenui_logger_interface.h`
  • Default impl: `core/src/agenui_logger_internal.cpp`
  • Engine API: `core/include/agenui_engine.h` (setRuntimeLogger/getRuntimeLogger)
  • Engine impl: `core/src/module/agenui_engine_impl.cpp`

Signature

// core/include/agenui_logger_interface.h
namespace agenui {

enum LogLevel {
    LOG_LEVEL_DEBUG,
    LOG_LEVEL_INFO,
    LOG_LEVEL_WARN,
    LOG_LEVEL_ERROR,
    LOG_LEVEL_FATAL,
    LOG_LEVEL_PERFORMANCE,
};

class IRuntimeLogger {
public:
    virtual void log(LogLevel level, const char* tag, const char* func,
                     int line, const char* format, ...) = 0;
    virtual LogLevel getMinLevel() const { return LOG_LEVEL_DEBUG; }
};

// Engine injection API (IAGenUIEngine)
virtual void setRuntimeLogger(IRuntimeLogger* logger) = 0;
virtual IRuntimeLogger* getRuntimeLogger() = 0;

} // namespace agenui

Import

#include "agenui_logger_interface.h"
#include "agenui_engine.h"

I/O Contract

Inputs

Name Type Required Description
logger `IRuntimeLogger*` No Custom logger impl, or nullptr to restore default
level `LogLevel` Yes Log severity level enum
tag `const char*` Yes Log tag string
format `const char*` Yes printf-style format string

Outputs

Name Type Description
getMinLevel() returns `LogLevel` Minimum log level; messages below this are filtered
getRuntimeLogger() returns `IRuntimeLogger*` Active logger (never null, falls back to default)

Usage Examples

Android Logger Implementation

#include "agenui_logger_interface.h"
#include <android/log.h>

class AndroidLogger : public agenui::IRuntimeLogger {
    std::atomic<agenui::LogLevel> _minLevel{agenui::LOG_LEVEL_INFO};

public:
    void log(agenui::LogLevel level, const char* tag, const char* func,
             int line, const char* format, ...) override {
        if (level < _minLevel.load()) return;

        va_list args;
        va_start(args, format);
        __android_log_vprint(toAndroidPriority(level), tag, format, args);
        va_end(args);
    }

    agenui::LogLevel getMinLevel() const override {
        return _minLevel.load();
    }

    void setMinLevel(agenui::LogLevel level) {
        _minLevel.store(level);
    }
};

Injecting the Logger

// Create and inject custom logger
auto* engine = agenui::initAGenUIEngine();
auto* myLogger = new AndroidLogger();
engine->setRuntimeLogger(myLogger);

// All AGENUI_LOG calls now route through AndroidLogger
// ...
engine->setRuntimeLogger(nullptr);  // restore default
delete myLogger;

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment