zlog学习笔记(level_list)
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)的更多相关文章
- zlog学习笔记(mdc)
mdc.h #ifndef __zlog_mdc_h #define __zlog_mdc_h #include "zc_defs.h" typedef struct zlog_m ...
- zlog学习笔记(level)
level.h /** * */ #ifndef __zlog_level_h #define __zlog_level_h #include "stdio.h" #include ...
- zlog学习笔记(zc_hashtable)
zc_hashtable.h /** * hashtable */ #ifndef __zc_hashtable_h #define __zc_hashtable_h typedef struct z ...
- zlog学习笔记(zc_arraylist)
zc_arraylist.h /** * 实现类似列表的功能 * */ #ifndef __zc_arraylist_h #define __zc_arraylist_h #define ARRAY_ ...
- zlog学习笔记(zc_profile)
zc_profile.h #ifndef __zlog_profile_h #define __zlog_profile_h #define EMPTY() #define zc_assert(exp ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- PHP-自定义模板-学习笔记
1. 开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2. 整体架构图 ...
- PHP-会员登录与注册例子解析-学习笔记
1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...
- 2014年暑假c#学习笔记目录
2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...
随机推荐
- CocoaPods常用终端命令及Profile文件简单介绍
Pod常用终端命令 pod init 创建pod文件 pod install 开始安装第三方框架,如果网上有更新,会安装最新的 pod install --verbose--no-repo-updat ...
- pod install 和 pod update的区别
pod install 和 pod update的区别 pod install(下载并安装pod) 1,当pod file文件中有“增加pod,删除pod,修改pod”的操作之后使用. 2,pod i ...
- 【C语言】C语言局部变量和全局变量
目录: [局部变量] · 定义 · 作用域 · 生命周期 · 用static修饰局部变量 [全局变量] · 定义 · 作用域 · 生命周期 1.局部变量 · 定义 在函数(代码块)内部定义的变量称为局 ...
- ReactiveCocoa框架下的MVVM模式解读
记录一些MVVM文章中关于ReactiveCocoa的代码: 实例一:带有分页的文章列表,根据文章类别过滤出文章的列表,可以进入文章详细页面 1:YFBlogListViewModel 首先了解关于列 ...
- C语言中的运算符
1. 在C语言中运算符包括:算术运算符.关系运算符.赋值运算符.逻辑运算符 2.用运算符把变量.常量连接起来的式子就是表达式 3.我们阅读一个表达式,从表达式的功能和表达式的值来看 4. 算术运算符和 ...
- 用Phaser实现Flappy Bird 游戏
How to Make a Flappy Bird in HTML5 With Phaser - Part 1 Flappy Bird is a nice little game with easy ...
- 2、HDFS和Yarn的基础学习笔记
日志 --排错 .log:通过log4j记录的,记录大部分应用程序的日志信息 .out:记录标准输出和标准错误日志,少量记录 hdfs 常用shell -ls -put < ...
- yii2开发后记
h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...
- 烂泥:apache性能测试工具ab的应用
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环.只有让服务器处在高压情况下,才能真正体现出软件.硬件等各种设置不当所暴露出的问题. 性能测试 ...
- net-snmp添加自定义MIB
我所知道的添加自定义MIB的方法有三种 1.静态加载,将生成的.c和.h文件加入到相应的位置,重新编译snmp库,优点是不需要修改配置文件,缺点是每次添加都得重新编译: 2.动态加载,将生成的.c ...