Files
stubser/src/ext/debug.h
Martin Winkler 28fb99e4b6 - new directory traversal method
- using debug output from debug.h
2017-03-06 12:43:23 +00:00

108 lines
3.4 KiB
C

/*
--------------------------------------------------------------------
Project : Systemsoftware MiCOM 30
Subsystem :
Modul :
--------------------------------------------------------------------
Creation date : 03.02.2012
Last change :
Version : under clearcase version control
Author : Seliger
Prog. Language : GNU-C
------------------------------------------------------------------
Description:
Some stuff to control debug messages
Definition _DEBUG_OUTPUT must be set for compilation
Activate debug messages with command line option -v
-v = DEBUG_LEVEL_INFO
-vv = DEBUG_LEVEL_WARNING
-vvv = DEBUG_LEVEL_ERROR
--------------------------------------------------------------------
*/
/*
--------------------------------------------------------------------
Change log:
Seliger First version
10.01.2012
--------------------------------------------------------------------
*/
#ifndef _DEBUG_H_INCLUDED
#define _DEBUG_H_INCLUDED
#include <stdio.h>
#include <string.h>
#define isDebugLevel(dflag) (_DEBUG_OUTPUT >= dflag)
/*!
* @brief extract only filename from __FILE__ without base path
*/
#define _DEBUG_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
/*!
* @brief Debug assert helper macro
* @param cond condition for output
* @param dflag eDebugLevel required to print output
* @param format format same as for printf
* @param args arguments for printf
*
* Condition as string is appended to the output.\n
* e.g. DEBUG_LOG_ASSERT(i >= 1, DEBUG_LEVEL_INFO, "Not allowed");\n
* New line must be appended manually
*/
#ifdef _DEBUG_OUTPUT
#define DEBUG_LOG_ASSERT(cond, dflag, format, args...) do { if(isDebugLevel(dflag) && (cond)) \
printf("%s:%d:%s():(" #cond "): " format, \
_DEBUG_FILENAME, __LINE__, __func__, ##args); } \
while (0)
#else
#define DEBUG_LOG_ASSERT(cond, dflag, format, args...) do{/* nothing */}while(0)
#endif
/*!
* @brief Debug output helper macro
* @param dflag eDebugLevel required to print output
* @param format format same as for printf
* @param args arguments for printf
*
* New line must be appended manually
*/
#ifdef _DEBUG_OUTPUT
#define DEBUG_LOG(dflag, format, args...) do { if(isDebugLevel(dflag)) \
printf("%s:%d:%s(): " format, \
_DEBUG_FILENAME, __LINE__, __func__, ##args); } \
while (0)
#else
#define DEBUG_LOG(dflag, format, args...) do{/* nothing */}while(0)
#endif
/*!
* @brief Debug output helper macro to append text without addition information
* @param dflag eDebugLevel required to print output
* @param format format same as for printf
* @param args arguments for printf
*
* New line must be appended manually
*/
#ifdef _DEBUG_OUTPUT
#define DEBUG_LOG_APPEND(dflag, format, args...) do { if(isDebugLevel(dflag)) \
printf(format, ##args); } \
while (0)
#else
#define DEBUG_LOG_APPEND(dflag, format, args...) do{/* nothing */}while(0)
#endif
typedef enum _EDEBUGLEVEL
{
DEBUG_LEVEL_ALWAYS = 0, /* DEBUG_LOGs are visible regardless of DEBUG_LEVEL */
DEBUG_LEVEL_INFO = 1, /* Visible when application started with -v */
DEBUG_LEVEL_WARNING = 2, /* Visible when application started with -vv */
DEBUG_LEVEL_ERROR = 3,
/* Visible when application started with -vvv */
} eDebugLevel;
#endif /* #ifndef _DEBUG_H_INCLUDED */