日志文件超过指定大小后,自动生成一个新的;并且只保留最多指定数量的日志文件: #include "spdlog/sinks/rotating_file_sink.h" void rotating_example() { // Create a file rotating logger with 5mb size max and 3 rotated files auto max_size = 1024*1024 * 5; auto max_files = 3; auto logger =...
我们仍然以rotating_file_sink为例来说明在spdlog中sink的创建过程。 在spdlog-master/tests中能够找到file_log.cpp文件,其中有关于rotate的示例代码,如下: TEST_CASE("rotating_file_logger1","[rotating_logger]]") {1.prepare_logdir();2.std::stringbasename ="logs/rotating_log";3.auto logger =spdlog::...
创建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...
SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__);SPDLOG_LOGGER_ERROR(spdlog::get("daily_logger"), __VA_ARGS__) int main(int argc, char *argv[]) { // 按文件大小 //auto file_logger = spdlog::rotating_logger_mt("file_log", "log/log.log", 1024 * 1024 * 100, ...
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;/...
创建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"); ...
Sink在本⽰例中即spdlog::sinks::rotating_file_sink_mt, 第⼆个模板参数也就是 rotating_file_sink_mt的构造函数参数。针对每⼀种sink,都会存在⼀个对应的create函数。当然sink的实际创建也是发⽣在该函数中(line2)。2.3 单例registry 1.2中 line:3⼜继续调⽤了registry执⾏对象的创建,我们先...
6.Rotating file 代码语言:javascript 复制 #include "spdlog/sinks/rotating_file_sink.h" void rotating_example() { // Create a file rotating logger with 5mb size max and 3 rotated files auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5...
循环文件 日志文件超过指定大小后,自动生成一个新的;并且只保留最多指定数量的日志文件: 代码语言:javascript 复制 #include"spdlog/sinks/rotating_file_sink.h"void
#include "spdlog/sinks/rotating_file_sink.h"auto max_size = 1048576 * 5; // 5 MBauto max_files = 3;auto logger = spdlog::rotating_logger_mt("my_logger", "my_log.txt", max_size, max_files); 这段代码创建了一个按大小滚动的日志记录器,每个日志文件最大 5MB,最多保留 3 个备份。