[ global]strict init = falsebuffer min = 1024buffer max = 2MB rotate lock file= /tmp/zlog.lock[formats]normal = "%d.%us [%V][%F:%L] %m%n"[ rules ]asr_level.* "/home/test/asr.log";normal
注意:如果配置了rotate lock file项,在自己本机测试时候,注意删除一下zlog.lock文件,不然有可能锁住,导致zlog初始化失败
zlog参数配置详解[formats]%d --表示时间,例如 2018-07-20 09:32:43%us --表示微妙,例如 991437%F --表示文件,例如 test_init.c%V --表示日志等级,例如 DEBUG,INFO%L --表示行号%m --表示用户输出信息%n --表示换行normal = "%d.%us [%V][%F:%L] %m%n"[rules]类别名.* --表示打印所有级别的日志信息类别名.=DEBUG --表示打印指定级别的日志类别名.!DEBUG --表示打印非DEBUG级别的日志
#ifndef __ASR_ZLOG_H_#define __ASR_ZLOG_H_#include "zlog.h"/*日志类*/extern zlog_category_t *zc;//初始化zlogint zlogInit(const char *pcConfigPath, const char *pcModelName);//释放zlogvoid zlogDestory();#define FATAL_LOG(fmt,...) \ zlog_fatal(zc,fmt,__VA_ARGS__);#define ERROR_LOG(fmt,...) \ zlog_error(zc,fmt,__VA_ARGS__);#define WARN_LOG(fmt,...) \ zlog_warn(zc,fmt,__VA_ARGS__);#define NOTICE_LOG(fmt,...) \ zlog_notice(zc,fmt,__VA_ARGS__);#define INFO_LOG(fmt,...) \ zlog_info(zc,fmt,__VA_ARGS__);#define DEBUG_LOG(fmt,...) \ zlog_debug(zc,fmt,__VA_ARGS__);#endif
#include#include "asr_log.h"#include "comontype.h"zlog_category_t *zc;/********************************************************zlog*********************************************************//******************************************************** Func Name: initDate Created: 2018-7-20 Description: 初始化 Input: Output: Return: error code Caution: *********************************************************/int zlogInit(IN const char *pcConfigPath,IN const char *pcModelName){ int iRet = DEFAULT_ERROR; if (NULL == pcConfigPath || NULL == pcModelName) { iRet = PARAM_ERROR; return iRet; } iRet = zlog_init(pcConfigPath); if (iRet) { printf("init fail"); return DEFAULT_ERROR; } zc = zlog_get_category(pcModelName); if (!zc) { printf("zlog_get_category fail\n"); zlog_fini(); return DEFAULT_ERROR; } return RESULT_OK;}/******************************************************** Func Name: initDate Created: 2018-7-20 Description: 销毁zlog Input: Output: Return: Caution: *********************************************************/void zlogDestory(){ zlog_fini();}