Add FILE log util

This commit is contained in:
bnnm 2017-09-17 03:38:11 +02:00
parent 82a9198fc5
commit ccc8c53146

View File

@ -83,6 +83,7 @@ void concatn(int length, char * dst, const char * src);
/* Simple stdout logging for debugging and regression testing purposes. /* Simple stdout logging for debugging and regression testing purposes.
* Needs C99 variadic macros. */ * Needs C99 variadic macros. */
#ifdef VGM_DEBUG_OUTPUT #ifdef VGM_DEBUG_OUTPUT
/* equivalent to printf when condition is true */ /* equivalent to printf when condition is true */
#define VGM_ASSERT(condition, ...) \ #define VGM_ASSERT(condition, ...) \
do { if (condition) printf(__VA_ARGS__); } while (0) do { if (condition) printf(__VA_ARGS__); } while (0)
@ -92,6 +93,9 @@ void concatn(int length, char * dst, const char * src);
/* prints file/line/func */ /* prints file/line/func */
#define VGM_LOGF() \ #define VGM_LOGF() \
do { printf("%s:%i '%s'\n", __FILE__, __LINE__, __func__); } while (0) do { printf("%s:%i '%s'\n", __FILE__, __LINE__, __func__); } while (0)
/* prints to a file */
#define VGM_LOGT(txt, ...) \
do { FILE *fl = fopen(txt,"a+"); if(fl){fprintf(fl,__VA_ARGS__); fflush(fl);} fclose(fl); } while(0)
/* prints a buffer/array */ /* prints a buffer/array */
#define VGM_LOGB(buf, buf_size, bytes_per_line) \ #define VGM_LOGB(buf, buf_size, bytes_per_line) \
do { \ do { \
@ -102,13 +106,15 @@ void concatn(int length, char * dst, const char * src);
} \ } \
printf("\n"); \ printf("\n"); \
} while (0) } while (0)
#else
#else/*VGM_DEBUG_OUTPUT*/
#define VGM_ASSERT(condition, ...) /* nothing */ #define VGM_ASSERT(condition, ...) /* nothing */
#define VGM_LOG(...) /* nothing */ #define VGM_LOG(...) /* nothing */
#define VGM_LOGF() /* nothing */ #define VGM_LOGF() /* nothing */
#define VGM_LOGT() /* nothing */
#define VGM_LOGB(buf, buf_size, bytes_per_line) /* nothing */ #define VGM_LOGB(buf, buf_size, bytes_per_line) /* nothing */
#endif #endif/*VGM_DEBUG_OUTPUT*/
#endif #endif