Custom debug functions for C/D + + development in peacetime

Source: Internet
Author: User

One, no color version
One, custom printf #include<stdio.h>#ifdef Mydebug#defineDEBUG (Arg ...) {\printf ("[debug]:%s:%s:%d---->", __file__,__function__,__line__); \ printf (arg); \ fflush (stdout); \} #else #defineDEBUG (Arg ...) {}#endif Invoke instance: DEBUG ("my debug......\n"); DEBUG ("The A is%d\n", a); Second, custom printf #ifdef DEBUG#defineD_str (_STR_) printf ("f:%s (l:%d)%s\n", __file__,__line__,_str_);#defineD_line printf ("f:%s (l:%d)-fn:%s\n", __file__,__line__,__function__);#defineD_char (_char_) printf ("f:%s (l:%d)%d\n", __file__,__line__,_char_);#defineD_hex (_hex_) printf ("f:%s (l:%d) [%x]\n", __file__,__line__,_hex_);#else #defineD_str (_STR_);#defineD_line;#defineD_char (_CHAR_);#defineD_hex (_HEX_);#endif Third, vfprintfStatic voidFprint_message_to_stdout (Const Char*format, va_list arg_ptr) { (void) vfprintf (stdout, format, arg_ptr); }

Second, color version
#defineLog_debug 0#defineLog_info 1#defineLog_warning 2#defineLog_err 3#definePrintf_error (s) \printf ("\e[1;31m[%s:%d func:%s]%s\e[0m\n", __file__, __line__, __function__, s); #definePrintf_run (s) \printf ("\e[1;32m[%s:%d func:%s]%s\e[0m\n", __file__, __line__, __function__, s); #definePrintf_warn (s) \printf ("\e[1;33m[%s:%d func:%s]%s\e[0m\n", __file__, __line__, __function__, s); #definePrintf_log (t,s) \Switch(t) \ {\ CaseLog_err: \ printf_error (s); \ Break; \  CaseLog_debug: \ Caselog_info: \ Printf_run (s); \ Break; \  Caselog_warning: \ Printf_warn (s); \default: \ printf (s); \ Break; \ }

Custom debug functions for C/D + + development in peacetime

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.