basic_logger_mt 的实现位于 basic_file_sink.h 文件中,它会默认调用 synchronous_factory 工厂来创建 logger 对象: struct synchronous_factory { template<typename Sink, typename... SinkArgs> static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&...args) { // 创建 Sin...
spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)"); } 文件日志 基本文件 最简单的日志文件: #include "spdlog/sinks/basic_file_sink.h" void basic_logfile_example() { try { auto logger = spdlog::basic_logger_mt("basic_log...
auto console = spdlog::stdout_color_mt("console"); // 基于文件的简单日志 auto logger = spdlog::basic_logger_mt("basic_logger","logs/basic.txt"); // 基于滚动文件的日志,每个文件5MB,三个文件 auto logger = spdlog::rotating_logger_mt("file_logger","myfilename",1024*1024*5,3); // 定...
auto logger = spdlog::stdout_color_mt('console'); logger->info('hello world'); return 0;} 运行结果如下: 创建基本文件 Logger #include 'spdlog/spdlog.h'#include 'spdlog/sinks/basic_file_sink.h'int main() { auto logger = spdlog::basic_logger_mt('file','my_log.log'); logger->inf...
#include"spdlog/spdlog.h"#include<iostream>intmain(){autofileLogger=spdlog::basic_logger_mt("fengyuzaitu","test.log");//fileLogger->flush_on(spdlog::level::info);//调用情况下立即刷新日志到磁盘std::string strURL="fengyuzaitu51.cto";intnFirstTime=1;fileLogger->info("Welcome to {0} ...
auto daily= spd::basic_logger_mt("basic2","logs/basic-log.txt"); daily->info("Thread 2,Count {}", i); spdlog::drop("basic2"); } }catch(constspd::spdlog_ex&ex) { std::cout<<"Thread 2 Logger failed:"<< ex.what() <<std::endl; ...
voidSimLog::InitSimLog(std::stringlogger_name,std::stringfile_name,intlog_level) { //设置日志等级 spdlog::set_level(static_cast<spdlog::level::level_enum>(log_level)); //设置日志为异步日志,不带滚动,日志文件会一直写入 my_logger_=spdlog::basic_logger_mt<spdlog::async_factory>(logger_name...
利用工厂函数spdlog::basic_logger_mt("logger_name", "filename.txt")创建一个写入文件的logger intmain(int,char*[]){automy_logger=spdlog::basic_logger_mt("basic_logger","basic.txt");for(inti=0;i<1000;i++){my_logger->info("Test File Logger {}",i);}} ...
auto my_logger=spdlog::basic_logger_mt("basic_logger","logs/basic-log.txt");my_logger->info("spdlog is very easy to use!"); 搭配C++ 11使用简直绝配,就是那么简单,而且我们不用再管文件打开之后忘记关闭的问题了。 当然我的调试需求也被轻松搞定了:由于涉及到大量的调试信息,而且调试信息较长,这样...
spdlog::daily_logger_mt 说明:该⽇志创建成功以后,写⼊的⽇志只在当天⽣效,简单来说,就是在⼀天的某个时间点(这个函数中有参数可以设置)就会把⽇志清空。2、创建多个⽂件⽇志 spdlog::rotating_logger_mt 说明:该⽇志创建成功以后,如果我们写⼊的⽇志⼤⼩⼤于某个值(这个值...