张不大的博客

日志项目详解

This is a page about »日志项目详解«.

详解 tlog 日志项目

日志level、日志时间、日志flag和日志info

tlog_level

  1. debug 0
  2. info 1
  3. notice 2
  4. error 3
  5. fatal 4
  6. off 5
  7. end 6

tlog_time

usec、mon、mday、hour、min、sec

日志flag

日志info

tlog

tlog 可变参数宏定义

// 定于你 tlog_ext 函数,其中 第6个参数采用 printf 格式,从第7个参数采用 可变参数,而且 第6个参数不能为空
extern int tlog_ext(tlog_level level, const char* file, int line, const char* func, void* userptr, const char* format, ...) __attribute((format( printf, 6, 7))) __attribute__((nonnull(6)))

tlog_reg_format_func customize log output format

the tlog_format_func 使用snprintf 或者vsnprintf 格式把日志定向到buffer tlog_format_func 需要使用 tlog_reg_format_fun register

tlog_open

打卡一个新的日志流需要使用 tlog_close 关闭handler

tlog_write 把 buffer 写入日志文件

tlog_close 关闭 日志流

  1. tlog_ext
  2. tlog_write_log
  3. tlog_setlevel
  4. tlog_long_enabled
  5. tlog_getlevel
  6. tlog_set_logfile
  7. tlog_get_level_string
  8. tlog_set_maxlog_count
  9. tlog_init
  10. tlog_exit
  11. tlog_reg_format_func –> tlog_format_func
  12. tlog_set_early_printf
  13. tlog_reg_early_printf_callback –> tlog_early_print_func
  14. tlog_reg_early_printf_output_callback
  15. tlog_get_root
  16. tlog_open
  17. tlog_write
  18. tlog_close
  19. tlog_rename_logfile
  20. tlog_printf 打印日志到日志流
  21. tlog_vprintf print log to log stream with ap
  22. tlog_logscreen enbale log to screen
  23. tlog_reg_output_func –> tlog_output_func
  24. tlog_set_private
  25. tlog_get_private
  26. tlog_localtime
  27. tlog_set_maxline_size
  28. tlog_logcount set max log count
  29. tlog_set_permission set log file and archive permission
  30. tlog_stdout_with_color

tlog.c

  1. 编译优化部分
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif

#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif

tlog 流程

tlog_init

tlog_init 需要 初始化配置 tlog_open,需要注册 log output func (_tlog_reg_output_func),以及tlog.root_format

重点注意 _tlog_reg_func、tlog.root_format
创建 attr 线程 执行 _tlog_work

_tlog_work

检查是否还有日志正在压缩,等待压缩指令结束

#c/c++