日志项目详解
This is a page about »日志项目详解«.
详解 tlog 日志项目
日志level、日志时间、日志flag和日志info
tlog_level
- debug 0
- info 1
- notice 2
- error 3
- fatal 4
- off 5
- end 6
tlog_time
usec、mon、mday、hour、min、sec
日志flag
- TLOG_NOCOMPRESS 1
- TLOG_SEGMENT 10
- TLOG_MULTI_WRITE 100
- TLOG_NONBLOCK 1000
- TLOG_SCREEN 10000
- TLOG_SUPPORT_FORK 100000
- TLOG_SCREEN_COLOR 1000000
- TLOG_FORMAT_NO_PREFIX 10000000
日志info
- level
- file
- func
- line
- time
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 关闭 日志流
- tlog_ext
- tlog_write_log
- tlog_setlevel
- tlog_long_enabled
- tlog_getlevel
- tlog_set_logfile
- tlog_get_level_string
- tlog_set_maxlog_count
- tlog_init
- tlog_exit
- tlog_reg_format_func –> tlog_format_func
- tlog_set_early_printf
- tlog_reg_early_printf_callback –> tlog_early_print_func
- tlog_reg_early_printf_output_callback
- tlog_get_root
- tlog_open
- tlog_write
- tlog_close
- tlog_rename_logfile
- tlog_printf 打印日志到日志流
- tlog_vprintf print log to log stream with ap
- tlog_logscreen enbale log to screen
- tlog_reg_output_func –> tlog_output_func
- tlog_set_private
- tlog_get_private
- tlog_localtime
- tlog_set_maxline_size
- tlog_logcount set max log count
- tlog_set_permission set log file and archive permission
- tlog_stdout_with_color
tlog.c
- 编译优化部分
#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
检查是否还有日志正在压缩,等待压缩指令结束