ScriptsMay 26, 2026·3 min read

spdlog — Super Fast C++ Logging Library

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

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
spdlog Overview
Direct install command
npx -y tokrepo@latest install 4a927595-5898-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets