DEBUG ZONE

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
/**
*    COPYRIGHT NOTICE 
*    Copyright (c) 2010, ffcs     (版权声明)  
*    All rights reserved.  

*   @file  Debug.h
*   @brief 按DEBUG_ZONE输出调试消息
*
*   当宏DEBUG被打开时,根据设置的DEBUG_ZONE输出相应的消息。DEBUG_ZONE可以通过
*   修改g_debug_setting的zone_mask修改。
*
*   @version v1.0
*   @author  
*   @date    2010/11/09
*
*   修订说明:
*   2010/11/09      新作成
*/
#ifndef __DEBUG_H__
#define __DEBUG_H__
#define DEBUG_ZONE_INFOPOINT     0
#define DEBUG_ZONE_LOGMNG        1
#define DEBUG_ZONE_INIT                        2
#define DEBUG_ZONE_BASC_FTP_LOG        3

#define ZONE_INFOPOINT_MSK    (1<<DEBUG_ZONE_INFOPOINT)
#define ZONE_LOGMNG_MSK        (1<<DEBUG_ZONE_LOGMNG)
#define ZONE_INIT_MSK                (1<<DEBUG_ZONE_INIT)
#define ZONE_BASC_FTP_LOG_MSK (1<<DEBUG_ZONE_BASC_FTP_LOG)

#define ZONE_INFOPOINT    (ZONE_INFOPOINT_MSK&g_debug_setting.zone_mask)
#define ZONE_LOGMNG        (ZONE_LOGMNG_MSK&g_debug_setting.zone_mask)
#define ZONE_INIT                (ZONE_INIT_MSK&g_debug_setting.zone_mask)
#define ZONE_BASC_FTP_LOG (ZONE_BASC_FTP_LOG_MSK&g_debug_setting.zone_mask)

#define DEBUGPRINT(switch,argv) ((switch)?DebugPrintf argv:((void)0))
#ifdef DEBUG
#define DEBUGMSG(switch,argv) DEBUGPRINT(switch,argv)
#else
#define DEBUGMSG(switch,argv) ((void*)0)
#endif

void DebugPrintf(char* pstr,...)
{
    va_list vl;
    va_start(vl,pstr);
    vprintf(pstr,vl);
  va_end(vl);
}
typedef struct _DEBUG_PARAM
{
    char module_name[30];
    char zones_name[16][32];
    unsigned zone_mask;
}DEBUG_PARAM,*PDEBUG_PARAM;

DEBUG_PARAM g_debug_setting=
{
    "FTPtrans",
    {
        "infopoint",
        "logmng",
        "init",
        "basc_ftp_log",
    },
    ZONE_INFOPOINT_MSK|ZONE_LOGMNG_MSK
};
#endif
/*
int main()
{
    DEBUGMSG(ZONE_INFOPOINT,("hello world!%d",9));
  return 0;
}
*/
原文地址:https://www.cnblogs.com/hbt19860104/p/2626395.html