Now let's see how it works:
The method is as follows:
Macros that define related colors
#define Esc_start " \033["
#define esc_end "\033[0m"
#define Color_fatal " 31;40;5m"
Define Color_alert " 31;40;1m"
#define Color_crit "31;40;1m"
#define COLOR_ERROR "35;40;1m"
#define Color_warn " 33;40;1m"
#define Color_notice "34;40;1m"
#define COLOR_INFO " 32;40;1m "
#define COLOR_DEBUG" 36;40;1m "
#define COLOR_TRACE" 37;40;1m "
Encapsulating Zlog Functions
1 extern zlog_category_t * log_category;
2 extern int log_init ();
3 extern void Log_fini ();
4 #define Log_fatal (Fmt,args ...) \
5 Zlog (log_category, __file__, sizeof (__file__)-1, \
6 __func__, sizeof (__func__)-1, __line__, \
7 Zlog_level_fatal, Esc_start color_fatal fmt esc_end, # #args)
8
9
#define LOG_ERROR (FMT, args ...) \
One Zlog (log_category, __file__, sizeof (__file__)-1, \
__func__, sizeof (__func__)-1, __line__, \
Zlog_level_error, Esc_start color_error fmt esc_end, # #args)
14
#define Log_warn (FMT, args ...) \
Zlog (log_category, __file__, sizeof (__file__)-1, \
__func__, sizeof (__func__)-1, __line__, \
Zlog_level_warn, Esc_start Color_warn fmt esc_end, # #args)
19
#define Log_notice (FMT, args ...) \
Zlog (log_category, __file__, sizeof (__file__)-1, \
__func__, sizeof (__func__)-1, __line__, \
Zlog_level_notice, Esc_start color_notice fmt esc_end, # #args)
24
#define LOG_INFO (Fmt,args ...) \
Zlog (log_category, __file__, sizeof (__file__)-1, \
__func__, sizeof (__func__)-1, __line__, \
Zlog_level_info, Esc_start color_info fmt esc_end, # #args)
29
#define LOG_DEBUG (FMT, args ...) \
Zlog (log_category, __file__, sizeof (__file__)-1, \
__func__, sizeof (__func__)-1, __line__, \
Zlog_level_debug, Esc_start color_debug fmt esc_end, # #args)
Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/
Encapsulation Zlog_init,zlog_get_category,zlog_fini
1 zlog_category_t * log_category = NULL;
3 int Log_init () {
4 //initialization. config filename is fixed log.conf
5 if (Zlog_init ("log.conf")) {
6 printf ("error:zlog_init\n");
7 Zlog_fini ();
8 return-1;
9 }
category//Find category, in config file
One log_category = zlog_get_category ("My_cat");
if (!log_category) {
printf ("Error:get cat fail\n");
Zlog_fini ();
return-2;
}
return 0;
18}
void Log_fini () {
Zlog_fini ();
23}
Author: cnblogs Superperfect