# 1. 日志库    日志库主要辅助调试和测试。 ## 1.1. 基本需求: 1. 日志类型:info / error / warning / trace ; 2. 通过预编译选择开启 / 关闭; 3. 通过多态动态加载 / 卸载; 4. 通过预编译加载 / 卸载某个模块的日志; ## 1.2. 参考 * 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() ```