Simple encapsulation of the Zlog log library and adding color display to the debug level

Source: Internet
Author: User
Tags config log printf

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.