# xncc_log **Repository Path**: lxncc/xncc_log ## Basic Information - **Project Name**: xncc_log - **Description**: 高性能日志库 前端调用消耗纳秒级(测试CPUi7-10710U 受睿频影响可能略有出入), 高性能版本可以使用C++14的编译选项 使用LoggerNew.h相关接口 - **Primary Language**: C++ - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2023-05-18 - **Last Updated**: 2025-06-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # xncc_log [![Security Status](https://www.murphysec.com/platform3/v31/badge/1674311609224347648.svg)](https://www.murphysec.com/console/report/1674311609182404608/1674311609224347648) #### 介绍 使用C++11实现的高性能日志库 #### 软件架构 1. 日志线程会管理N个无锁SPSC队列,每个日志数据生产线程会有对应的线程变量,有对应的SPSC队列,因此避免了多线程写日志需要加锁竞争的问题。 2. 日志生产线程写日志的时候,SPSC队列会预分配内存(实际上是提供写入的index),大大减小了前端的消耗,前端消耗只有对日志数据的内存拷贝消耗 3. 对于常量字符串也有优化,可以调用logConstant写入日志 4. 日志时间、以及日志数据的格式化都由日志线程完成,前端无消耗 5. 支持传入函数指针和对象,后台进行数据格式化 参考如下 ``` cpp struct TestObj { int a = 1; int b = 2; int c = 3; }; void TestObjToString(const void* arg, std::ostringstream& oss) { const TestObj* obj = reinterpret_cast(arg); oss << "a=" << obj->a << " b=" << obj->b << " c=" << obj->c << " "; } xncc::LogObject& operator<<(xncc::LogObject& logger, const TestObj& obj) { return logger << xncc::ObjectWithLogFunciton{.func = TestObjToString, .objSize = sizeof(TestObj), .objPtr = &obj}; } xncc::ObjectWithLogFunciton{.func = TestObjToString, .objSize = sizeof(TestObj), .objPtr = &obj} ``` #### 安装教程 sh build.sh #### 使用说明 参考examples