把zlog封装成模块,隐藏zlog

mylog.h

#ifndef _MY_LOG_H

#define _MY_LOG_H



int init(char *filename);

void *get_category(char * cateory_name);

void info(void *category, char *message);

void debug(void *category, char *message);

void fini();



#endif

mylog.c

#include "zlog.h"

#include "mylog.h"



int init(char *filename)

{

    return zlog_init(filename);

}



void *get_category(char *cateory_name)

{

    return zlog_get_category(cateory_name);

}



void debug(void *category, char *message)

{

    zlog_debug(category, message);

}



void info(void *category, char *message)

{

    zlog_info(category, message);

}



void fini()

{

    zlog_fini();

}

test.c

#include <stdio.h>

#include "mylog.h"



int main(int argc, char** argv)



{

    int rc;

    void *category;



    rc = init("test_hello.conf");

    if (rc) {

        printf("init failed\n");

        return -1; 

    }



    category = get_category("my_cat");

    if (!category) {

        printf("get cat fail\n");

        fini();

        return -2; 

    }



    info(category, "hello, zlog");

    debug(category, "hello, zlog");

    fini();



    return 0; 

}

你可能感兴趣的:(log)