spdlog日志庫(kù)
Very fast, header-only/compiled, C++ logging library.
Install
Header only version
Copy the include folder to your build tree and use a C++11 compiler.
Static lib version (recommended - much faster compile times)
$ git clone https://github.com/gabime/spdlog.git
$ cd spdlog && mkdir build && cd build
$ cmake .. && make -j
Platforms
Linux, FreeBSD, OpenBSD, Solaris, AIX
Windows (msvc 2013+, cygwin)
macOS (clang 3.5+)
Android
Package managers:
Debian:
sudo apt install libspdlog-dev
Homebrew:
brew install spdlog
MacPorts:
sudo port install spdlog
FreeBSD: ?
pkg install spdlog
Fedora:
dnf install spdlog
Gentoo:
emerge dev-libs/spdlog
Arch Linux:
pacman -S spdlog
vcpkg:
vcpkg install spdlog
conan:
spdlog/[>=1.4.1]
conda:
conda install -c conda-forge spdlog
build2:
depends: spdlog ^1.8.2
Features
Very fast (see benchmarks below).
Headers only or compiled
Feature rich formatting, using the excellent fmt library.
Asynchronous mode (optional)
Custom formatting.
Multi/Single threaded loggers.
Various log targets:
Rotating log files.
Daily log files.
Console logging (colors supported).
syslog.
Windows event log.
Windows debugger (
OutputDebugString(..)
).Easily extendable with custom log targets.
Log filtering - log levels can be modified in runtime as well as in compile time.
Support for loading log levels from argv or from environment var.
Backtrace support - store debug messages in a ring buffer and display later on demand.
Usage samples
Basic usage
Create stdout/stderr logger object
Basic file logger
Rotating files
Daily files
Backtrace support
Periodic flush
Stopwatch
Log binary data in hex
Logger with multi sinks - each with different format and log level
Asynchronous logging
Asynchronous logger with multi sinks
User defined types
User defined flags in the log pattern
Custom error handler
syslog
Android example
Load log levels from env variable or from argv
So then you can:
Log file open/close event handlers
Replace the Default Logger
Benchmarks
Asynchronous mode
python 輸入與輸出