{"id":31363853,"url":"https://github.com/hesphoros/lightlogwriteimplwithpanel","last_synced_at":"2025-10-30T18:41:31.306Z","repository":{"id":316487536,"uuid":"1056718747","full_name":"hesphoros/LightLogWriteImplWithPanel","owner":"hesphoros","description":"Modern C++17 logging library with async processing, smart rotation, ZIP compression, and powerful filtering","archived":false,"fork":false,"pushed_at":"2025-09-24T21:21:41.000Z","size":2383,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-24T23:28:19.955Z","etag":null,"topics":["async","cmake","compression","cpp17","cross-platform","high-performance","logging","rotation","thread-safe"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hesphoros.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-14T17:04:01.000Z","updated_at":"2025-09-24T21:21:44.000Z","dependencies_parsed_at":"2025-09-24T23:38:21.348Z","dependency_job_id":null,"html_url":"https://github.com/hesphoros/LightLogWriteImplWithPanel","commit_stats":null,"previous_names":["hesphoros/lightlogwriteimplwithpanel"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/hesphoros/LightLogWriteImplWithPanel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2FLightLogWriteImplWithPanel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2FLightLogWriteImplWithPanel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2FLightLogWriteImplWithPanel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2FLightLogWriteImplWithPanel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hesphoros","download_url":"https://codeload.github.com/hesphoros/LightLogWriteImplWithPanel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2FLightLogWriteImplWithPanel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277184148,"owners_count":25775286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-27T02:00:08.978Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","cmake","compression","cpp17","cross-platform","high-performance","logging","rotation","thread-safe"],"created_at":"2025-09-27T05:26:22.265Z","updated_at":"2025-10-30T18:41:31.299Z","avatar_url":"https://github.com/hesphoros.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LightLog - Modern C++17 Logging Library\n\n\u003cdiv align=\"center\"\u003e\n\n![C++](https://img.shields.io/badge/C++-17-blue.svg)\n![CMake](https://img.shields.io/badge/CMake-3.16+-green.svg)\n![License](https://img.shields.io/badge/License-GPL%20v3-green.svg)\n![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux-lightgrey.svg)\n![Build](https://img.shields.io/badge/Build-Passing-brightgreen.svg)\n\n**现代化企业级C++日志库**\n\n*功能完整 • 性能卓越 • 现代CMake • 易于集成*\n\n\u003c/div\u003e\n\n---\n\n## 📋 项目概述\n\nLightLog (LightLogWriteImplWithPanel) 是一个现代化的企业级C++17日志库，提供全面的日志记录、轮转、压缩、过滤和多输出功能。采用现代CMake构建系统，支持多种集成方式，专为高并发、大规模应用场景设计。\n\n### ✨ 核心特性\n\n- 🚀 **高性能**: 异步队列处理、多线程优化、支持批处理操作\n- 🔄 **智能轮转**: 支持基于大小、时间、复合等多种轮转策略\n- 📦 **自动压缩**: 内置ZIP/GZIP/LZ4/ZSTD压缩算法，节省存储空间\n- 🔍 **强大过滤**: 级别、关键词、正则表达式、频率限制等多种过滤方式\n- 🎯 **多输出支持**: 控制台、文件等多种输出目标，支持同时输出\n- 🔒 **线程安全**: 完整的多线程支持和线程安全保证\n- 🌐 **跨平台**: 支持Windows和Linux平台\n- 🏗️ **现代CMake**: 支持FetchContent、add_subdirectory、find_package三种集成方式\n- ⚙️ **易配置**: 灵活的JSON配置系统和丰富的API\n- 📦 **依赖管理**: 通过FetchContent自动管理外部依赖\n\n---\n\n## 🚀 快速开始\n\n### 基础使用\n\n```cpp\n#include \"log/LightLogWriteImpl.h\"\n\nint main() {\n    // 创建日志实例\n    auto logger = std::make_shared\u003cLightLogWrite_Impl\u003e();\n    \n    // 设置日志文件（目录和基础名称）\n    logger-\u003eSetLastingsLogs(L\"logs\", L\"app\");\n    \n    // 写入不同级别的日志\n    logger-\u003eWriteLogInfo(L\"应用程序启动\");\n    logger-\u003eWriteLogWarning(L\"这是一个警告消息\");\n    logger-\u003eWriteLogError(L\"发生了一个错误\");\n    \n    // 或使用通用接口\n    logger-\u003eWriteLogContent(LogLevel::Info, L\"信息日志\");\n    logger-\u003eWriteLogContent(LogLevel::Debug, L\"调试日志\");\n    \n    return 0;\n}\n```\n\n### 高级配置示例\n\n```cpp\n#include \"log/LightLogWriteImpl.h\"\n#include \"log/LogCompressor.h\"\n#include \"log/ILogRotationManager.h\"\n\nint main() {\n    // 1. 创建压缩器（可选）\n    LogCompressorConfig compressorConfig;\n    compressorConfig.algorithm = CompressionAlgorithm::ZIP;\n    compressorConfig.compressionLevel = 6;              // 压缩级别 1-9\n    compressorConfig.workerThreadCount = 4;             // 工作线程数\n    compressorConfig.deleteSourceAfterSuccess = true;   // 压缩后删除源文件\n    auto compressor = std::make_shared\u003cLogCompressor\u003e(compressorConfig);\n    compressor-\u003eStart();  // 启动压缩服务\n    \n    // 2. 创建日志记录器\n    auto logger = std::make_shared\u003cLightLogWrite_Impl\u003e(\n        10000,                              // 日志队列大小\n        LogQueueOverflowStrategy::Block,    // 队列满时的策略（Block或DropOldest）\n        1000,                               // 批处理大小\n        compressor                          // 压缩器（可选，传nullptr禁用压缩）\n    );\n    \n    // 3. 设置日志文件路径\n    logger-\u003eSetLastingsLogs(L\"logs\", L\"myapp\");\n    \n    // 4. 配置日志轮转\n    LogRotationConfig rotationConfig;\n    rotationConfig.strategy = LogRotationStrategy::SizeAndTime;  // 复合策略\n    rotationConfig.maxFileSizeMB = 100;                         // 100MB触发轮转\n    rotationConfig.timeInterval = TimeRotationInterval::Daily;  // 每天轮转\n    rotationConfig.maxArchiveFiles = 30;                        // 保留30个归档\n    rotationConfig.enableCompression = true;                    // 启用压缩\n    rotationConfig.enableAsync = true;                          // 异步轮转\n    rotationConfig.archiveDirectory = L\"logs/archive\";          // 归档目录\n    logger-\u003eSetLogRotationConfig(rotationConfig);\n    \n    // 5. 设置日志级别过滤\n    logger-\u003eSetMinLogLevel(LogLevel::Info);  // 只记录Info及以上级别\n    \n    // 6. 使用日志系统\n    logger-\u003eWriteLogInfo(L\"系统配置完成\");\n    logger-\u003eWriteLogDebug(L\"这条不会被记录（低于Info级别）\");\n    \n    return 0;\n}\n```\n\n---\n\n## 📦 安装说明\n\n### 环境要求\n\n- **C++标准**: C++17或更高版本\n- **CMake**: 3.16或更高版本\n- **编译器**:\n  - Windows: Visual Studio 2019或更高版本\n  - Linux: GCC 7.0+或Clang 6.0+\n- **外部依赖**: 完全自动管理，无需手动安装\n  - UniConv (通过FetchContent自动获取)\n  - nlohmann/json (已包含)\n  - BS::thread_pool (已包含)\n  - miniz (已包含)\n\n### 方式一：作为独立项目构建\n\n```bash\n# 克隆仓库\ngit clone https://github.com/hesphoros/LightLogWriteImplWithPanel.git\ncd LightLogWriteImplWithPanel\n\n# CMake 构建\nmkdir build \u0026\u0026 cd build\ncmake .. -DLIGHTLOG_BUILD_EXAMPLES=ON -DLIGHTLOG_BUILD_TESTS=ON\ncmake --build . --config Release\n\n# 运行主演示程序\n./bin/Release/lightlog_demo\n\n# Windows用户\n.\\bin\\Release\\lightlog_demo.exe\n```\n\n### 方式二：作为子项目集成\n\n```cmake\n# 在你的CMakeLists.txt中添加子目录\nadd_subdirectory(external/LightLog)\n\n# 链接到你的目标\nadd_executable(my_app main.cpp)\ntarget_link_libraries(my_app PRIVATE LightLog::lightlog)\n```\n\n### 方式三：使用FetchContent集成（推荐）\n\n```cmake\ncmake_minimum_required(VERSION 3.16)\nproject(MyProject LANGUAGES CXX)\n\n# 设置C++标准\nset(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\n\ninclude(FetchContent)\n\n# 自动获取LightLog\nFetchContent_Declare(\n    LightLog\n    GIT_REPOSITORY https://github.com/hesphoros/LightLogWriteImplWithPanel.git\n    GIT_TAG main\n    GIT_SHALLOW TRUE\n)\n\nFetchContent_MakeAvailable(LightLog)\n\n# 创建目标并链接\nadd_executable(my_app main.cpp)\ntarget_link_libraries(my_app PRIVATE LightLog::lightlog)\n```\n\n### 方式四：使用find_package\n\n```cmake\n# 先安装LightLog到系统\ncmake --build build --target install\n\n# 在你的项目中使用\nfind_package(LightLog REQUIRED)\ntarget_link_libraries(my_app PRIVATE LightLog::lightlog)\n```\n\n### CMake选项配置\n\n```cmake\n# 可用的配置选项\noption(LIGHTLOG_BUILD_EXAMPLES \"Build example programs\" OFF)\noption(LIGHTLOG_BUILD_TESTS \"Build test programs\" OFF)\noption(LIGHTLOG_INSTALL \"Generate installation target\" OFF)\noption(LIGHTLOG_BUILD_SHARED \"Build shared library\" OFF)\n\n# 在FetchContent中使用\nset(LIGHTLOG_BUILD_EXAMPLES OFF CACHE BOOL \"\" FORCE)\nset(LIGHTLOG_BUILD_TESTS OFF CACHE BOOL \"\" FORCE)\nFetchContent_MakeAvailable(LightLog)\n```\n\n---\n\n## 📖 功能详解\n\n### 🎯 日志级别\n\nLightLog支持10个标准日志级别，从详细到严重：\n\n```cpp\nenum class LogLevel {\n    Trace = 0,     // 最详细的追踪信息\n    Debug,         // 调试信息\n    Info,          // 一般信息\n    Notice,        // 需要注意的事件\n    Warning,       // 警告信息\n    Error,         // 错误信息\n    Critical,      // 严重错误\n    Alert,         // 需要立即处理\n    Emergency,     // 系统不可用\n    Fatal          // 致命错误\n};\n```\n\n使用示例：\n\n```cpp\n// 方式1：使用便捷方法\nlogger-\u003eWriteLogTrace(L\"详细追踪信息\");\nlogger-\u003eWriteLogDebug(L\"调试信息\");\nlogger-\u003eWriteLogInfo(L\"一般信息\");\nlogger-\u003eWriteLogNotice(L\"需要注意的事件\");\nlogger-\u003eWriteLogWarning(L\"警告\");\nlogger-\u003eWriteLogError(L\"错误\");\nlogger-\u003eWriteLogCritical(L\"严重错误\");\nlogger-\u003eWriteLogAlert(L\"需要立即处理\");\nlogger-\u003eWriteLogEmergency(L\"系统不可用\");\nlogger-\u003eWriteLogFatal(L\"致命错误\");\n\n// 方式2：使用通用接口\nlogger-\u003eWriteLogContent(LogLevel::Info, L\"信息日志\");\nlogger-\u003eWriteLogContent(LogLevel::Error, L\"错误日志\");\n\n// 设置最小日志级别\nlogger-\u003eSetMinLogLevel(LogLevel::Info);  // 只记录Info及以上级别\n```\n\n### 🔄 日志轮转系统\n\n支持多种轮转策略，自动管理日志文件：\n\n```cpp\nLogRotationConfig config;\n\n// 1. 基于文件大小的轮转\nconfig.strategy = LogRotationStrategy::Size;\nconfig.maxFileSizeMB = 50;              // 50MB触发轮转\nconfig.maxArchiveFiles = 10;            // 保留10个归档文件\n\n// 2. 基于时间的轮转  \nconfig.strategy = LogRotationStrategy::Time;\nconfig.timeInterval = TimeRotationInterval::Daily;   // 每天轮转\n// 可选值: Hourly, Daily, Weekly, Monthly\n\n// 3. 复合轮转策略（同时基于大小和时间）\nconfig.strategy = LogRotationStrategy::SizeAndTime;\nconfig.maxFileSizeMB = 100;\nconfig.timeInterval = TimeRotationInterval::Daily;\n\n// 4. 轮转配置选项\nconfig.enableCompression = true;        // 启用压缩\nconfig.enableAsync = true;              // 异步轮转\nconfig.asyncWorkerCount = 2;            // 异步工作线程数\nconfig.archiveDirectory = L\"logs/archive\"; // 归档目录\nconfig.deleteSourceAfterArchive = true; // 归档后删除源文件\n\n// 应用配置\nlogger-\u003eSetLogRotationConfig(config);\n\n// 手动触发轮转\nlogger-\u003eForceLogRotation();\n\n// 异步轮转\nauto future = logger-\u003eForceLogRotationAsync();\nfuture.wait();  // 等待完成\n\n// 查询当前日志文件大小\nsize_t currentSize = logger-\u003eGetCurrentLogFileSize();\n```\n\n### 📦 压缩功能\n\n内置多种压缩算法，显著节省存储空间：\n\n```cpp\n// 1. 创建压缩器配置\nLogCompressorConfig compressorConfig;\ncompressorConfig.algorithm = CompressionAlgorithm::ZIP;  // ZIP, GZIP, LZ4, ZSTD\ncompressorConfig.compressionLevel = 6;                   // 1-9，平衡速度和压缩率\ncompressorConfig.workerThreadCount = 4;                  // 并行压缩线程数\ncompressorConfig.maxQueueSize = 1000;                    // 最大队列大小\ncompressorConfig.deleteSourceAfterSuccess = true;        // 压缩成功后删除源文件\ncompressorConfig.enableStatistics = true;                // 启用统计功能\n\n// 2. 创建并启动压缩器\nauto compressor = std::make_shared\u003cLogCompressor\u003e(compressorConfig);\ncompressor-\u003eStart();\n\n// 3. 将压缩器传递给日志记录器\nauto logger = std::make_shared\u003cLightLogWrite_Impl\u003e(\n    10000,                              // 队列大小\n    LogQueueOverflowStrategy::Block,    // 溢出策略\n    1000,                               // 批处理大小\n    compressor                          // 压缩器\n);\n\n// 4. 获取压缩统计信息\nauto stats = logger-\u003eGetCompressionStatistics();\nif (stats.totalTasks \u003e 0) {\n    std::wcout \u003c\u003c L\"总任务数: \" \u003c\u003c stats.totalTasks \u003c\u003c std::endl;\n    std::wcout \u003c\u003c L\"成功任务数: \" \u003c\u003c stats.successfulTasks \u003c\u003c std::endl;\n    std::wcout \u003c\u003c L\"失败任务数: \" \u003c\u003c stats.failedTasks \u003c\u003c std::endl;\n    std::wcout \u003c\u003c L\"原始总大小: \" \u003c\u003c stats.totalOriginalSize \u003c\u003c \" bytes\" \u003c\u003c std::endl;\n    std::wcout \u003c\u003c L\"压缩后大小: \" \u003c\u003c stats.totalCompressedSize \u003c\u003c \" bytes\" \u003c\u003c std::endl;\n    std::wcout \u003c\u003c L\"平均压缩率: \" \u003c\u003c (stats.GetAverageCompressionRatio() * 100) \u003c\u003c \"%\" \u003c\u003c std::endl;\n}\n```\n\n### 🔍 过滤器系统\n\n强大的过滤器系统，支持多种过滤方式：\n\n```cpp\n#include \"log/LogFilters.h\"\n#include \"log/CompositeFilter.h\"\n\n// 1. 级别过滤器\nauto levelFilter = std::make_shared\u003cLevelFilter\u003e(LogLevel::Warning);\nlogger-\u003eSetLogFilter(levelFilter);\n\n// 2. 关键词过滤器\nauto keywordFilter = std::make_shared\u003cKeywordFilter\u003e();\nkeywordFilter-\u003eAddIncludeKeyword(L\"error\");      // 包含\"error\"的日志\nkeywordFilter-\u003eAddIncludeKeyword(L\"warning\");\nkeywordFilter-\u003eAddExcludeKeyword(L\"debug\");      // 排除\"debug\"的日志\nlogger-\u003eSetLogFilter(keywordFilter);\n\n// 3. 正则表达式过滤器\nauto regexFilter = std::make_shared\u003cRegexFilter\u003e(L\"\\\\b(error|warning|critical)\\\\b\");\nlogger-\u003eSetLogFilter(regexFilter);\n\n// 4. 频率限制过滤器（防止日志洪泛）\nauto rateLimitFilter = std::make_shared\u003cRateLimitFilter\u003e(100, 10);  // 100消息/秒，突发10\nlogger-\u003eSetLogFilter(rateLimitFilter);\n\n// 5. 线程过滤器\nauto threadFilter = std::make_shared\u003cThreadFilter\u003e();\nthreadFilter-\u003eAddAllowedThreadId(std::this_thread::get_id());\nlogger-\u003eSetLogFilter(threadFilter);\n\n// 6. 组合过滤器（多个过滤器组合）\nauto compositeFilter = std::make_shared\u003cCompositeFilter\u003e(\n    L\"MainFilter\", CompositionStrategy::AllMustPass  // 所有过滤器都通过\n);\ncompositeFilter-\u003eAddFilter(levelFilter);\ncompositeFilter-\u003eAddFilter(keywordFilter);\nlogger-\u003eSetLogFilter(compositeFilter);\n\n// 其他组合策略：\n// - AnyCanPass: 任一过滤器通过即可\n// - MajorityMustPass: 多数通过\n// - Custom: 自定义策略\n\n// 清除过滤器\nlogger-\u003eClearLogFilter();\n\n// 检查是否有过滤器\nbool hasFilter = logger-\u003eHasLogFilter();\n```\n\n### 🎯 多输出系统\n\n支持同时输出到多个目标：\n\n```cpp\n#include \"log/ConsoleLogOutput.h\"\n#include \"log/FileLogOutput.h\"\n#include \"log/LogOutputManager.h\"\n\n// 1. 启用多输出系统\nlogger-\u003eSetMultiOutputEnabled(true);\n\n// 2. 创建控制台输出\nauto consoleOutput = std::make_shared\u003cConsoleLogOutput\u003e(\n    L\"Console\",      // 输出名称\n    true,            // 输出到stderr（错误流）\n    true,            // 启用颜色\n    false            // 不使用单独控制台\n);\n\n// 3. 创建文件输出\nauto fileOutput = std::make_shared\u003cFileLogOutput\u003e(L\"MainFile\");\nfileOutput-\u003eInitialize(L\"logs/app.log\");\n\n// 4. 添加输出\nlogger-\u003eAddLogOutput(consoleOutput);\nlogger-\u003eAddLogOutput(fileOutput);\n\n// 5. 移除输出\nlogger-\u003eRemoveLogOutput(L\"Console\");\n\n// 6. 从JSON配置文件加载\nlogger-\u003eLoadMultiOutputConfigFromJson(L\"config/log_config.json\");\n\n// 7. 保存配置到JSON文件\nlogger-\u003eSaveMultiOutputConfigToJson(L\"config/log_config.json\");\n\n// 8. 获取输出管理器\nauto outputManager = logger-\u003eGetOutputManager();\n```\n\n### 📞 回调系统\n\n支持日志事件回调通知：\n\n```cpp\n// 1. 订阅日志事件\nCallbackHandle handle = logger-\u003eSubscribeToLogEvents(\n    [](const LogCallbackInfo\u0026 info) {\n        // 回调函数在日志线程上执行，应避免阻塞操作\n        std::wcout \u003c\u003c L\"[Callback] \" \u003c\u003c info.levelString \n                   \u003c\u003c L\": \" \u003c\u003c info.message \u003c\u003c std::endl;\n    },\n    LogLevel::Warning  // 只接收Warning及以上级别\n);\n\n// 2. 取消订阅\nbool removed = logger-\u003eUnsubscribeFromLogEvents(handle);\n\n// 3. 清除所有回调\nlogger-\u003eClearAllLogCallbacks();\n\n// 4. 获取回调数量\nsize_t count = logger-\u003eGetCallbackCount();\n```\n\n---\n\n## 🎮 示例程序\n\n项目包含丰富的示例程序，展示各种功能的使用：\n\n### 主要示例文件\n\n| 示例文件 | 功能说明 |\n|---------|---------|\n| `examples/simple_demo.cpp` | 基本使用演示 |\n| `examples/demo_main.cpp` | 综合功能演示和测试框架 |\n| `examples/rotation_demo.cpp` | 日志轮转功能演示 |\n| `examples/rotation_compression_examples.cpp` | 轮转和压缩机制演示 |\n| `examples/rotation_configuration_examples.cpp` | 轮转配置详解 |\n| `examples/rotation_strategy_examples.cpp` | 各种轮转策略演示 |\n| `examples/filter_system_demo.cpp` | 过滤器系统演示 |\n| `examples/filter_serialization_demo.cpp` | 过滤器序列化演示 |\n| `examples/multioutput_json_config_demo.cpp` | 多输出JSON配置演示 |\n\n### 运行示例\n\n```bash\n# 构建项目（启用示例）\ncd LightLogWriteImplWithPanel\nmkdir build \u0026\u0026 cd build\ncmake .. -DLIGHTLOG_BUILD_EXAMPLES=ON\ncmake --build . --config Release\n\n# 运行示例程序\n# Linux/macOS:\n./bin/simple_demo\n./bin/demo_main\n./bin/rotation_demo\n\n# Windows:\n.\\bin\\Release\\simple_demo.exe\n.\\bin\\Release\\demo_main.exe\n.\\bin\\Release\\rotation_demo.exe\n```\n\n---\n\n## 📁 项目结构\n\n```text\nLightLogWriteImplWithPanel/\n├── CMakeLists.txt                          # 主CMake配置文件\n├── LICENSE                                 # GPL v3许可证\n├── README.md                               # 项目说明文档\n├── CHANGELOG.md                            # 版本变更记录\n│\n├── include/log/                            # 公共头文件目录\n│   ├── LightLogWriteImpl.h                 # 主日志类接口\n│   ├── LogCommon.h                         # 公共定义（日志级别、回调等）\n│   ├── ILogRotationManager.h               # 轮转管理器接口\n│   ├── ILogCompressor.h                    # 压缩器接口\n│   ├── LogCompressor.h                     # 压缩器实现\n│   ├── ILogFilter.h                        # 过滤器基础接口\n│   ├── LogFilters.h                        # 各种过滤器实现\n│   ├── CompositeFilter.h                   # 组合过滤器\n│   ├── FilterManager.h                     # 过滤器管理器\n│   ├── LogFilterFactory.h                  # 过滤器工厂\n│   ├── ILogOutput.h                        # 输出接口\n│   ├── ConsoleLogOutput.h                  # 控制台输出\n│   ├── FileLogOutput.h                     # 文件输出\n│   ├── LogOutputManager.h                  # 多输出管理器\n│   ├── MultiOutputLogConfig.h              # 多输出配置\n│   ├── ILogFormatter.h                     # 格式化器接口\n│   ├── BasicLogFormatter.h                 # 基础格式化器\n│   ├── RotationManagerFactory.h            # 轮转管理器工厂\n│   ├── RotationStrategies.h                # 轮转策略\n│   ├── RotationErrorHandler.h              # 轮转错误处理\n│   ├── RotationPreChecker.h                # 轮转前置检查\n│   ├── RotationStateMachine.h              # 轮转状态机\n│   ├── TransactionalRotation.h             # 事务性轮转\n│   ├── AsyncRotationManager.h              # 异步轮转管理器\n│   ├── TimeCalculator.h                    # 时间计算工具\n│   ├── UniConvAdapter.h                    # 字符编码适配器\n│   ├── DebugUtils.h                        # 调试工具\n│   └── singleton.h                         # 单例模式模板\n│\n├── src/log/                                # 实现源码目录\n│   ├── LightLogWriteImpl.cpp               # 主日志类实现\n│   ├── LogCompressor.cpp                   # 压缩器实现\n│   ├── LogFilters.cpp                      # 过滤器实现\n│   ├── CompositeFilter.cpp                 # 组合过滤器实现\n│   ├── FilterManager.cpp                   # 过滤器管理器实现\n│   ├── LogFilterFactory.cpp                # 过滤器工厂实现\n│   ├── ConsoleLogOutput.cpp                # 控制台输出实现\n│   ├── FileLogOutput.cpp                   # 文件输出实现\n│   ├── BaseLogOutput.cpp                   # 输出基类实现\n│   ├── LogOutputManager.cpp                # 多输出管理器实现\n│   ├── MultiOutputLogConfig.cpp            # 多输出配置实现\n│   ├── BasicLogFormatter.cpp               # 基础格式化器实现\n│   ├── RotationManagerFactory.cpp          # 轮转管理器工厂实现\n│   ├── RotationStrategies.cpp              # 轮转策略实现\n│   ├── RotationErrorHandler.cpp            # 轮转错误处理实现\n│   ├── RotationPreChecker.cpp              # 轮转前置检查实现\n│   ├── RotationStateMachine.cpp            # 轮转状态机实现\n│   ├── TransactionalRotation.cpp           # 事务性轮转实现\n│   ├── AsyncRotationManager.cpp            # 异步轮转管理器实现\n│   └── TimeCalculator.cpp                  # 时间计算工具实现\n│\n├── examples/                               # 示例程序目录\n│   ├── simple_demo.cpp                     # 简单演示\n│   ├── demo_main.cpp                       # 综合功能演示\n│   ├── rotation_demo.cpp                   # 轮转演示\n│   ├── rotation_compression_examples.cpp   # 轮转压缩演示\n│   ├── rotation_configuration_examples.cpp # 轮转配置演示\n│   ├── rotation_strategy_examples.cpp      # 轮转策略演示\n│   ├── filter_system_demo.cpp              # 过滤器系统演示\n│   ├── filter_serialization_demo.cpp       # 过滤器序列化演示\n│   └── multioutput_json_config_demo.cpp    # 多输出JSON配置演示\n│\n├── test/                                   # 测试程序目录\n│   ├── test_rotation.cpp                   # 轮转功能测试\n│   └── test_compressor.cpp                 # 压缩器测试\n│\n├── docs/                                   # 详细文档目录\n│   ├── rotation_strategy_guide.md          # 轮转策略指南\n│   ├── rotation_strategy_api.md            # 轮转策略API文档\n│   ├── rotation_system.md                  # 轮转系统说明\n│   ├── enhanced_filter_system.md           # 增强过滤器系统\n│   ├── filter_serialization_guide.md       # 过滤器序列化指南\n│   ├── multioutput_json_config_guide.md    # 多输出JSON配置指南\n│   ├── debug_system_guide.md               # 调试系统指南\n│   └── cmake_build_guide.md                # CMake构建指南\n│\n├── config/                                 # 配置文件示例\n│   ├── example_filter_config.json          # 过滤器配置示例\n│   └── example_multioutput_config.json     # 多输出配置示例\n│\n├── example_usage/                          # 集成示例目录\n│   ├── README.md                           # 集成使用说明\n│   ├── CMakeLists.txt                      # 示例CMake配置\n│   └── main.cpp                            # 示例主程序\n│\n├── cmake/                                  # CMake模块\n│   └── ...                                 # CMake辅助脚本\n│\n└── lib/                                    # 第三方库（包含在项目中）\n    ├── json/                               # nlohmann/json\n    ├── thread_pool/                        # BS::thread_pool\n    └── miniz/                              # miniz压缩库\n```\n\n### 关键文件说明\n\n- **主要接口**: `include/log/LightLogWriteImpl.h` - 这是你需要包含的主要头文件\n- **日志级别定义**: `include/log/LogCommon.h` - 包含日志级别、回调函数等公共定义\n- **演示程序**: `examples/demo_main.cpp` - 包含完整的功能演示和测试框架\n- **简单示例**: `examples/simple_demo.cpp` - 最简单的使用示例，适合入门\n- **构建配置**: `CMakeLists.txt` - 现代CMake配置，支持FetchContent和多种集成方式\n- **文档目录**: `docs/` - 包含详细的API文档和使用指南\n\n---\n\n## 📊 性能特性\n\n### 队列配置\n\nLightLog使用异步队列处理日志，支持两种溢出策略：\n\n```cpp\n// 阻塞策略：队列满时阻塞直到有空间\nauto logger = std::make_shared\u003cLightLogWrite_Impl\u003e(\n    10000,                              // 队列大小\n    LogQueueOverflowStrategy::Block,    // 阻塞策略\n    1000                                // 批处理大小\n);\n\n// 丢弃策略：队列满时丢弃最旧的消息\nauto logger = std::make_shared\u003cLightLogWrite_Impl\u003e(\n    10000,                              // 队列大小\n    LogQueueOverflowStrategy::DropOldest, // 丢弃策略\n    1000                                // 批处理大小\n);\n\n// 查询丢弃计数\nsize_t discarded = logger-\u003eGetDiscardCount();\nlogger-\u003eResetDiscardCount();\n```\n\n### 实际性能数据\n\n基于Windows 11 + Visual Studio 2022 Release模式测试：\n\n- **写入速度**: 100,000+ 消息/秒 (典型配置)\n- **内存占用**: \u003c 10MB (10,000条消息队列)\n- **压缩比率**: 90-95% (实测66KB→3KB)\n- **轮转耗时**: \u003c 100ms (100MB文件)\n- **批处理性能**: 1000条消息 \u003c 100ms\n\n### 压缩效果实测\n\n```text\n测试场景: 1000条结构化日志消息\n原始大小: 66.2 KB\n压缩后大小: 3.0 KB  \n压缩率: 95.45%\n空间节省: 63.2 KB\n压缩时间: \u003c 50ms\n```\n\n### 性能优化建议\n\n```cpp\n// 1. 高吞吐量配置\nauto logger = std::make_shared\u003cLightLogWrite_Impl\u003e(\n    100000,                             // 大队列减少阻塞\n    LogQueueOverflowStrategy::DropOldest, // 丢弃策略避免阻塞\n    5000                                // 大批处理提升吞吐\n);\n\n// 2. 轮转优化配置\nLogRotationConfig config;\nconfig.enableAsync = true;              // 启用异步轮转\nconfig.asyncWorkerCount = 4;            // 多工作线程\n\n// 3. 压缩优化配置\nLogCompressorConfig compConfig;\ncompConfig.compressionLevel = 1;        // 快速压缩（级别1-3）\ncompConfig.workerThreadCount = std::thread::hardware_concurrency();\n\n// 4. 禁用不需要的功能\nlogger-\u003eSetMinLogLevel(LogLevel::Info); // 过滤低级别日志\nlogger-\u003eClearLogFilter();               // 移除复杂过滤器\n```\n\n---\n\n## 🔧 配置详解\n\n### JSON配置文件\n\n多输出系统支持JSON配置文件：\n\n```json\n{\n  \"configVersion\": \"1.0\",\n  \"enabled\": true,\n  \"globalMinLevel\": 2,\n  \"outputs\": [\n    {\n      \"name\": \"MainFile\",\n      \"type\": \"File\",\n      \"enabled\": true,\n      \"minLevel\": 1,\n      \"filePath\": \"logs/app.log\",\n      \"rotation\": {\n        \"enabled\": true,\n        \"maxSizeMB\": 100,\n        \"maxFiles\": 30,\n        \"compression\": true\n      }\n    },\n    {\n      \"name\": \"Console\",\n      \"type\": \"Console\",\n      \"enabled\": true,\n      \"minLevel\": 3,\n      \"useColors\": true,\n      \"separateConsole\": false\n    }\n  ]\n}\n```\n\n### 代码配置示例\n\n```cpp\n// 1. 从JSON加载配置\nbool success = logger-\u003eLoadMultiOutputConfigFromJson(L\"config/log_config.json\");\n\n// 2. 保存配置到JSON\nlogger-\u003eSaveMultiOutputConfigToJson(L\"config/log_config_backup.json\");\n\n// 3. 代码直接配置输出\nauto fileOutput = std::make_shared\u003cFileLogOutput\u003e(L\"MyFile\");\nfileOutput-\u003eInitialize(L\"logs/my_app.log\");\nfileOutput-\u003eSetMinLevel(LogLevel::Info);\nlogger-\u003eAddLogOutput(fileOutput);\n```\n\n---\n\n## 🧪 测试\n\n### 构建测试程序\n\n```bash\n# 配置CMake（启用测试）\ncd LightLogWriteImplWithPanel\nmkdir build \u0026\u0026 cd build\ncmake .. -DLIGHTLOG_BUILD_TESTS=ON\n\n# 构建\ncmake --build . --config Release\n```\n\n### 运行测试\n\n```bash\n# Linux/macOS\n./bin/test_rotation\n./bin/test_compressor\n\n# Windows  \n.\\bin\\Release\\test_rotation.exe\n.\\bin\\Release\\test_compressor.exe\n```\n\n### 集成测试\n\n主演示程序包含完整的集成测试框架：\n\n```bash\n# 运行完整测试套件\n# Linux/macOS:\n./bin/demo_main\n\n# Windows:\n.\\bin\\Release\\demo_main.exe\n```\n\n测试模块覆盖范围：\n\n- ✅ **基础日志功能**: 各种日志级别、字符串类型\n- ✅ **回调系统**: 事件订阅、取消订阅、多回调\n- ✅ **轮转系统**: 大小轮转、时间轮转、复合策略\n- ✅ **压缩功能**: 压缩算法、压缩级别、统计信息\n- ✅ **过滤器系统**: 级别过滤、关键词过滤、组合过滤\n- ✅ **性能测试**: 吞吐量、延迟、内存使用\n\n---\n\n## 📚 API文档\n\n### 核心类和接口\n\n#### LightLogWrite_Impl - 主日志类\n\n主要的日志记录器类，提供所有日志功能。\n\n**构造函数：**\n```cpp\nLightLogWrite_Impl(\n    size_t maxQueueSize = 500000,                     // 最大队列大小\n    LogQueueOverflowStrategy strategy = Block,        // 队列溢出策略\n    size_t reportInterval = 100,                      // 丢弃报告间隔\n    std::shared_ptr\u003cILogCompressor\u003e compressor = nullptr  // 压缩器（可选）\n);\n```\n\n**核心方法：**\n```cpp\n// 文件配置\nvoid SetLastingsLogs(const std::wstring\u0026 dir, const std::wstring\u0026 baseName);\nvoid SetLogsFileName(const std::wstring\u0026 filename);\n\n// 日志记录\nvoid WriteLogContent(LogLevel level, const std::wstring\u0026 message);\nvoid WriteLogTrace(const std::wstring\u0026 message);\nvoid WriteLogDebug(const std::wstring\u0026 message);\nvoid WriteLogInfo(const std::wstring\u0026 message);\nvoid WriteLogWarning(const std::wstring\u0026 message);\nvoid WriteLogError(const std::wstring\u0026 message);\n// ... 其他级别类似\n\n// 日志级别控制\nvoid SetMinLogLevel(LogLevel level);\nLogLevel GetMinLogLevel() const;\n\n// 轮转配置\nvoid SetLogRotationConfig(const LogRotationConfig\u0026 config);\nLogRotationConfig GetLogRotationConfig() const;\nvoid ForceLogRotation();\nstd::future\u003cbool\u003e ForceLogRotationAsync();\nsize_t GetCurrentLogFileSize() const;\n\n// 回调系统\nCallbackHandle SubscribeToLogEvents(const LogCallback\u0026 callback, LogLevel minLevel);\nbool UnsubscribeFromLogEvents(CallbackHandle handle);\nvoid ClearAllLogCallbacks();\nsize_t GetCallbackCount() const;\n\n// 压缩器管理\nvoid SetCompressor(std::shared_ptr\u003cILogCompressor\u003e compressor);\nstd::shared_ptr\u003cILogCompressor\u003e GetCompressor() const;\nCompressionStatistics GetCompressionStatistics() const;\n\n// 多输出系统\nvoid SetMultiOutputEnabled(bool enabled);\nbool AddLogOutput(std::shared_ptr\u003cILogOutput\u003e output);\nbool RemoveLogOutput(const std::wstring\u0026 outputName);\nbool LoadMultiOutputConfigFromJson(const std::wstring\u0026 configPath);\nbool SaveMultiOutputConfigToJson(const std::wstring\u0026 configPath);\n\n// 过滤器系统\nvoid SetLogFilter(std::shared_ptr\u003cILogFilter\u003e filter);\nstd::shared_ptr\u003cILogFilter\u003e GetLogFilter() const;\nvoid ClearLogFilter();\nbool HasLogFilter() const;\n\n// 队列管理\nsize_t GetDiscardCount() const;\nvoid ResetDiscardCount();\n```\n\n### 详细文档\n\n更多详细信息请参考以下文档：\n\n- **[增强过滤器系统](docs/enhanced_filter_system.md)** - 过滤器的完整使用指南\n- **[轮转策略指南](docs/rotation_strategy_guide.md)** - 日志轮转策略详解\n- **[轮转系统API](docs/rotation_strategy_api.md)** - 轮转系统API参考\n- **[轮转系统说明](docs/rotation_system.md)** - 轮转系统架构说明\n- **[多输出配置](docs/multioutput_json_config_guide.md)** - JSON配置指南\n- **[过滤器序列化](docs/filter_serialization_guide.md)** - 过滤器序列化指南\n- **[调试系统](docs/debug_system_guide.md)** - 调试功能指南\n- **[CMake构建](docs/cmake_build_guide.md)** - CMake构建配置详解\n\n---\n\n## 🤝 贡献指南\n\n我们欢迎各种形式的贡献：\n\n### 如何贡献\n\n1. **Fork** 项目\n2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 创建 **Pull Request**\n\n### 开发环境设置\n\n```bash\n# 克隆仓库\ngit clone https://github.com/your-username/LightLogWriteImplWithPanel.git\n\n# 创建开发分支\ngit checkout -b develop\n\n# 安装开发依赖 (如需要)\n# 配置IDE或编辑器\n```\n\n### 代码规范\n\n- 遵循现有代码风格\n- 添加适当的注释和文档\n- 确保所有测试通过\n- 新功能需要添加相应测试\n\n---\n\n## 🐛 问题报告\n\n遇到问题？请通过以下方式报告：\n\n1. 查看 [现有Issues](https://github.com/hesphoros/LightLogWriteImplWithPanel/issues)\n2. 创建新Issue，请提供：\n   - 问题描述\n   - 复现步骤\n   - 预期行为\n   - 实际行为\n   - 环境信息（操作系统、编译器版本等）\n\n---\n\n## 📈 路线图\n\n### 版本 1.1.0 (计划中)\n\n- [ ] macOS平台支持\n- [ ] 更多过滤器类型\n- [ ] 网络日志输出\n- [ ] 性能监控面板\n\n### 版本 1.2.0 (计划中)\n\n- [ ] Python绑定\n- [ ] C#绑定\n- [ ] 配置热重载\n- [ ] 分布式日志收集\n\n### 长期规划\n\n- [ ] 云原生支持\n- [ ] Kubernetes集成\n- [ ] 监控和可观测性增强\n- [ ] 图形化管理界面\n\n---\n\n## 📄 许可证\n\n本项目采用 [GPL v3 许可证](LICENSE) - 详情请查看LICENSE文件。\n\n---\n\n## 👨‍💻 作者\n\n**hesphoros** - *项目创始人和主要开发者*\n\n- 📧 Email: \u003chesphoros@gmail.com\u003e\n- 🐙 GitHub: [@hesphoros](https://github.com/hesphoros)\n\n---\n\n## 🙏 致谢\n\n特别感谢以下开源项目和技术：\n\n- **[nlohmann/json](https://github.com/nlohmann/json)** - 优秀的JSON库，用于配置文件解析\n- **[BS::thread_pool](https://github.com/bshoshany/thread-pool)** - 高性能线程池，用于异步任务处理\n- **[UniConv](https://github.com/hesphoros/UniConv)** - 字符编码转换库\n- **[miniz](https://github.com/richgel999/miniz)** - 轻量级ZIP压缩库，提供压缩功能\n\n感谢所有为本项目贡献代码、报告问题和提供建议的开发者！\n\n---\n\n## 📞 支持\n\n如需支持，请：\n\n1. 查看 [文档](docs/) 和 [示例](examples/)\n2. 搜索 [已有Issues](https://github.com/hesphoros/LightLogWriteImplWithPanel/issues)\n3. 创建新Issue或发送邮件至 \u003chesphoros@gmail.com\u003e\n\n### 常见问题\n\n**Q: 如何在多线程环境中使用？**  \nA: LightLog完全线程安全，可以从多个线程同时调用日志方法，无需额外同步。\n\n**Q: 日志文件会自动轮转吗？**  \nA: 是的，配置好轮转策略后，日志会自动轮转。你也可以手动调用`ForceLogRotation()`强制轮转。\n\n**Q: 压缩功能会影响性能吗？**  \nA: 压缩是异步进行的，不会阻塞日志写入。你可以调整`workerThreadCount`和`compressionLevel`来平衡性能和压缩率。\n\n**Q: 如何只记录错误和警告级别的日志？**  \nA: 使用`SetMinLogLevel(LogLevel::Warning)`或设置级别过滤器。\n\n**Q: 支持Unicode字符吗？**  \nA: 完全支持，建议使用`std::wstring`接口来处理Unicode文本。\n\n---\n\n---\n\n**⭐ 如果这个项目对你有帮助，请给个星星！**\n\n[⬆ 回到顶部](#lightlog---modern-c17-logging-library)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhesphoros%2Flightlogwriteimplwithpanel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhesphoros%2Flightlogwriteimplwithpanel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhesphoros%2Flightlogwriteimplwithpanel/lists"}