zoukankan      html  css  js  c++  java
  • Linux共享库 zlog日志

    [ global]
    strict init    = false
    buffer min = 1024
    buffer 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;
    
    //初始化zlog
    int zlogInit(const char *pcConfigPath, const char *pcModelName);
    
    //释放zlog
    void 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 <stdarg.h>
    
    #include "asr_log.h"
    #include "comontype.h"
    
    zlog_category_t *zc;
    
    
    /********************************************************
    zlog
    *********************************************************/
    
    /********************************************************
       Func Name: init
    Date 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
    ");
            zlog_fini();
            return DEFAULT_ERROR;
        }
    
        return RESULT_OK;
    }
    
    /********************************************************
       Func Name: init
    Date Created: 2018-7-20
     Description: 销毁zlog
           Input: 
          Output: 
          Return: 
         Caution: 
    *********************************************************/
    void zlogDestory()
    {
        zlog_fini();
    }
  • 相关阅读:
    Java-API-Package:java.sql百科
    Java-API-Package:java.net百科
    Java-API-Package:java.lang
    Java-API:java.lang百科
    Java-API-Package:org.springframework.stereotype
    Java-API-Package:org.springframework.beans.factory.annotation
    Java-API-Package:org.springframwork.transaction.annotation
    Java-API-Package:org.springframework.web.bind.annotation
    Java-API-Package:javax.annotation
    Java-API-Package:java.math
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/9410704.html
Copyright © 2011-2022 走看看