文章目录
- 系列文章目录
- 目录结构
- bench目录
- example目录
- include
- src目录
- 测试目录
源码的版本是v1.x
通过cloc命令进行代码统计
------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C/C++ Header 104 6521 3730 33410 C++ 34 635 264 3130 CMake 7 92 82 433 Markdown 1 64 0 402 YAML 2 33 18 218 SVG 1 0 0 43 reStructuredText 1 5 0 22 Python 1 4 0 13 Bourne Shell 1 4 0 12 ------------------------------------------------------------------------------- SUM: 152 7358 4094 37683 -------------------------------------------------------------------------------
可以看到总的代码量还是不小的。
但是头文件有3w多行,源文件只有3130行
通过tree命令看一下,好家伙几乎全是头文件
bench目录bench目录是值得研究的,从其中可以通过看它测试了哪些东西,来判断这个项目核心点是什么。bench应该也是覆盖了几乎所有的使用场景的。话说学习都是从使用开始的。所以研究它有重要意义。
├── bench │ ├── async_bench.cpp │ ├── bench.cpp │ ├── CMakeLists.txt │ ├── formatter-bench.cpp │ ├── latency.cpp │ └── utils.h ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C++ 4 98 95 498 CMake 1 8 5 28 C/C++ Header 1 6 4 24 ------------------------------------------------------------------------------- SUM: 6 112 104 550 -------------------------------------------------------------------------------
bench有四个cpp文件,分别测试了四个指标:异步的日志、同步的日志、格式化效率测试、延迟测试。还有一个utils工具。
example目录一个使用示例文件,README.md中的示例都在这里,可以编译运行下看看
├── example │ ├── CMakeLists.txt │ └── example.cpp ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C++ 1 49 70 258 CMake 1 4 8 11 ------------------------------------------------------------------------------- SUM: 2 53 78 269 -------------------------------------------------------------------------------include
这个可以说是该项目的核心了。spd日志库说其可以支持只使用头文件来运行,看来其精华都在这里了。我也比较好奇,头文件一般是一些类定义和接口,若要附带实现,那么各类之间的引用其实是很难处理的。所以它代码实现是如何组织的?
└── spdlog ├── async.h ├── async_logger.h ├── async_logger-inl.h ├── cfg │ ├── argv.h │ ├── env.h │ ├── helpers.h │ └── helpers-inl.h ├── common.h ├── common-inl.h ├── details │ ├── backtracer.h │ ├── backtracer-inl.h │ ├── circular_q.h │ ├── console_globals.h │ ├── file_helper.h │ ├── file_helper-inl.h │ ├── fmt_helper.h │ ├── log_msg_buffer.h │ ├── log_msg_buffer-inl.h │ ├── log_msg.h │ ├── log_msg-inl.h │ ├── mpmc_blocking_q.h │ ├── null_mutex.h │ ├── os.h │ ├── os-inl.h │ ├── periodic_worker.h │ ├── periodic_worker-inl.h │ ├── registry.h │ ├── registry-inl.h │ ├── synchronous_factory.h │ ├── tcp_client.h │ ├── tcp_client-windows.h │ ├── thread_pool.h │ ├── thread_pool-inl.h │ ├── udp_client.h │ ├── udp_client-windows.h │ └── windows_include.h ├── fmt │ ├── bin_to_hex.h │ ├── bundled │ │ ├── args.h │ │ ├── chrono.h │ │ ├── color.h │ │ ├── compile.h │ │ ├── core.h │ │ ├── fmt.license.rst │ │ ├── format.h │ │ ├── format-inl.h │ │ ├── locale.h │ │ ├── os.h │ │ ├── ostream.h │ │ ├── printf.h │ │ ├── ranges.h │ │ └── xchar.h │ ├── chrono.h │ ├── compile.h │ ├── fmt.h │ ├── ostr.h │ ├── ranges.h │ └── xchar.h ├── formatter.h ├── fwd.h ├── logger.h ├── logger-inl.h ├── pattern_formatter.h ├── pattern_formatter-inl.h ├── sinks │ ├── android_sink.h │ ├── ansicolor_sink.h │ ├── ansicolor_sink-inl.h │ ├── base_sink.h │ ├── base_sink-inl.h │ ├── basic_file_sink.h │ ├── basic_file_sink-inl.h │ ├── daily_file_sink.h │ ├── dist_sink.h │ ├── dup_filter_sink.h │ ├── hourly_file_sink.h │ ├── mongo_sink.h │ ├── msvc_sink.h │ ├── null_sink.h │ ├── ostream_sink.h │ ├── qt_sinks.h │ ├── ringbuffer_sink.h │ ├── rotating_file_sink.h │ ├── rotating_file_sink-inl.h │ ├── sink.h │ ├── sink-inl.h │ ├── stdout_color_sinks.h │ ├── stdout_color_sinks-inl.h │ ├── stdout_sinks.h │ ├── stdout_sinks-inl.h │ ├── syslog_sink.h │ ├── systemd_sink.h │ ├── tcp_sink.h │ ├── udp_sink.h │ ├── wincolor_sink.h │ ├── wincolor_sink-inl.h │ └── win_eventlog_sink.h ├── spdlog.h ├── spdlog-inl.h ├── stopwatch.h ├── tweakme.h └── version.h ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C/C++ Header 99 3342 2600 19602 reStructuredText 1 5 0 22 ------------------------------------------------------------------------------- SUM: 100 3347 2600 19624 -------------------------------------------------------------------------------
浏览下来,主要分几个模块:配置模块、细节模块、格式化模块、sinks模块。还有一些散放的头文件,猜测这些头文件依赖以上几个模块,对几个模块进行了封装,并对外提供使用接口
src目录文件并不多,仅有7个,大致对应了头文件中的几大模块和几个重要的散放头文件。但也并没有一一对应。而且源码文件只有180行,少的让人吃惊,测试文件都比它多的多。可想而知,那些头文件有多么重要与精妙
async、fmt、spdlog、stdout_sinks是有对应的同名头文件的
file_sinks、color_sinks、cfg则没有。其中
- color_sinks有一个stdout_color_sinks.h与它对应。
- cfg应该对应整个cfg模块。
- file_sinks有一大堆各式各样的file_sink与它对应。
├── src │ ├── async.cpp │ ├── cfg.cpp │ ├── color_sinks.cpp │ ├── file_sinks.cpp │ ├── fmt.cpp │ ├── spdlog.cpp │ └── stdout_sinks.cpp ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C++ 7 45 30 180 ------------------------------------------------------------------------------- SUM: 7 45 30 180 -------------------------------------------------------------------------------测试目录
测试文件应该能够比bench目录的文件提供更为详尽的使用信息。作为看不懂代码时的辅助使用比较好。
└── tests
├── catch.hpp
├── catch.license
├── CMakeLists.txt
├── includes.h
├── main.cpp
├── test_async.cpp
├── test_backtrace.cpp
├── test_cfg.cpp
├── test_create_dir.cpp
├── test_daily_logger.cpp
├── test_dup_filter.cpp
├── test_errors.cpp
├── test_eventlog.cpp
├── test_file_helper.cpp
├── test_file_logging.cpp
├── test_fmt_helper.cpp
├── test_macros.cpp
├── test_misc.cpp
├── test_mpmc_q.cpp
├── test_pattern_formatter.cpp
├── test_registry.cpp
├── test_sink.h
├── test_stdout_api.cpp
├── test_stopwatch.cpp
├── test_systemd.cpp
├── test_time_point.cpp
├── utils.cpp
└── utils.h
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C/C++ Header 4 3173 1126 13784
C++ 22 443 69 2194
CMake 1 10 3 57
-------------------------------------------------------------------------------
SUM: 27 3626 1198 16035
-------------------------------------------------------------------------------



