spdlog 使用

spdlog 是一个日志库,直接引用头文件即可使用,速度快,异步打印日志。

对应的git地址 spdloggit地址

对应的目录

把上面划线的文件夹引入到自己的工程中,即可使用spdlog

下面是使用例子

cpp 复制代码
   inline static void create_logging(const std::string& dir) 
    {
        spdlog::init_thread_pool(8192 * 2, 1); // 16k
        std::shared_ptr<spdlog::logger> l;
        l = spdlog::create_async_nb<spdlog::sinks::rotating_file_sink_mt>
                ("async_file_logger", dir, 1024 * 1024 * 10, 5);
        // 日志级别从低到高 trace, debug, info, warn, err, critical, off, n_levels
        l->flush_on(spdlog::level::info);//warn
        l->set_pattern("[%Y-%m-%d %T.%e][tid:%t  %s:%#] [%l] %v"); //设置信息格式
        spdlog::flush_every(std::chrono::seconds(3));
        spdlog::set_default_logger(l);
    }
    int main()
    {
    	std::string path = "./log.txt";
    	create_logging(path); //创建log文件
    	SPDLOG_ERROR(u8"log文件 error 信息{}", path.c_str()); //打印error类信息
    	SPDLOG_INFO(u8"log文件 info 信息{}", path.c_str());
    	return 0;
    }
相关推荐
Mr_WangAndy1 天前
C++_chapter15_C++重要知识点_auto,function,bind,decltype
c++·decltype·bind·function·可调用对象
万象.1 天前
QT基础及对象树的认识
c++·qt
小张成长计划..1 天前
【C++】2:cin和cout的介绍和使用,函数的缺省参数
c++
再卷也是菜1 天前
C++篇(17)哈希拓展学习
c++·哈希
“愿你如星辰如月”1 天前
Linux:进程间通信
linux·运维·服务器·c++·操作系统
灵晔君1 天前
C++标准模板库(STL)——list的模拟实现
c++·list
Justinyh1 天前
1、CUDA 编程基础
c++·人工智能
white-persist1 天前
差异功能定位解析:C语言与C++(区别在哪里?)
java·c语言·开发语言·网络·c++·安全·信息可视化
ShineWinsu1 天前
对于数据结构:链式二叉树的超详细保姆级解析—中
数据结构·c++·算法·面试·二叉树·校招·递归
liu****1 天前
20.传输层协议TCP
服务器·网络·数据结构·c++·网络协议·tcp/ip·udp