zoukankan      html  css  js  c++  java
  • zlog小试(C语言日志工具)

    test.c

    #include <stdio.h> 
    #include "zlog.h"
    
    int main(int argc, char** argv)
    
    {
        int rc;
        zlog_category_t *c;
    
        rc = zlog_init("test_hello.conf");
        if (rc) {
            printf("init failed
    ");
            return -1; 
        }
    
        c = zlog_get_category("my_cat");
        if (!c) {
            printf("get cat fail
    ");
            zlog_fini();
            return -2; 
        }
    
        zlog_info(c, "hello, zlog");
        zlog_debug(c, "hello, zlog");
        zlog_fini();
    
        return 0; 
    }

    test_hello.conf

    [formats]
    simple = "%d(%F %T %ms) %m%n"
    
    [rules]
    # my_cat.INFO    >stdout; simple 
    my_cat.INFO    "test.log"; simple 

    编译命令

    gcc test.c -lzlog -I /usr/local/include/ -L /usr/local/lib/

    说明

    test_hello.conf 需要和可执行文件在同一目录,如果找不到或者配置文件里的配置不正确zlog_init都会报告初始化失败 %m是用户需要记录的message从info,debug函数传入,%n是换行符 %d(...) 表示配置的是日期时间选项,日志的时间是非常非常重要的,只有对程序各个环节在执行时消耗的时间有大致的了解,才能知道程序性能的瓶颈在哪里,以及找对应的解决办法%(%F %T %ms)分别是(年-月-日)日期,时间,毫秒, #号是注释 >stdout 表示日志输出到终端,"test.log"则表示日志输出到文件,直接写文件名日志就会被输出到可执行文件所在目录

  • 相关阅读:
    Spring知识整理
    业务开发(四)—— 服务器
    TCP/IP协议知识整理
    XSS
    Java并发编程(一) —— 线程
    业务开发(三)—— 前端
    Effective Java——(一)创建和销毁对象
    Java编程思想——异常
    Git使用
    网络基础(一)
  • 原文地址:https://www.cnblogs.com/code-style/p/3386065.html
Copyright © 2011-2022 走看看