格式化的打印输出
#include<stdio.h>
#include<stdarg.h>
#define LOG_NONE (-1)
#define LOG_ERROR 0
#define LOG_WARNING 1
#define LOG_INFO 2
#define LOG_DEBUG 3
void sky_log( const char *name, int i_level, const char *fmt, ... )
{
char *s_level;
switch( i_level )
{
case LOG_ERROR:
s_level = "error";
break;
case LOG_WARNING:
s_level = "warning";
break;
case LOG_INFO:
s_level = "info";
break;
case LOG_DEBUG:
s_level = "debug";
break;
default:
s_level = "unknown";
break;
}
//将格式化的内容先输出到缓冲区中
fprintf(stderr, "%s [%s]: ", name, s_level);
var_list var;
va_start(var, fmt);
vfprintf(stderr,fmt, arg);
va_end(var);
}
int main()
{
const char * test = "test";
sky_log("sky", 0, "hello vfprintf %s", test);
return 1;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
posted on 2013-09-17 14:43 agiletiger 阅读(156) 评论(0) 编辑 收藏 举报