spdlog库安装与使用
一、通过包管理器安装
#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
二、源码安装制定版本的库
#git clone -b v1.9.2 https://gitee.com/chenjian688/spdlog.git
git clone https://github.com/gabime/spdlog.git
cd spdlog && mkdir build && cd build
cmake .. && make -j
sudo make install
#卸载
cd build #进入安装文件夹的build目录
sudo xargs rm < install_manifest.txt
三、使用
//直接包含头文件即可使用
#include<spdlog.h>
int main(){
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
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("{:>8} aligned, {:<8} aligned", "right", "left");
// Runtime log levels
spdlog::set_level(spdlog::level::info); // Set global log level to info
spdlog::debug("This message should not be displayed!");
spdlog::set_level(spdlog::level::trace); // Set specific logger's log level
spdlog::debug("This message should be displayed..");
return 0;
}