hunting/utils/Log
2024-03-12 21:55:44 +08:00
..
abstract Add new log module. 2023-09-08 22:44:13 -07:00
include backup. 2023-09-24 16:16:15 -07:00
src zhoulongyu; 添加头文件<iostream>,解决变异报错 2023-11-27 23:57:08 +08:00
CMakeLists.txt Improve:compile speed. 2024-03-12 21:55:44 +08:00
README.md backup. 2023-09-24 16:16:15 -07:00

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()