技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

把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; 
}

posted on 2013-10-25 10:45  codestyle  阅读(682)  评论(0)    收藏  举报