Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ggml org Llama cpp Log Header

From Leeroopedia
Revision as of 12:40, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Ggml_org_Llama_cpp_Log_Header.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Logging, Infrastructure
Last Updated 2026-02-15 00:00 GMT

Overview

Declares the logging API and convenience macros (LOG_DBG, LOG_INF, LOG_WRN, LOG_ERR) used throughout llama.cpp.

Description

Defines log level constants (DEBUG=4, INFO=3, WARN=2, ERROR=1, OUTPUT=0), ANSI color code macros, and the common_log opaque struct API for initialization, singleton access, pause, resume, and free. Configuration functions control file output, color mode (auto/enabled/disabled), prefix formatting, and timestamps. The LOG_TMPL macro checks the verbosity threshold before evaluating log arguments, avoiding expensive computations when messages would be discarded.

Usage

Include this header in any llama.cpp source file that needs to emit log messages at any level. Use the LOG_DBG, LOG_INF, LOG_WRN, and LOG_ERR macros for leveled logging, and the LOG macro for direct output. Configure verbosity thresholds, file output, color, prefix, and timestamp settings via the common_log_set_* functions.

Code Reference

Source Location

Signature

struct common_log * common_log_init();
struct common_log * common_log_main();
void                common_log_pause (struct common_log * log);
void                common_log_resume(struct common_log * log);
void                common_log_free  (struct common_log * log);
void common_log_add(struct common_log * log, enum ggml_log_level level, const char * fmt, ...);
void common_log_set_file      (struct common_log * log, const char * file);
void common_log_set_colors    (struct common_log * log, log_colors colors);
void common_log_set_prefix    (struct common_log * log, bool prefix);
void common_log_set_timestamps(struct common_log * log, bool timestamps);
void common_log_flush         (struct common_log * log);
void common_log_set_verbosity_thold(int verbosity);

Import

#include "log.h"

I/O Contract

Inputs

Name Type Required Description
log struct common_log * Yes Pointer to the log instance (or use common_log_main() for singleton)
level enum ggml_log_level Yes Log level for the message (DEBUG, INFO, WARN, ERROR, CONT, NONE)
fmt const char * Yes Printf-style format string for the log message
... variadic No Arguments matching the format string placeholders

Outputs

Name Type Description
log instance struct common_log * Returned by common_log_init() and common_log_main()
(side effect) void Messages are written to stdout/stderr and optionally to a log file

Usage Examples

#include "log.h"

// Basic leveled logging using convenience macros
LOG_INF("Model loaded with %d layers\n", n_layers);
LOG_DBG("Token %d mapped to piece: %s\n", token_id, piece.c_str());
LOG_WRN("KV cache nearly full: %d / %d\n", n_used, n_total);
LOG_ERR("Failed to load model: %s\n", path.c_str());

// Direct output (no level prefix)
LOG("Hello, world!\n");

// Configure the singleton logger
struct common_log * log = common_log_main();
common_log_set_file(log, "output.log");
common_log_set_colors(log, LOG_COLORS_ENABLED);
common_log_set_prefix(log, true);
common_log_set_timestamps(log, true);

Related Pages

Page Connections

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