# spdlog
Very fast, header-only/compiled, C++ logging library. [![ci](https://github.com/gabime/spdlog/actions/workflows/ci.yml/badge.svg)](https://github.com/gabime/spdlog/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/d2jnxclg20vd0o50?svg=true&branch=v1.x)](https://ci.appveyor.com/project/gabime/spdlog) [![Release](https://img.shields.io/github/release/gabime/spdlog.svg)](https://github.com/gabime/spdlog/releases/latest)
## Install
#### Header only version
Copy the include [folder](https://github.com/gabime/spdlog/tree/v1.x/include/spdlog) to your build tree and use a C++11 compiler.
#### Compiled version (recommended - much faster compile times)
```console
$ git clone https://github.com/gabime/spdlog.git
$ cd spdlog && mkdir build && cd build
$ cmake .. && make -j
```
see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/example/CMakeLists.txt) on how to use.
## 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`
* openSUSE: `sudo zypper in spdlog-devel`
* 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](#benchmarks) below).
* Headers only or compiled
* Feature rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library.
* Asynchronous mode (optional)
* [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) 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](https://github.com/gabime/spdlog/wiki/4.-Sinks#implementing-your-own-sink) 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](#backtrace-support) support - store debug messages in a ring buffer and display later on demand.
## Usage samples
#### Basic usage
```c++
#include "spdlog/spdlog.h"
int main()
{
spdlog::info("Welcome to spdlog!");
spdlog::error("Some error message with arg: {}", 1);
spdlog::warn("Easy padding in numbers like {:08d}", 12);
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
spdlog::info("Support for floats {:03.2f}", 1.23456);
spdlog::info("Positional args are {1} {0}..", "too", "supported");
spdlog::info("{:<30}", "left aligned");
spdlog::set_level(spdlog::level::debug); // Set global log level to debug
spdlog::debug("This message should be displayed..");
// change log pattern
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
// Compile time log levels
// define SPDLOG_ACTIVE_LEVEL to desired level
SPDLOG_TRACE("Some trace message with param {}", 42);
SPDLOG_DEBUG("Some debug message");
}
```
---
#### Create stdout/stderr logger object
```c++
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
void stdout_example()
{
// create color multi threaded logger
auto console = spdlog::stdout_color_mt("console");
auto err_logger = spdlog::stderr_color_mt("stderr");
spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");
}
```
---
#### Basic file logger
```c++
#include "spdlog/sinks/basic_file_sink.h"
void basic_logfile_example()
{
try
{
auto logger = spdlog::basic_logger_mt("basic_logger", "logs/basic-log.txt");
}
catch (const spdlog::spdlog_ex &ex)
{
std::cout << "Log init failed: " << ex.what() << std::endl;
}
}
```
---
#### Rotating files
```c++
#include "spdlog/sinks/rotating_file_sink.h"
void rotating_example()
{
// Create a file rotating logger with 5mb size max and 3 rotated files
auto max_size = 1048576 * 5;
auto max_files = 3;
auto logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", max_size, max_files);
}
```
---
#### Daily files
```c++
#include "spdlog/sinks/daily_file_sink.h"
void daily_example()
{
// Create a daily logger - a new file is created every day on 2:30am
auto logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
}
```
---
#### Backtrace support
```c++
// Debug messages can be stored in a ring buffer instead of being logged immediately.
// This is useful in order to display debug logs only when really needed (e.g. when error happens).
// When needed, call dump_backtrace() to dump them to your log.
spdlog::enable_backtrace(32); // Store the latest 32 messages in a buffer.
// or my_logger->enable_backtrace(32)..
for(int i = 0; i < 100; i++)
{
spdlog::debug("Backtrace message {}", i); // not logged yet..
}
// e.g. if some has error happened:
spdlog::dump_backtrace(); // log them now! show the last 32 messages
// or my_logger->dump_backtrace(32)..
```
---
#### Periodic flush
```c++
// periodically flush all *registered* loggers every 3 seconds:
// warning: only use if all your loggers are thread safe ("_mt" loggers)
spdlog::flush_every(std::chrono::seconds(3));
```
---
#### Stopwatch
```c++
// Stopwatch support for spdlog
#include "spdlog/stopwatch.h"
void stopwatch_example()
{
spdlog::stopwatch sw;
spdlog::debug("Elapsed {}", sw);
spdlog::debug("Elapsed {:.3}", sw);
}
```
---
#### Log binary data in hex
```c++
// many types of std::container<char> types can be used.
// ranges are supported too.
// format flags:
// {:X} - print in uppercase.
// {:s} - don't separate each byte with space.
// {:p} - don't print the position on each line start.
// {:n} - don't split the output to lines.
// {:a} - show ASCII if :n is not set.
#include "spdlog/fmt/bin_to_hex.h"
void binary_example()
{
auto console = spdlog::get("console");
std::array<char, 80> buf;
console->info("Binary example: {}", spdlog::to_hex(buf));
console->info("Another binary example:{:n}", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10));
// more examples:
// logger->info("uppercase: {:X}", spdlog::to_hex(buf));
// logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf));
// logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf));
}
```
---
#### Logger with multi sinks - each with different format and log level
```c++
// create logger with 2 targets with different log levels and formats.
// the console will show only warnings or errors, while the file will log all.
void multi_sink_example()
{
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::warn);
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
file_sink->set_level(spdlog::level::trace);
spdlog::logger logger("multi_sink", {console_sink, file_sink});
logger.set_level(spdlog::level::debug);
logger.warn("this should appear in both console and file");
logger.info("this message should not appear in the console, only in the file");
}
```
---
#### User defined callbacks about log events
```c++
// cr
没有合适的资源?快使用搜索试试~ 我知道了~
c++ 日志库spdlog 最新源代码
共167个文件
h:107个
cpp:35个
txt:4个
5星 · 超过95%的资源 需积分: 0 5 下载量 130 浏览量
2023-04-14
14:50:19
上传
评论
收藏 320KB ZIP 举报
温馨提示
c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志库spdlog 最新源代码c++ 日志
资源推荐
资源详情
资源评论
收起资源包目录
c++ 日志库spdlog 最新源代码 (167个子文件)
.clang-format 3KB
.clang-tidy 2KB
utils.cmake 3KB
spdlogCPack.cmake 3KB
ide.cmake 1KB
test_pattern_formatter.cpp 20KB
example.cpp 13KB
test_misc.cpp 10KB
bench.cpp 9KB
latency.cpp 8KB
test_file_helper.cpp 7KB
test_async.cpp 6KB
test_daily_logger.cpp 6KB
async_bench.cpp 6KB
test_cfg.cpp 5KB
test_errors.cpp 4KB
test_registry.cpp 4KB
test_create_dir.cpp 4KB
test_file_logging.cpp 3KB
test_mpmc_q.cpp 3KB
test_dup_filter.cpp 3KB
color_sinks.cpp 3KB
utils.cpp 3KB
test_backtrace.cpp 3KB
test_eventlog.cpp 3KB
test_stdout_api.cpp 3KB
formatter-bench.cpp 2KB
test_fmt_helper.cpp 2KB
stdout_sinks.cpp 2KB
test_macros.cpp 2KB
bundled_fmtlib_format.cpp 2KB
test_time_point.cpp 1KB
test_stopwatch.cpp 1KB
test_custom_callbacks.cpp 1KB
spdlog.cpp 1KB
file_sinks.cpp 801B
test_systemd.cpp 588B
async.cpp 398B
cfg.cpp 279B
main.cpp 275B
.gitattributes 13B
.gitignore 1KB
format.h 151KB
core.h 109KB
format-inl.h 73KB
chrono.h 66KB
pattern_formatter-inl.h 43KB
color.h 24KB
ranges.h 23KB
compile.h 21KB
printf.h 20KB
os-inl.h 17KB
logger.h 14KB
os.h 14KB
common.h 13KB
spdlog.h 11KB
daily_file_sink.h 10KB
xchar.h 9KB
win_eventlog_sink.h 9KB
registry-inl.h 9KB
ostream.h 7KB
args.h 7KB
bin_to_hex.h 7KB
logger-inl.h 7KB
hourly_file_sink.h 6KB
tweakme.h 6KB
wincolor_sink-inl.h 6KB
std.h 5KB
file_helper-inl.h 5KB
rotating_file_sink-inl.h 5KB
ansicolor_sink-inl.h 4KB
android_sink.h 4KB
fmt_helper.h 4KB
kafka_sink.h 4KB
systemd_sink.h 4KB
mpmc_blocking_q.h 4KB
tcp_client-windows.h 4KB
stdout_sinks-inl.h 4KB
registry.h 4KB
ansicolor_sink.h 4KB
tcp_client.h 4KB
os.h 4KB
mongo_sink.h 4KB
syslog_sink.h 4KB
pattern_formatter.h 4KB
async.h 4KB
thread_pool-inl.h 3KB
circular_q.h 3KB
thread_pool.h 3KB
qt_sinks.h 3KB
helpers-inl.h 3KB
dup_filter_sink.h 3KB
udp_client-windows.h 3KB
spdlog-inl.h 3KB
wincolor_sink.h 3KB
rotating_file_sink.h 3KB
async_logger-inl.h 2KB
dist_sink.h 2KB
stdout_sinks.h 2KB
async_logger.h 2KB
共 167 条
- 1
- 2
资源评论
- DONOT_WORRY_BE_HAPPY2023-05-16#完美解决问题 #运行顺畅 #内容详尽 #全网独家 #注释完整
「已注销」
- 粉丝: 1
- 资源: 93
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于Spring Boot框架的报表管理系统.zip
- (源码)基于树莓派和TensorFlow Lite的智能厨具环境监测系统.zip
- (源码)基于OpenCV和Arduino的面部追踪系统.zip
- (源码)基于C++和ZeroMQ的分布式系统中间件.zip
- (源码)基于SSM框架的学生信息管理系统.zip
- (源码)基于PyTorch框架的智能视频分析系统.zip
- (源码)基于STM32F1的Sybertooth电机驱动系统.zip
- (源码)基于PxMATRIX库的嵌入式系统显示与配置管理.zip
- (源码)基于虚幻引擎的舞蹈艺术节目包装系统.zip
- (源码)基于Dubbo和Redis的用户中台系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功