Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 26, 2026·3 min de lecture

spdlog — Super Fast C++ Logging Library

A very fast, header-only or compiled, C++ logging library with fmt-style formatting and multiple sink targets.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
spdlog Overview
Commande d'installation directe
npx -y tokrepo@latest install 4a927595-5898-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

spdlog is one of the fastest C++ logging libraries available, designed around the fmt formatting library. It supports synchronous and asynchronous logging to consoles, files, syslog, and custom sinks while keeping API surface minimal and intuitive.

What spdlog Does

  • Logs messages with microsecond timestamps using lock-free queues for async mode
  • Formats output via the {fmt} library with compile-time format checking
  • Rotates log files by size or daily schedule automatically
  • Supports multiple named loggers each with independent sinks and levels
  • Provides colored console output on all major platforms

Architecture Overview

spdlog separates concerns into loggers, sinks, and formatters. A logger holds one or more sinks (console, file, syslog, etc.) and a formatter that renders the log record. In async mode, log records are pushed to a thread-safe ring buffer and flushed by a dedicated worker thread, minimizing latency on the hot path.

Self-Hosting & Configuration

  • Header-only mode: include spdlog headers and compile; no library linking needed
  • Compiled mode: build as a static/shared library for faster compile times in large projects
  • CMake support via find_package(spdlog) or FetchContent
  • Configure log pattern with strftime-like tokens: spdlog::set_pattern("[%H:%M:%S.%e] [%l] %v")
  • Thread-safe by default; optional _mt (multi-thread) and _st (single-thread) sink variants

Key Features

  • Benchmarked at millions of log lines per second in async mode
  • Built-in rotating, daily, and basic file sinks out of the box
  • Backtrace support: store debug messages in ring buffer, dump on error
  • Compile-time log level elimination to remove overhead in release builds
  • MIT licensed with no dependencies beyond {fmt} (bundled)

Comparison with Similar Tools

  • glog (Google) — feature-rich but heavier; uses CHECK macros and signal handlers
  • Boost.Log — very flexible but complex configuration and slow compile times
  • log4cxx — Java Log4j port for C++; XML config, larger binary
  • plog — header-only and simple but fewer sinks and no async support
  • Quill — newer async logger with similar speed; less adoption so far

FAQ

Q: Header-only or compiled — which should I choose? A: Use header-only for small projects. For large codebases, compiled mode reduces recompilation when only log calls change.

Q: Is spdlog thread-safe? A: Yes. The default sinks are multi-thread safe. Use _st variants if you guarantee single-thread access for a small speed boost.

Q: Can I write my own sink? A: Yes. Subclass spdlog::sinks::base_sink<Mutex> and override sink_it_() and flush_().

Q: Does async logging guarantee no message loss? A: By default the async queue blocks when full. You can configure an overflow policy to drop oldest messages instead.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires