spdlog linux编译出错,spdlog「建议收藏」

spdlog linux编译出错,spdlog「建议收藏」#include#include”spdlog/spdlog.h”intmain(int,char*[]){namespacespd=spdlog;try{//consolelogger(multithreadedandwithcolor)autoconsole=spd::stdout_logger_mt(“console”,true);console-&gt…

大家好,又见面了,我是你们的朋友全栈君。

#include

#include “spdlog/spdlog.h”

int main(int, char* [])

{

namespace spd = spdlog;

try {

// console logger (multithreaded and with color)

auto console = spd::stdout_logger_mt(“console”, true);

console->info(“Welcome to spdlog!”) ;

console->info(“An info message example {}..”, 1);

console->info() << “Streams are supported too ” << 1;

//Formatting examples

console->info(“Easy padding in numbers like {:08d}”, 12);

console->info(“Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}”, 42);

console->info(“Support for floats {:03.2f}”, 1.23456);

console->info(“Positional args are {1} {0}..”, “too”, “supported”);

console->info(“{:<30}”, “left aligned”);

console->info(“{:>30}”, “right aligned”);

console->info(“{:^30}”, “centered”);

//

// Runtime log levels

//

spd::set_level(spd::level::info); //Set global log level to info

console->debug(“This message shold not be displayed!”);

console->set_level(spd::level::debug); // Set specific logger’s log level

console->debug(“Now it should..”);

//

// Create a file rotating logger with 5mb size max and 3 rotated files

//

auto file_logger = spd::rotating_logger_mt(“file_logger”, “logs/mylogfile”, 1048576 * 5, 3);

for (int i = 0; i < 10; ++i)

file_logger->info(“{} * {} equals {:>10}”, i, i, i * i);

//

// Create a daily logger – a new file is created every day on 2:30am

//

auto daily_logger = spd::daily_logger_mt(“daily_logger”, “logs/daily”, 2, 30);

//

// Customize msg format for all messages

//

spd::set_pattern(“*** [%H:%M:%S %z] [thread %t] %v ***”);

file_logger->info(“This is another message with custom format”);

spd::get(“console”)->info(“loggers can be retrieved from a global registry using the spdlog::get(logger_name) function”);

//

// Compile time debug or trace macros.

// Enabled #ifdef SPDLOG_DEBUG_ON or #ifdef SPDLOG_TRACE_ON

//

SPDLOG_TRACE(console, “Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}”, 1, 3.23);

SPDLOG_DEBUG(console, “Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}”, 1, 3.23);

//

// Asynchronous logging is very fast..

// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..

//

size_t q_size = 1048576; //queue size must be power of 2

spdlog::set_async_mode(q_size);

auto async_file = spd::daily_logger_st(“async_file_logger”, “logs/async_log.txt”);

async_file->info() << “This is async log..” << “Should be very fast!”;

//

// syslog example. linux only..

//

#ifdef __linux__

std::string ident = “spdlog-example”;

auto syslog_logger = spd::syslog_logger(“syslog”, ident, LOG_PID);

syslog_logger->warn(“This is warning that will end up in syslog. This is Linux only!”);

#endif

} catch (const spd::spdlog_ex& ex) {

std::cout << “Log failed: ” << ex.what() << std::endl;

}

}

// Example of user defined class with operator<<

class some_class {};

std::ostream& operator<

{

return os << “some_class”;

}

void custom_class_example()

{

some_class c;

spdlog::get(“console”)->info(“custom class with operator<<: c>

spdlog::get(“console”)->info() << “custom class with operator<<: c>

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/152285.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 手机号码归属地 mysql_最新手机号段归属地数据库 (2021年1月版) 471402行

    手机号码归属地 mysql_最新手机号段归属地数据库 (2021年1月版) 471402行//名称:手机号码归属地查询dat高效率查询内存优化版//压缩:原版txt为22M,生成这种dat结构为2.66M//性能:每秒解析300万+号段或者号码,简洁高效//环境:CPUi7-7700K+内存16GB//创建:qqzeng-ipusingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Text;…

    2022年7月22日
    14
  • DSP的入门教程「建议收藏」

    DSP的入门教程「建议收藏」(1)第一步:打开CCS5.2,新建一个工程。(2)第二步:输入工程名后点击“finish”如图(3)第三步:右键单击工程名-“properties“如图(4)第四步:所有头文件路径添加完成后,点击“ok”,如图(5)第五步:添加工程所需头文件,如图依次添加需要头文件,添加时按下图添加:添加完成后,如图:(6)第六步:程序编写(7)第七步:对程序进行编译。编译结果:…

    2025年9月29日
    4
  • UE4摄像机_ue4怎么做摄像机动画

    UE4摄像机_ue4怎么做摄像机动画一.摄像机工作原理在游戏中,摄像机是玩家的眼睛,他控制了玩家的视点(POV即PointOfView,后面简称POV)位置以及玩家的视野大小(FOV即FieldOfView,后面简称FOV)。一句话,摄像机决定了我们去观察这个游戏世界。游戏的类型多种多样,有第一人称的FPS游戏,有第三人称的动作游戏,还有需要统筹全局来观察的RTS游戏。简单来说,第一人称就是把POV放在人眼睛的位置,第三人称就是把P…

    2022年10月4日
    5
  • JS–JavaScript变量详解(全局变量、局部变量)

    JS–JavaScript变量详解(全局变量、局部变量)JavaScript变量JavaScript使用var关键字声明变量。声明变量的5种常规用法如下:vara; //声明单个变量。var关键字与变量名之间以空格分隔varb,c; //声明多个变量。变量之间以逗号分隔vard=1; //声明并初始化变量。等号左侧是变量名,等号右侧是值vare=2,f=3; //声明并初始化多个变量。以逗号分隔多个变量…

    2022年6月5日
    39
  • eclipse中改变默认的workspace的方法及说明

    eclipse中改变默然的workspace的方法可以有:1.在创建project的时候,手动选择使用新的workspace,如创建一个webproject,在向导中的Location选项,取消使

    2021年12月22日
    39
  • PostgreSQL查询全角字符「建议收藏」

    PostgreSQL查询全角字符「建议收藏」PostgreSQL中~*的妙用PostgreSQL中可以使用~*进行模糊查询,同时会忽略大小写,在查询的条件中也会支持正则表达式。所以在查询全角字符的时候,可以使用正则表达式来来进行查询。select*from表名where字段~*'[A-Za-z0-9]’;使用上面SQL就可以查询出数据库中所有包含全角字符的数据了。…

    2025年6月5日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号