inlinestd::shared_ptr<spdlog::logger>spdlog::rotating_logger_mt(conststd::string& logger_name,constfilename_t& filename,size_tmax_file_size,size_tmax_files){1.returncreate<spdlog::sinks::rotating_file_sink_mt>(logger_name, filename,SPDLOG_FILENAME_T("txt"), max_file_size, max_files);...
目前spdlog 已经提供了多种 Sink 的实现,包括: stdout_sink(输出到控制台) basic_file_sink(输出到文件) daily_file_sink(每天输出到不同的日志文件) rotating_file_sink(按文件大小或时间自动切分日志文件) null_sink(无输出) syslog_sink(输出到系统日志) udp_sink(输出到udp) tcp_sink(输出到tcp) kafka_s...
// spdlog #include "spdlog/spdlog.h" #include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" #include <iostream> #include <memory> // spd 带行号的打印,同时输出console和文件 #define DEBUG(...) SPDLOG_LOGGER_DE...
创建rotating file logger 复制代码 //Create rotating file multi-threaded logger #include "spdlog/sinks/rotating_file_sink.h" auto file_logger = spdlog::rotating_logger_mt("file_logger", "logs/mylogfile", 1048576 * 5, 3); ... auto same_logger= spdlog::get("file_logger"); 创建异步logger...
1. return create<spdlog::sinks::rotating_file_sink_mt>(logger_name, filename, SPDLOG_FILENAME_T("txt"), max_file_size, max_files);} line: 1, 实际创建对象。create是⼀个模板函数,如下:template <typename Sink, typename... Args> inline std::shared_ptr<spdlog::logger> spdlog::create(...
3、新建一个C++控制台应用程序项目spdlog-test,在项目属性页VC++目录-包含目录中添加上述include路径 4、添加源文件 源.cpp,输入以下代码 代码语言:javascript 复制 #include<iostream>#include<cstdio>#include"spdlog/spdlog.h"#include"spdlog/sinks/rotating_file_sink.h"using namespace std;using namespace spdl...
//Create rotating file multi-threaded logger #include "spdlog/sinks/rotating_file_sink.h" auto file_logger = spdlog::rotating_logger_mt("file_logger", "logs/mylogfile", 1048576 * 5, 3); ... auto same_logger= spdlog::get("file_logger"); ...
auto logger = spdlog::basic_logger_mt('file','my_log.log'); logger->info('hello world'); return 0;} 运行结果如下: 创建滚动文件 Logger 可以设置日志文件的大小及数量限定: #include 'spdlog/spdlog.h'#include 'spdlog/sinks/rotating_file_sink.h'int main() { auto max_size = 1024*2;/...
or create the sink manually and pass it to the logger: #include"spdlog/sinks/rotating_file_sink.h"...autorotating = make_shared<spdlog::sinks::rotating_file_sink_mt> ("log_filename",1024*1024,5,false);autofile_logger = make_shared<spdlog::logger>("my_logger", rotating); ...
循环文件 日志文件超过指定大小后,自动生成一个新的;并且只保留最多指定数量的日志文件: 代码语言:javascript 复制 #include"spdlog/sinks/rotating_file_sink.h"void