A example of Log4c

来源:互联网 发布:杭州淘宝代运营hzjttp 编辑:程序博客网 时间:2024/05/02 01:17
#include <stdio.h>
#include "log4c.h"

int main(int argc,char **argv){
    int rc;
    log4c_category_t  *mycat=NULL:
    if(log4c_init()){                       // 1 step
       printf("log4c_init() failed/n");
       rc=1;
    }
    else{
       mycat=log4c_category_get("log4c.helloworld");     //2 step
       log4c_category_log(mycat,LOG4C_PRIORITY_TRACE,"Hello world/n");  //3 step
       if(log4c_fini()){  //4 step
             printf("log4c_fini() failed/n");
       }
    }
}


The most important of run this program is setting configuration file ---log4crc.

Exp:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE log4c SYSTEM "">

<log4c version="1.2.1">

    <config>
        <bufsize>0</bufsize>
        <debug level="2"/>
        <nocleanup>0</nocleanup>
        <reread>1</reread>
    </config>
   
    <rollingpolicy name="myrollingpolicy" type="sizewin" maxsize="1024" maxnum="10" />

    <category name="log4c.helloworld" priority="trace" appender="startrun"/>


    <appender name="startrun" type="rollingfile" logdir="." prefix="logfile" layout="none"       rollingpolicy="myrollingpolicy" />
    <appender name="stdout" type="stream" layout="basic"/>
    <appender name="stderr" type="stream" layout="dated"/>
    <appender name="run.log" type="stream" layout="none"/>
    <appender name="syslog" type="syslog" layout="basic"/>


    <layout name="basic" type="basic"/>
    <layout name="dated" type="dated"/>
    <layout name="catlayout" type="you can set the cat format"/>
    <layout name="xmllayout" type="you can set the xml format"/>
    <layout name="none" type="none"/>
    <layout name="userlayout" type="you can set other types output format "/>
   
</log4c>

原创粉丝点击