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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • yum卸载重装[通俗易懂]

    yum卸载重装[通俗易懂]莫名原因(之前操作不小心删除了某相关文件)导致虚拟机的yum使用不了,在重新安装之前需要卸载原来的相关数据1.删除/usr/share目录下的yum-cli、yum-pluginrm-rfyum-cli/yum-plugins/2.清理与yum相关的文件rpm-qa|grepyumrpm-eyum-3.4.3-161.el7.centos.noarch…

    2022年6月10日
    72
  • 【已解决】解决IntelliJ IDEA控制台输出中文乱码问题

    IntelliJ IDEA 真的是一款很方便的Java开发工具,但是关于中文乱码这个问题我不得不吐槽,这个编码也弄得这么麻烦干嘛,真想找idea开发者干架,我敢打包票我能在一分钟之内一拳飞过去让他跪下

    2022年3月13日
    264
  • Carson带你学Android:你要的WebView与 JS 交互方式都在这里了

    Carson带你学Android:你要的WebView与 JS 交互方式都在这里了前言现在很多App里都内置了Web网页(HybridApp),比如说很多电商平台,淘宝、京东、聚划算等等,如下图上述功能是由Android的WebView实现的,其中涉及到Android客户端与Web网页交互的实现今天我将全面介绍Android通过WebView与JS交互的全面方式阅读本文前请先阅读:Android开发:最全面、最易懂的Webview详解…

    2022年6月13日
    37
  • Android控件 – TextView、Button、EditText、CompoundButton、CheckBox简介「建议收藏」

    Android控件 – TextView、Button、EditText、CompoundButton、CheckBox简介「建议收藏」TextViewTextView类是View的直接子类,用于单纯地显示一行或多行静态文本的视图。它继承View所有XML属性,并有着自己的XML属性。在XM布局中常用的属性:属性说明android:autoLink设置文本超链接样式,并点击跳向链接,值:none不匹配任何类型的文字(默认);web匹配URL地址,单击后打开浏览器显示地址;email匹配邮箱地址,单击后打

    2022年7月18日
    14
  • JavaScript两种数组去重方法「建议收藏」

    JavaScript两种数组去重方法「建议收藏」JavaScript两种数组去重方法第一种(利用splice方法去重)splice()方法用于插入、删除或替换数组的元素。//申明一个数组vararr=[1,3,5,4,3,1,5,7,8,4,7];functiontemp(arr){for(i=0;i<arr.length;i++){for(j…

    2022年6月24日
    28
  • 为什么Redis选择6379作为默认端口号?[通俗易懂]

    为什么Redis选择6379作为默认端口号?[通俗易懂]6379在是手机按键上MERZ对应的号码,而MERZ取自意大利歌女AlessiaMerz的名字。MERZ长期以来被antirez及其朋友当作愚蠢的代名词。Redis作者antirez同学在twitter上说将在下一篇博文中向大家解释为什么他选择6379作为默认端口号。而现在这篇博文出炉,在解释了Redis的LRU机制之后,向大家解释了采用6379作为默认端口的原因。原博文:http://anti…

    2022年5月27日
    98

发表回复

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

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