Favicon of spdlog

spdlog

spdlog is a header-only or compiled C++ logging library with fast performance, async mode, and multiple log sinks.

spdlog website screenshot
spdlog GitHub repository preview

spdlog is a C++ logging library built for speed, with either a header-only or compiled setup. It targets C++ developers who need fast, formatted logging in applications ranging from small tools to multi-threaded services, without pulling in a heavyweight logging framework.

It uses the fmt library for formatting, which means log calls support positional args, padding, hex/octal/binary output, and custom formatters for user-defined types. Logging can be synchronous or asynchronous, and log levels can be toggled at compile time or runtime, including loading them from environment variables or argv.

Key features

  • Speed: designed and benchmarked for very fast logging, in both sync and async modes.
  • Header-only or compiled: use as a drop-in header set, or build it as a library for faster compile times.
  • fmt-based formatting: positional args, numeric padding, hex/bin/oct output, and custom type formatters via fmt::formatter.
  • Multiple sinks: rotating files, daily files, console (with colors), syslog, Windows event log, Windows debugger output, Qt widgets, and custom sinks.
  • Async logging: optional background thread pool with configurable queue size and overflow policy.
  • Runtime and compile-time log level control: change levels globally or per logger, and strip calls out of release builds with SPDLOG_ACTIVE_LEVEL.
  • Backtrace support: buffer debug messages in a ring buffer and dump them on demand, e.g. when an error occurs.
  • Custom pattern formatting: define your own flags in the log pattern format string.
  • Periodic flush: flush all registered thread-safe loggers on a timer.
  • File event hooks: run callbacks before/after a log file opens or closes.
  • Multi-sink loggers: attach several sinks to one logger, each with its own level and format.
  • Cross-platform: Linux, FreeBSD, OpenBSD, Solaris, AIX, Windows (MSVC 2013+, cygwin), macOS (clang 3.5+), and Android.

Ideal use cases

spdlog fits any C++11+ project that needs structured, fast logging without adopting a large framework: CLI tools, servers, game engines, embedded-adjacent applications, and libraries that want to expose logging hooks to consumers. It's a good fit when you need multiple output targets (console + rotating file + syslog) with per-sink formatting and levels, or when you need async logging so log writes don't block hot paths.

It's also useful for debugging workflows where you want to keep a ring buffer of recent debug messages and only dump them when an error condition triggers, avoiding noisy always-on debug logging.

It is not the right choice if you need built-in structured logging (JSON-first) as the primary output format, centralized log aggregation/shipping, or a logging solution for non-C++ codebases. If your project targets pre-C++11 compilers, spdlog won't work since it requires C++11 at minimum. For projects that want zero third-party dependency exposure, note that spdlog pulls in the fmt library (bundled or external).

Installation

Header-only version: copy the include/spdlog folder into your build tree and compile with a C++11-capable compiler.

Compiled version (recommended for faster compile times):

$ git clone https://github.com/gabime/spdlog.git
$ cd spdlog && mkdir build && cd build
$ cmake .. && cmake --build .

See the example CMakeLists.txt in the example folder for integration details.

Package managers:

# Debian
sudo apt install libspdlog-dev
# Homebrew
brew install spdlog
# vcpkg
vcpkg install spdlog
# conan
conan install --requires=spdlog/[*]
# conda
conda install -c conda-forge spdlog

Other supported package managers include MacPorts, FreeBSD pkg, Fedora dnf, Gentoo emerge, Arch pacman, openSUSE zypper, ALT Linux apt-get, and build2.

Basic usage after install:

#include "spdlog/spdlog.h"

int main() {
    spdlog::info("Welcome to spdlog!");
    spdlog::error("Some error message with arg: {}", 1);
}
Categories:

Frequently asked questions

Share:

Stars
29.5K
Forks
5.4K
Last commit
19 days ago
Repository age
12 years
Self-hosted
No
Activity score
85/100
View Repository
Ad
Favicon

 

  
 

Similar to spdlog

Favicon

 

  
 
Favicon

 

  
 
Favicon