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)
上一篇 2022年6月23日 下午3:46
下一篇 2022年6月23日 下午4:00


相关推荐

  • jquery删除添加输入文本框

    效果体验:http://hovertree.com/texiao/jquery/67/效果图:参考:http://hovertree.com/h/bjaf/traversing_each.htm代码如

    2021年12月24日
    50
  • AutoEventWireup=“true” 属性

    AutoEventWireup=“true” 属性AutoEventWireupAutoEventWireup=“true” :自动事件匹配asp.net(AutoEventWireup属性的确切含义)使用Asp.NET时,新建的aspx页面第一行page指令中包含了一个AutoEventWireup属性。网上的很多教程认为这一属性,甚至这一行代码都是没用的。其实,这是不了解Asp.NET事件处理模型的表现。简单

    2022年5月28日
    33
  • ubuntu系统下mysql重置密码和修改密码操作

    ubuntu系统下mysql重置密码和修改密码操作一、忘记密码后想重置密码在介绍修改密码之前,先介绍一个文件/etc/mysql/debian.cnf.其主要内容如下图:里面有一个debian-sys-maint用户,这个用户只有Debian或Ubuntu服务器才有,所以如果您的服务器是Debain或Ubuntu,debian-sys-maint是个Mysql安装之后自带的用户,具体作用是重启及运行mysql服务。所以如果忘了root密码,可以通…

    2022年5月31日
    50
  • 智谱ZCode上手:把Claude和Gemini装进桌面,编程还能这么玩?

    智谱ZCode上手:把Claude和Gemini装进桌面,编程还能这么玩?

    2026年3月12日
    3
  • ES6中的模板字符串改变html_vue事件绑定修饰符

    ES6中的模板字符串改变html_vue事件绑定修饰符step1:模板字符传中写法renderDom(){return`<divdata-action=”goDetail”data-url=”${item.clickUrl}”class=”uliao-news-item”><h1>${item.title}</h1>&…

    2022年8月21日
    27
  • 大数据管理平台(一)概述「建议收藏」

    大数据管理平台(一)概述「建议收藏」系列文章目录文章目录系列文章目录前言一、功能概述二、使用步骤2.1安装2.2监控2.3管理2.4用户管理2.5应用市场2.6操作系统三、总结前言做大数据有几年了,这些年耳濡目染了一些大数据管理平台的使用,但是或多或少使用起来,都不怎么方便,所以决定自己来实现一个简单的大数据平台一、功能概述大数据应用组件往往很多,可能几百台服务器组成一个Hadoop集群,当部署这些节点时,需要一个节点一个节点的操作,简直不敢想象。同时在这些服务器上可能还部署着Spark、Flink、Hive

    2022年5月1日
    51

发表回复

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

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