common.c

00001 /*
00002  * Copyright (c) 2005-2012 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: common.c,v 1.6 2006/01/09 12:38:38 tat Exp $
00009  */
00010 
00011 #include "klone_conf.h"
00012 #include <time.h>
00013 #include <u/libu.h>
00014 #include <klone/klog.h>
00015 #include <klone/klogprv.h>
00016 
00017 /* each klog_*_open() will push its private data afterwards */
00018 int klog_new (int type, int threshold, const char *ident, klog_t **pkl)
00019 {
00020     klog_t *kl;
00021 
00022     dbg_return_if (pkl == NULL, ~0);
00023 
00024     kl = u_zalloc(sizeof(klog_t));
00025     dbg_err_if (kl == NULL);
00026 
00027     kl->threshold = threshold;
00028     u_strlcpy(kl->ident, ident ? ident : "", sizeof kl->ident);
00029 
00030     /* check the supplied type */
00031     switch (type)
00032     {
00033         case KLOG_TYPE_MEM:
00034         case KLOG_TYPE_FILE:
00035         case KLOG_TYPE_SYSLOG:
00036             kl->type = type;
00037             break;
00038         default:
00039             warn_err("bad klog_t type !");
00040     }
00041 
00042     /* push out the klog_t object */
00043     *pkl = kl;
00044     
00045     return 0;
00046 err:
00047     U_FREE(kl);
00048     return ~0;
00049 }
00050 
00051 const char *klog_to_str (int lev)
00052 {
00053     return (lev < KLOG_DEBUG || lev > KLOG_EMERG) ? "?" : kloglev[lev];
00054 }
00055 

←Products
Copyright © 2005-2012 - KoanLogic S.r.l. - All rights reserved