分类:
2009-03-14 09:49:25
ace log 使用说明与定制
1. ace log 主要提供的功能
ace log 以下提供的宏,由三个外部宏进行开关控制
ACE_NDEBUG = [default value = 0] 控制 1.1
ACE_NLOGGING = [default value = 0] 控制 1.2-1.6
ACE_NTRACE = [default value = 1] 控制 1.7
1.1 ACE_ASSERT(test)
1.2 ACE_HEX_DUMP((level, buffer, size [,text]))
1.2 ACE_RETURN(value)
1.3 ACE_ERROR_RETURN((level, string, ...), value)
1.4 ACE_ERROR((level, string, ...))
1.5 ACE_DEBUG((level, string, ...))
1.6 ACE_ERROR_BREAK((level, string, ...))
1.7 ACE_TRACE(string)
2. ace log serverity设置
LM_TRACE
Messages indicating function-calling sequence
LM_DEBUG
Debugging information
LM_INFO
Messages that contain information normally of use only when debugging a program
LM_NOTICE
Conditions that are not error conditions but that may require special handling
LM_WARNING
Warning messages
LM_ERROR
Error messages
LM_CRITICAL
Critical conditions, such as hard device errors
LM_ALERT
A condition that should be corrected immediately, such as a corrupted system database
LM_EMERGENCY
A panic condition, normally broadcast to all users
3. 定制日志wrapper
#include
#define LINEEND ACE_TEXT("\n")
#define DEBUG_PREFIX ACE_TEXT("[DEBUG] %t %T ")
#define WARNING_PREFIX ACE_TEXT("[WARN ] %t %T ")
#define INFO_PREFIX ACE_TEXT("[INFO ] %t %T ")
#define ERROR_PREFIX ACE_TEXT("[ERROR] %t %T ")
#define FATAL_PREFIX ACE_TEXT("[FATAL] %t %T ")
#define assert(x) ACE_ASSERT(x)
#define logtrace(x) ACE_TRACE(x)
#define logdump(buffer, size) \
ACE_HEX_DUMP(( LM_DEBUG, buffer, size))
#define _logdebug(module, fmt, ...) \
ACE_DEBUG(( LM_DEBUG, DEBUG_PREFIX module fmt LINEEND \
,##__VA_ARGS__))
#define _logwarn(module, fmt, ...) \
ACE_DEBUG(( LM_WARNING, WARNING_PREFIX module fmt LINEEND \
,##__VA_ARGS__))
#define _loginfo(module, fmt, ...) \
ACE_DEBUG(( LM_INFO, INFO_PREFIX module fmt LINEEND \
,##__VA_ARGS__))
#define _logerror(module, fmt, ...) \
ACE_ERROR(( LM_ERROR, ERROR_PREFIX module fmt LINEEND \
,##__VA_ARGS__))
#define _logfatal(module, fmt, ...) \
ACE_ERROR(( LM_CRITICAL, FATAL_PREFIX module fmt LINEEND \
,##__VA_ARGS__))
#define logdebug(x) _logdebug x
#define logwarn(x) _logwarn x
#define loginfo(x) _loginfo x
#define logerror(x) _logerror x
#define logfatal(x) _logfatal x
注意:
",##__VA_ARGS__"
当可变参数是0时通过##移除.
使用:
宏定义自己的模块
ex:
#define COMMON "[COMMON]"
logdebug((COMMON, "hello logdebug = %s", "world!"));