$ show gabime/spdlog
spdlog is a high-performance, header-only or compiled C++ logging library. It provides synchronous and asynchronous logging to a wide variety of sinks including console (stdout/stderr with color), files (basic, rotating, daily, hourly), system facilities (syslog, systemd journal, Windows Event Log, Android), network (TCP, UDP, Kafka, Loki), and custom targets. The library uses the fmt library for formatting, supports custom pattern formatting with user-defined flags, backtrace logging, mapped diagnostic context (MDC), and configuration via environment variables or command-line arguments. It is designed for production use with extensive compile-time configuration options, thread safety, and minimal overhead. The architecture is modular: loggers manage a vector of sinks, each sink inherits from a base template that handles locking and formatting, and an optional async mode uses a thread pool with a bounded MPMC queue. The codebase is well-tested (Catch2) and benchmarked, with CI covering multiple compilers and platforms. It is a library, not an application, and is intended to be embedded into other C++ projects.
The LLM identified 5 files worth highlighting for reuse:
A simple, header-only circular queue template with fixed capacity. Provides push, pop, size, and capacity operations. It is self-contained, uses no internal spdlog dependencies, and can be extracted for use in any C++ project requiring a bounded FIFO buffer. Demonstrates clean template design and efficient memory management.
A bounded multi-producer multi-consumer blocking queue implemented with a circular buffer, mutex, and condition variables. Supports push with timeout and pop with timeout. It is self-contained (only depends on standard library and spdlog/common.h for types) and can be reused in any concurrent C++ project. Demonstrates careful handling of thread synchronization and overflow policies.
Provides platform-independent functions for file operations (open, close, read, write, rename, remove), thread ID retrieval, process ID, time utilities (gmtime, localtime, sleep), and terminal detection. It abstracts Windows and POSIX APIs behind a clean interface. This module is self-contained and can be extracted to provide cross-platform OS utilities for any C++ project.
Encapsulates file open/close, buffered writes, and rotation logic. Supports filename generation with timestamps, file size tracking, and automatic rotation. It depends only on os.h and common.h, making it reusable for any project needing file output with rotation. Demonstrates clean separation of file I/O concerns.
A template base class for implementing custom sinks. It provides thread-safe logging via a mutex (or null_mutex for single-threaded), automatic formatting using the pattern_formatter, and error handling. Implementers only need to override sink_it_() and flush_(). This pattern is a textbook example of the Template Method design pattern and can be reused to create new log targets with minimal boilerplate.