快速的 C++ 日志库 spdlog

码农软件 · 软件分类 · 日志工具(Logging) · 2019-09-20 16:42:49

软件介绍

spdlog 是一个快速的 C++ 日志库,只包含头文件,兼容 C++11。

特性:

  • 非常快

  • 只包含头文件

  • 无需依赖第三方库

  • 支持跨平台 - Linux / Windows on 32/64 bits

  • 支持多线程

  • 可对日志文件进行循环输出

  • 可每日生成日志文件

  • 支持控制台日志输出

  • 可选的异步日志

  • 支持日志输出级别

  • 可自定义日志格式

示例代码:

#include <iostream>
#include "spdlog/spdlog.h"

int main(int, char* [])
{
    namespace spd = spdlog;

    try
    {
        std::string filename = "spdlog_example";
        auto console = spd::stdout_logger_mt("console");
        console->info("Welcome to spdlog!") ;
        console->info() << "Creating file " << filename << "..";

        auto file_logger = spd::rotating_logger_mt("file_logger", filename, 1024 * 1024 * 5, 3);
        file_logger->info("Log file message number", 1);

        for (int i = 0; i < 100; ++i)
        {
            auto square = i*i;
            file_logger->info() << i << '*' << i << '=' << square << " (" << "0x" << std::hex << square << ")";
        }

        // Change log level to all loggers to warning and above
        spd::set_level(spd::level::WARN);
        console->info("This should not be displayed");
        console->warn("This should!");
        spd::set_level(spd::level::INFO);

        // Change format pattern to all loggers
        spd::set_pattern(" **** %Y-%m-%d %H:%M:%S.%e %l **** %v");
        spd::get("console")->info("This is another message with different format");
    }
    catch (const spd::spdlog_ex& ex)
    {
        std::cout << "Log failed: " << ex.what() << std::endl;
    }
    return 0;
}

本文地址:https://codercto.com/soft/d/15023.html

互联网浪尖上的女性

互联网浪尖上的女性

田玉翠 / 人民出版社 / 2017-1 / 68.00

二十三个真实、前沿的女性创业者实例,带你走进“她世界”洞悉“她经济”。《互联网浪尖上的女性》不仅仅关于创业,更是关于女性如何追逐自己的梦想,让人生更丰满、更精彩。一起来看看 《互联网浪尖上的女性》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

SHA 加密
SHA 加密

SHA 加密工具