spdlog是什么linux
Fast C++ logging library
按照官方介绍,是一个高性能的C++日志组件,支持跨平台,兼容 C++11。原来项目中使用的是log4cxx,我感受稍微有点笨重,而且好久没有更新了。ios
在新项目中,我只须要一款轻量级的日志组件,能:git
存文件
按照天数切分
快速的浏览了spdlog,知足个人需求,因而开搞!github
spdlog快速入门
如下内容来自spdlog的 READMEmacos
编译json
$ git clone https://github.com/gabime/spdlog.git
$ cd spdlog && mkdir build && cd build
$ cmake .. && make -j
PS:使用cmake来编译,cmake 命令会生成makefile。若是机器上没有cmake,请先安装一下,个人cmake3.14.5,macos 10.15,swift
meki-mac-pro:~ xuyc$ cmake -version
cmake version 3.14.5
CMake suite maintained and supported by Kitware (kitware.com/cmake).
使用bash
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.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_