[Log4c-devel] [RFC]A question about LOG4C_PRIORITY_TRACE
Brought to you by:
valtri
|
From: harryxiyou <har...@gm...> - 2011-10-13 14:11:33
|
Hi all,
When i used log4c library, i just happened to the following questions.
After i compiled helloworld.c(see the details in the following) successfully,
i ran it. It only produced two files, log.0 and log.wf.0. The contents of them
are:
$ cat log.0
20111013 13:49:55.652 NOTICE hlfslog- [helloworld.c][main][11]Hello Wrold
20111013 13:49:55.652 INFO hlfslog- [helloworld.c][main][14]3333
20111013 13:49:55.652 NOTICE hlfslog- [helloworld.c][main][17]9
$ cat log.wf.0
20111013 13:49:55.652 FATAL hlfslogwf- [helloworld.c][main][15]7
I think we should see not only INFO and NOTICE, FATAL messages.
but also TRACE,INFO messages in log.0 file and ERROR, WARN messages
in the log.wf.0 file. IOW, they should like this:
$ cat log.0
20111013 13:49:55.652 NOTICE hlfslog- [helloworld.c][main][11]Hello Wrold
20111013 13:49:55.652 INFO hlfslog- [helloworld.c][main][14]3333
20111013 13:49:55.652 TRACE hlfslog- [helloworld.c][main][16]8
20111013 13:49:55.652 NOTICE hlfslog- [helloworld.c][main][17]9
$ cat log.wf.0
20111013 13:49:55.652 ERROR hlfslogwf- [helloworld.c][main][12]111
20111013 13:49:55.652 WARN hlfslogwf- [helloworld.c][main][13]222
20111013 13:49:55.652 FATAL hlfslogwf- [helloworld.c][main][15]7
Some comments??
Thanks in advance.
Harry Wei
hlfs_log.h
----------------
#ifndef _HLFS_LOG_H
#define _HLFS_LOG_H
#include "log4c.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LOG_LEN (1024)
static char __msg_log[LOG_LEN];
static log4c_category_t *__mycat_debug = NULL;
static log4c_category_t *__mycat_info = NULL;
static log4c_category_t *__mycat_error = NULL;
static log4c_category_t *__mycat_warn = NULL;
static log4c_category_t *__mycat_fatal = NULL;
static log4c_category_t *__mycat_trace = NULL;
static log4c_category_t *__mycat_notice = NULL;
#define HLOG_NOTICE(msg, args...) { \
if (NULL == __mycat_notice) { \
__mycat_notice = log4c_category_get("hlfslog"); \
} \
memset(__msg_log, 0, LOG_LEN); \
snprintf(__msg_log, LOG_LEN, "[%s][%s][%d]%s", __FILE__, __func__,
__LINE__, msg); \
const log4c_location_info_t locinfo =
LOG4C_LOCATION_INFO_INITIALIZER(NULL); \
log4c_category_log_locinfo(__mycat_notice, &locinfo,
LOG4C_PRIORITY_NOTICE, __msg_log, ##args); \
}
#define HLOG_TRACE(msg, args...) { \
if (NULL == __mycat_trace) { \
__mycat_trace = log4c_category_get("hlfslog"); \
} \
memset(__msg_log, 0, LOG_LEN); \
snprintf(__msg_log, LOG_LEN, "[%s][%s][%d]%s", __FILE__, __func__,
__LINE__, msg); \
const log4c_location_info_t locinfo =
LOG4C_LOCATION_INFO_INITIALIZER(NULL); \
log4c_category_log_locinfo(__mycat_trace, &locinfo,
LOG4C_PRIORITY_TRACE, __msg_log, ##args); \
}
#define HLOG_FATAL(msg, args...) { \
if (NULL == __mycat_fatal) { \
__mycat_fatal = log4c_category_get("hlfslogwf"); \
} \
memset(__msg_log, 0, LOG_LEN); \
snprintf(__msg_log, LOG_LEN, "[%s][%s][%d]%s", __FILE__, __func__,
__LINE__, msg); \
const log4c_location_info_t locinfo =
LOG4C_LOCATION_INFO_INITIALIZER(NULL); \
log4c_category_log_locinfo(__mycat_fatal, &locinfo,
LOG4C_PRIORITY_FATAL, __msg_log, ##args); \
}
#define HLOG_DEBUG(msg, args...) { \
if (NULL == __mycat_debug) { \
__mycat_debug = log4c_category_get("hlfslog"); \
} \
memset(__msg_log, 0, LOG_LEN); \
snprintf(__msg_log, LOG_LEN, "[%s][%s][%d]%s", __FILE__, __func__,
__LINE__, msg); \
const log4c_location_info_t locinfo =
LOG4C_LOCATION_INFO_INITIALIZER(NULL); \
log4c_category_log_locinfo(__mycat_debug, &locinfo,
LOG4C_PRIORITY_DEBUG, __msg_log, ##args); \
}
#define HLOG_INFO(msg, args...) { \
if (NULL == __mycat_info) { \
__mycat_info = log4c_category_get("hlfslog"); \
} \
memset(__msg_log, 0, LOG_LEN); \
snprintf(__msg_log, LOG_LEN, "[%s][%s][%d]%s", __FILE__, __func__,
__LINE__, msg); \
const log4c_location_info_t locinfo =
LOG4C_LOCATION_INFO_INITIALIZER(NULL); \
log4c_category_log_locinfo(__mycat_info, &locinfo,
LOG4C_PRIORITY_INFO, __msg_log, ##args); \
}
#define HLOG_ERROR(msg, args...) { \
if (NULL == __mycat_error) { \
__mycat_error = log4c_category_get("hlfslogwf"); \
} \
memset(__msg_log, 0, LOG_LEN); \
snprintf(__msg_log, LOG_LEN, "[%s][%s][%d]%s", __FILE__, __func__,
__LINE__, msg); \
const log4c_location_info_t locinfo =
LOG4C_LOCATION_INFO_INITIALIZER(NULL); \
log4c_category_log_locinfo(__mycat_error, &locinfo,
LOG4C_PRIORITY_ERROR, __msg_log, ##args); \
}
#define HLOG_WARN(msg, args...) { \
if (NULL == __mycat_warn) { \
__mycat_warn = log4c_category_get("hlfslogwf"); \
} \
memset(__msg_log, 0, LOG_LEN); \
snprintf(__msg_log, LOG_LEN, "[%s][%s][%d]%s", __FILE__, __func__,
__LINE__, msg); \
const log4c_location_info_t locinfo =
LOG4C_LOCATION_INFO_INITIALIZER(NULL); \
log4c_category_log_locinfo(__mycat_warn, &locinfo,
LOG4C_PRIORITY_WARN, __msg_log, ##args); \
}
#endif
helloworld.c
------------------
/**
* For testing.
*
* Copyright (C) 2009, 2010, Harry Wei
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>
*/
#include <stdio.h>
#include <stdlib.h>
#include "hlfs_log.h"
int main(int argc, char** argv){
if (log4c_init()){
printf("log4c_init() failed");
}else{
HLOG_NOTICE("Hello Wrold");
HLOG_ERROR("111");
HLOG_WARN("222");
HLOG_INFO("3333");
HLOG_FATAL("7");
HLOG_TRACE("8");
HLOG_NOTICE("9");
/* Explicitly call the log4c cleanup routine */
if ( log4c_fini()){
printf("log4c_fini() failed");
}
}
return 0;
}
log4crc
-----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE log4c SYSTEM "">
<log4c version="1.2.1">
<config>
<bufsize>0</bufsize>
<debug level="2"/>
<nocleanup>0</nocleanup>
<reread>1</reread>
</config>
<category name="hlfslog" priority="debug" appender="myrollingfileappender" />
<category name="hlfslog" priority="notice" appender="myrollingfileappender" />
<category name="hlfslog" priority="trace" appender="myrollingfileappender" />
<category name="hlfslog" priority="info" appender="myrollingfileappender" />
<rollingpolicy name="myrollingpolicy" type="sizewin"
maxsize="1048576000" maxnum="10" />
<appender name="myrollingfileappender" type="rollingfile" logdir="./"
prefix="log" layout="dated" rollingpolicy="myrollingpolicy" />
<layout name="dated" type="dated"/>
<category name="hlfslogwf" priority="fatal"
appender="myrollingfileappenderwf" />
<category name="hlfslogwf" priority="error"
appender="myrollingfileappenderwf" />
<category name="hlfslogwf" priority="warn"
appender="myrollingfileappenderwf" />
<rollingpolicy name="myrollingpolicywf" type="sizewin"
maxsize="1048576000" maxnum="10" />
<appender name="myrollingfileappenderwf" type="rollingfile"
logdir="./" prefix="log.wf" layout="dated"
rollingpolicy="myrollingpolicywf" />
<layout name="dated" type="dated"/>
</log4c>
|