level_list.h

/**
*
*/ #ifndef __zlog_level_list_h
#define __zlog_level_list_h zc_arraylist_t *zlog_level_list_new(void);
void zlog_level_list_del(zc_arraylist_t *levels);
void zlog_level_list_profile(zc_arraylist_t *levels, int flag); /* notice */
int zlog_level_list_set(zc_arraylist_t *levels, char *line); /* notice */
zlog_level_t *zlog_level_list_get(zc_arraylist_t *levels, int l); /* notice */
int zlog_level_init_atoi(zc_arraylist_t *level, char *str); #endif

level_list.c

#include <stdio.h>
#include <ctype.h>
#include <errno.h> #include "zc_defs.h"
#include "level.h"
#include "level_list.h" void zlog_level_list_profile(zc_arraylist_t *levels, int flag){
int i;
zlog_level_t *a_level; zc_assert(levels,);
zc_profile(flag, "---level_list[%p]", levels);
zc_arraylist_foreach(levels, i, a_level){
/*skip empty slots*/
if(a_level){
zlog_level_profile(a_level, flag);
}
}
return ;
} //----------------------------------------------------------------------
void zlog_level_list_del(zc_arraylist_t *levels){
zc_assert(levels,);
zc_arraylist_del(levels);
zc_debug("zc_level_list_del[%p]", levels);
return ;
} int zlog_level_list_set(zc_arraylist_t *levels, char *line){
zlog_level_t *a_level;
a_level = zlog_level_new(line);
if(!a_level){
zc_error("zlog_level_new fail");
return -;
}
if(zc_arraylist_set(levels, a_level->int_level, a_level)){
zc_error("zc_arraylist_set fail");
goto err;
}
return ;
err:
zc_error("line[%s]", line);
zlog_level_del(a_level);
return -;
} static int zlog_level_list_set_default(zc_arraylist_t *levels){
return zlog_level_list_set(levels, "* = 0, LOG_INFO")
|| zlog_level_list_set(levels, "DEBUG = 20, LOG_DEBUG")
|| zlog_level_list_set(levels, "INFO = 40, LOG_INFO")
|| zlog_level_list_set(levels, "WARN = 80, LOG_WARNING")
|| zlog_level_list_set(levels, "ERROR = 100, LOG_ERR")
|| zlog_level_list_set(levels, "FATAL = 120, LOG_ALERT")
|| zlog_level_list_set(levels, "UNKNOWN = 254, LOG_ERR")
|| zlog_level_list_set(levels, "! = 255, LOG_INFO");
} zc_arraylist_t *zlog_level_list_new(void){
zc_arraylist_t *levels;
levels = zc_arraylist_new((zc_arraylist_del_fn) *zlog_level_del);
if(!levels){
zc_error("zc_arraylist_new fail");
return NULL;
}
if(zlog_level_list_set_default(levels)){
zc_error("zlog_level_set_default faile");
goto err;
}
//zlog_level_list_profile(levels, ZC_DEBUG);
return levels;
err:
zc_arraylist_del(levels);
return NULL;
} zlog_level_t *zlog_level_list_get(zc_arraylist_t *levels, int l){
zlog_level_t *a_level;
#if 0 #endif a_level = zc_arraylist_get(levels, l);
if(a_level){
return a_level;
}else{
zc_error("l[%d] not in (0, 254), or has no level defined,"
"see configure file define, set to UNKOWN", l);
return zc_arraylist_get(levels, );
}
} //------------------------------------------------------------------
int zlog_level_list_atoi(zc_arraylist_t *levels, char *str){
int i;
zlog_level_t *a_level; if(str == NULL || *str == '\0'){
zc_error("str is [%s], can't find level", str);
return -;
} zc_arraylist_foreach(levels, i, a_level){
if(a_level && STRICMP(str, ==, a_level->str_uppercase)){
return i;
}
} zc_error("str[%s] can't found in level list", str);
return -;
}

测试 test_level_list.c

#include "zc_defs.h"
#include "level.h"
#include "level_list.h" #include "zc_profile.c"
#include "zc_arraylist.c"
#include "level.c"
#include "level_list.c" int main(){
zc_arraylist_t *levels = zlog_level_list_new(); zlog_level_list_set(levels, "FATAL = 110, LOG_ERR"); zlog_level_list_profile(levels, ZC_DEBUG); zlog_level_t *a_level = zlog_level_list_get(levels, ); zlog_level_list_del(levels);
}

zlog学习笔记(level_list)的更多相关文章

  1. zlog学习笔记(mdc)

    mdc.h #ifndef __zlog_mdc_h #define __zlog_mdc_h #include "zc_defs.h" typedef struct zlog_m ...

  2. zlog学习笔记(level)

    level.h /** * */ #ifndef __zlog_level_h #define __zlog_level_h #include "stdio.h" #include ...

  3. zlog学习笔记(zc_hashtable)

    zc_hashtable.h /** * hashtable */ #ifndef __zc_hashtable_h #define __zc_hashtable_h typedef struct z ...

  4. zlog学习笔记(zc_arraylist)

    zc_arraylist.h /** * 实现类似列表的功能 * */ #ifndef __zc_arraylist_h #define __zc_arraylist_h #define ARRAY_ ...

  5. zlog学习笔记(zc_profile)

    zc_profile.h #ifndef __zlog_profile_h #define __zlog_profile_h #define EMPTY() #define zc_assert(exp ...

  6. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  7. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  8. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  9. 2014年暑假c#学习笔记目录

    2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...

随机推荐

  1. Android打开相机和打开相册

    打开相机 /** * 选择相机 */ private void showCamera() { // 跳转到系统照相机 Intent cameraIntent = new Intent(MediaSto ...

  2. OC NSDictionary

    OC NSDictionary NSDictionary初始化 NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:@ ...

  3. JSON TO NSDictionary Mac & iOS

    NSString * jsonPath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Cont ...

  4. 手把手教你使用Git

    一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...

  5. 详解 Spotlight on Unix 监控Linux服务器

    1.安装 Spotlight on Unix 下载地址:http://yunpan.cn/QNWyEEvNS4xc9  访问密码 1c7d 傻瓜安装 2.配置spotlight登陆用户,注意spotl ...

  6. Microsoft.Owin.Hosting 实现启动webapp.dll

    Microsoft.Owin.Hosting 下面是 asp.net core 实现 using System;using System.Collections.Generic;using Syste ...

  7. 基于微软平台IIS/ASP.NET开发的大型网站有哪些呢?

    首先说明一下,本文绝不是要说Microsoft平台多么好,多么牛.只是要提醒一些LAMP/JAVA平台下的同志们,微软平台不至于像你们说的,和想象的那么不堪!只是你们自己不知道而已.同时,也希望广大M ...

  8. redmine + apache + mod_fcgid

    redmine默认是用webrick启动的,这种方法不适合生产环境,最好部署在apache下,本文介绍如何通过mod_fcgid启动. 首先要有一个能够启动的redmine,可以通过我之前的博文查看: ...

  9. java多线程与单例模式(Singleton)不得不说的故事

    转发自:http://blog.csdn.net/ligang7560/article/details/50890282 单例模式的多种实现方式 我们都知道单例模式有几种常用的写法: - 饿汉模式 - ...

  10. [转载]DBA的特质第二部分:性格

    本文转自http://www.searchdatabase.com.cn/showcontent_84382.htm 支持原创.尊重原创,分享知识! 在本系列文章中,笔者将谈一谈数据库管理员(DBA) ...