当前位置:网站首页>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:设置的日志输出格式
边栏推荐
- Crawl with requests
- 表空间创建管理及控制文件管理
- 使用onvif协议操作设备
- Exclusive analysis | truth about resume and interview
- 图解网络:什么是虚拟路由器冗余协议 VRRP?
- one hot 独热码
- I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
- 11. Provider service registration of Nacos service registration source code analysis
- Error installing the specified version of pilot
- ConstraintLayout跟RelativeLayout嵌套出现的莫名奇妙的问题
猜你喜欢
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
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
8年测试总监的行业思考,看完后测试思维认知更深刻
Qt:qss custom qscrollbar instance
Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
进程与线程
Game test related tests a hero's skills (spring moves are asked more questions)
2021 reading summary (continuously updating)
. Net core - a queuing system for wechat official account
随机推荐
QT: QSS custom qtabwidget and qtabbar instances
Project management essence reading notes (VII)
8年测试工程师总结出来的《测试核心价值》与《0基础转行软件测试超全学习指南》
有赞CTO崔玉松:有赞Jarvis核心目标是使产品变得更加聪明和可靠
Solutions of n-ary linear equations and their criteria
What experience is there only one test in the company? Listen to what they say
嵌入式软件测试怎么实现自动化测试?
Hard goods | write all the codes as soon as you change the test steps? Why not try yaml to realize data-driven?
线性表的双链表
高精度室内定位技术,在智慧工厂安全管理的应用
POI excel 单元格换行
Do you really need automated testing?
Word line and bit line
MAUI Developer Day in GCR
Ext file system mechanism principle
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
读书笔记:《心若菩提》 曹德旺
项目管理精华读书笔记(六)
Hal -- writing hardware drivers
Error installing the specified version of pilot