当前位置:网站首页>C语言日志库zlog基本使用
C语言日志库zlog基本使用
2022-07-03 10:02:00 【B!GGer.】
1、zlog的下载、编译与安装
git clone https://github.com/HardySimpson/zlog.git
vim src/makefile
设置安装路径PREFIX
设置工具链CC
编译问题:
relocation R_X86_64_PC32 against symbol `zlog_conf_del'......recompile with –fPIC
解决方法:REAL_CFLAGS之前增加CFLAGS += -fPIC
make
make install
2、使用手册
http://hardysimpson.github.io/zlog/UsersGuide-CN.html
3、参考配置
[global]
strict init = true
reload conf period = 0
buffer min = 1024
buffer max = 2MB
rotate lock file = self
default format = "%d(%F %T.%l) %-6V (%c:%F:%L) - %m%n"
file perms = 666
fsync period = 1K
[levels]
#TRACE = 10
#CRIT = 130, LOG_CRIT
[formats]
simple = "%m%n"
normal = "%d [%V] [%U:%L] %m%n"
[rules]
test.* >stdout; normal
test_log.* "./test.log", 1KB*4 ~ "./test-%d(%Y%m%d).#2s.log"; normal
4、参考demo
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "zlog.h"
int main(int argc, const char *argv[])
{
int rc;
zlog_category_t *c;
rc = zlog_init("./zlog.conf");//初始化
if (rc)
{
printf("init failed\n");
return -1;
}
c = zlog_get_category("test_log");//获取test_log分类和对应的规则
if (!c)
{
printf("zlog_get_category failed\n");
zlog_fini();
return -2;
}
int i = 7;
zlog_info(c, "abcdecghilklmnopqrstuvwxyz:%d", i);//写日志
zlog_fini();//清理
return 0;
}
5、说明
[rules]
test_log.DEBUG "./test.log", 1KB*4 ~ "./test-%d(%Y%m%d).#2s.log"; normal
test_log:分类
DEBUG:日志等级
"./test.log", 1KB*4 ~ "./test-%d(%Y%m%d).#2s.log"; normal:具体规则
"./test.log":日志保存路径
1KB:每个日志文件的大小
4:最多保存4个日志文件
"./test-%d(%Y%m%d).#2s.log":文件转档设置(当日志文件满1KB时进行转档保存)
normal:设置的日志输出格式
边栏推荐
- How did I grow up in the past eight years as a test engineer of meituan? I hope technicians can gain something after reading it
- BI技巧丨权限轴
- Solutions of n-ary linear equations and their criteria
- Solve the problem that pycharm Chinese input method does not follow
- 如何让让别人畏惧你
- 【obs】封装obs实现采集的基础流程
- The testing department of the company came to the king of the Post-00 roll, and the veteran exclaimed that it was really dry, but
- 可以写进简历的软件测试电商项目,不进来get一下?
- 进程与线程
- 如何成为一名高级数字 IC 设计工程师(1-4)Verilog 编码语法篇:表达式
猜你喜欢

8年测试工程师总结出来的《测试核心价值》与《0基础转行软件测试超全学习指南》

After 8 years of industry thinking, the test director has a deeper understanding of test thinking
![[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials](/img/e0/c2b1fbe99939d44201401abf1b5a72.png)
[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials

A simple method of adding dividing lines in recyclerview

面试题总结(2) IO模型,集合,NIO 原理,缓存穿透,击穿雪崩

进程与线程

What kind of living condition is a tester with a monthly salary of more than 10000?

My understanding of testing (summarized by senior testers)

面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩

字节跳动大裁员,测试工程师差点遭团灭:大厂招人背后的套路,有多可怕?
随机推荐
php服务器 与redis交互大量CLOSE_WAIT分析
如何让让别人畏惧你
What kind of living condition is a tester with a monthly salary of more than 10000?
. Net core - a queuing system for wechat official account
Probability theory: application of convolution in calculating moving average
The element form shows the relationship between elementary transformation and elementary matrix
读书笔记:《心若菩提》 曹德旺
如何成为一名高级数字 IC 设计工程师(1-4)Verilog 编码语法篇:表达式
在职美团测试工程师的这八年,我是如何成长的,愿技术人看完都有收获
行业唯一!法大大电子合同上榜36氪硬核科技企业
UI自动化测试如何走出困境?价值又如何体现?
AMS Series 1 - AMS startup process
T5 attempt
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
Qt:qss custom qscrollbar instance
Qt:qss custom QSlider instance
【obs】obs的ini格式的ConfigFile
2021 reading summary (continuously updating)
[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials
线性表的双链表