Skip to content

caliper.log.v1

Service id caliper.log.v1 — structured logs into the host console (PLATFORM.md §7.1); fuller semantics arrive at Task 13. This page embeds the header verbatim; the docs build fails if the file moves.

#pragma once
/* caliper.log.v1 — structured logs into the host console (PLATFORM.md §7.1).
 * IMMUTABLE once published: new capability = log_v2, alongside. */
#include <stdint.h>

#define CALIPER_LOG_V1 "caliper.log.v1"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum CaliperLogLevel {
    CALIPER_LOG_DEBUG = 0,
    CALIPER_LOG_INFO  = 1,
    CALIPER_LOG_WARN  = 2,
    CALIPER_LOG_ERROR = 3
} CaliperLogLevel;

typedef struct CaliperLogV1 {
    uint32_t struct_size;
    void (*log)(CaliperLogLevel level, const char* message_utf8); /* pre-formatted */
} CaliperLogV1;

#ifdef __cplusplus
}
#endif

Semantics

  • Pre-formatted lines. message_utf8 is a single, already-formatted UTF-8 line — no printf format string is interpreted, and no trailing newline is required (the host adds one). Do the formatting on the applet side and pass the finished string.
  • Where it goes today. The host stamps each line with a local HH:MM:SS timestamp and its level tag and writes it to stderr. A dedicated console panel is planned later; the ABI does not change when that lands — the same table keeps working.
  • Levels. level is one of CALIPER_LOG_DEBUG/INFO/WARN/ERROR; any value outside 0..3 is treated as INFO.
  • Threading. Unlike caliper.ui.v1, log() may be called from any thread the applet owns (e.g. a background worker). But the CaliperLogV1* table pointer itself must be obtained via get_service(CALIPER_LOG_V1) during initialize() and cached — resolve it on the UI thread, then call it from wherever you need to log.