hunting/utils/Log/README.md
2023-09-24 16:16:15 -07:00

44 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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