hunting/utils/Log/README.md
2024-06-15 08:36:44 +08:00

57 lines
1.9 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. 通过多态动态加载 / 卸载;
5. 通过预编译加载 / 卸载某个模块的日志;
## 1.2. 接口描述
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()
```