spdlog linux编译出错,【C++】spdlog--log4cxx有点笨重,试一试spdlog

本文介绍了C++高性能日志库spdlog,对比了它与log4cxx的区别,并展示了如何在Linux环境下进行编译与使用。包括编译步骤、基本用法、日志格式设定、行号打印、控制台输出和文件日志的管理,以及如何防止日志丢失的策略。此外,还提供了完整的示例代码和遇到的问题解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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_

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值