nlog-简单易用的C++日志,线程安全、异步、高性能

两年前发过一个自己实现的C++异步日志, 由于当时水平太菜,做的那是相当的丑陋 ,有朋友不嫌弃 问我有没有后续的版本,最近借着项目需要,翻出来重新实现了一下。

该日志主要围绕几个主题:
1.简单易用 兼容 printf、 std::cout两种方式
2.功能灵活
3.小巧-500行左右
4.多线程安全
5.性能每秒至少10万+
6.完美兼容 多字节(ANSI)、宽字节(UNICODE)
7.同时打印多日志,互不干扰

只支持Windows
传送门:https://download.csdn.net/download/cstringw/10294191
git仓库:https://gitee.com/skygarth/nlog

#使用简单

#include "nlog/nlog.h"

int main()
{
    LOG_APP("hello world");
    LOG_ERR() << "[中文测试]";
    LOG_WAR("my name is %s, I am ", "nlog") << 6 << " years old!";

    /*释放所有资源*/
    nlog::CLog::ReleaseAll();
    return 0;
}

//输出
[03-18 21:29:02][APP][2AAC    ]: hello world
[03-18 21:29:02][ERR][2AAC    ]: [中文测试]
[03-18 21:29:02][WAR][2AAC    ]: my name is nlog, I am 6 years old!

#灵活的自定义配置

#include "nlog/nlog.h"

int main()
{
    nlog::Config logCfg;

    /*日志前缀 如:[log-test-01.cpp: 32 ][BD4     ]: */
    logCfg.prefixion  = _T("[{file}:{line}][{id}]: ");

    /*日期格式*/
    logCfg.dateFormat = _T("%m%d");

    /*日志目录 默认:模块当前目录/log*/
    logCfg.logDir;

    /*文件名格式 {time} {id}将被转换为时间与线程id*/
    logCfg.fileName   = _T("日志{time}.log");

    /*设置配置*/
    nlog::CLog::Instance().SetConfig(logCfg);

    /*设置日志等级,大于当前等级的日志将不被打印*/
    nlog::CLog::Instance().SetLevel(nlog::LV_WAR);

    LOG_APP() << _T("[中文测试]");
    LOG_WAR("my name is %s, I am ", "nlog") << 6 << " years old!";
    LOG_ERR("time is ") << nlog::time << " and thread id: " << nlog::id;

    /*释放所有资源*/
    nlog::CLog::ReleaseAll();
    return 0;
}

//输出
日志0318.log
[log-test-01.cpp: 34 ][F40     ]: my name is nlog, I am 6 years old!
[log-test-01.cpp: 35 ][F40     ]: time is 0318 and thread id: F40   

#多线程并发性能:

多线程并发性能

猜你喜欢

转载自blog.csdn.net/cstringw/article/details/79605143