.. | ||
abstract | ||
include | ||
src | ||
CMakeLists.txt | ||
README.md |
1. 日志库
日志库主要辅助调试和测试。
1.1. 基本需求:
- 日志类型:info / error / warning / trace ;需要打印出运行时间,文件名和行号;
- 不同日志类型显示不同的颜色;
- 通过预编译选择开启 / 关闭;
- 通过多态动态加载 / 卸载;
- 通过预编译加载 / 卸载某个模块的日志;
1.2. 接口描述
- 开启日志保存功能,把运行日志保存到制定目录;
- 开启日志保存功能,只保存error和trace的日志;
接口示例:
示例代码
1.3. 参考
- CMakeLists.txt脚本代码:
//build/global_config.cmake
// 文件名宏定义__F_FILE__,指定文件实现打印文件名 + 行号功能
// 不使用系统宏__FILE__是因为系统宏会打印绝对路径,日志阅读性差
function(define_file_name target)
get_target_property(source_files "${target}" SOURCES)
foreach(source_file ${source_files})
get_property(defs SOURCE "${source_file}"
PROPERTY COMPILE_DEFINITIONS)
get_filename_component(file_name "${source_file}" NAME)
list(APPEND defs "__F_FILE__=/"${file_name}/"")
set_property(
SOURCE "${source_file}"
PROPERTY COMPILE_DEFINITIONS ${defs})
endforeach()
endfunction()
// LOG_DISABLE日志使能宏,指定文件开启 / 关闭日志功能
function(log_disable target)
get_target_property(source_files "${target}" SOURCES)
foreach(source_file ${source_files})
get_property(defs SOURCE "${source_file}"
PROPERTY COMPILE_DEFINITIONS)
get_filename_component(file_name "${source_file}" NAME)
list(APPEND defs "LOG_DISABLE")
set_property(
SOURCE "${source_file}"
PROPERTY COMPILE_DEFINITIONS ${defs})
endforeach()
endfunction()