{
if (log4c_category_is_priority_enabled(mycat, LOG4C_PRIORITY_TRACE))
{
a_list argptr;
va_start(argptr, format);
log4c_category_vlog(mycat, LOG4C_PRIORITY_TRACE, format, argptr);
va_end(argptr);
}
}
5.自定义Logout
5.1 添加在Log4c源代码中的流程
在log4c-1.2.0/src/文件夹添加相应的头文件和实现文件,如examplelayout.h和examplelayout.c文件
在am__liblog4c_la_SOURCES_DIST中添加examplelayout.c
在am_liblog4c_la_OECTS中添加examplelayout. lo
在liblog4c_la_SOURCES 中添加examplelayout.c
在pkginclude_HEADERS中添加 examplelayout.h
添加@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ examplelayout.Plo@am__quote@
在liblog4c_la_SOURCES中添加examplelayout.c
在pkginclude_HEADERS中添加examplelayout.h
添加#include <examplelayout.h>
在static const log4c_layout_type_t * const layout_types[]数组中添加新添加的layout_type函数指针
5.2在工程中添加自定义日志格式
实现自定义格式的主要函数:
static const char* cat_format(
const log4c_layout_t* a_layout,
const log4c_logging_event_t*a_event)
{
static char buffer[4096];
/*
* For this formatter we put the category up front in the log message
*/
sprintf(buffer, "[%s][LINE:%d][FILE:%s] %s", a_event->evt_category,
a_event->evt_loc->loc_line, a_event->evt_loc->loc_file, a_event->evt_msg);
return buffer;
}
const log4c_layout_type_t log4c_layout_type_cat= {
"test_cat", //格式名称,用于配置文件的设置
cat_format, //格式定义函数
5.3将自定义格式添加到Log4c的配置中:
5.4自定义格式的使用
//执行自定义格式初始化
#ff00806.自定义Appender
6.1实现自定义输出流的主要函数:
static int test_file_append(log4c_appender_t* a_appender,
const log4c_logging_event_t* a_event)
{
FILE* fp = log4c_appender_get_udata(a_appender);
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-23402-3.html
斤的慎买
他进入12海里以內了
送检和抽检完全是两个概念