1 /* 2 * libiio - Library for interfacing industrial I/O (IIO) devices 3 * 4 * Copyright (C) 2014 Analog Devices, Inc. 5 * Author: Paul Cercueil <paul.cercueil@analog.com> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * */ 18 19 #ifndef DEBUG_H 20 #define DEBUG_H 21 22 #include "iio-config.h" 23 24 #include <stdio.h> 25 26 #define NoLog_L 0 27 #define Error_L 1 28 #define Warning_L 2 29 #define Info_L 3 30 #define Debug_L 4 31 32 /* -------------------- */ 33 34 #ifdef WITH_COLOR_DEBUG 35 #ifndef COLOR_DEBUG 36 #define COLOR_DEBUG "\e[0;32m" 37 #endif 38 #ifndef COLOR_WARNING 39 #define COLOR_WARNING "\e[01;35m" 40 #endif 41 #ifndef COLOR_ERROR 42 #define COLOR_ERROR "\e[01;31m" 43 #endif 44 45 #define COLOR_END "\e[0m" 46 #endif 47 48 #if (LOG_LEVEL >= Debug_L) 49 # ifdef COLOR_DEBUG 50 # define DEBUG(str, ...) \ 51 fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, ##__VA_ARGS__) 52 # else 53 # define DEBUG(...) \ 54 fprintf(stdout, "DEBUG: " __VA_ARGS__) 55 # endif 56 #else 57 #define DEBUG(...) do { } while (0) 58 #endif 59 60 #if (LOG_LEVEL >= Info_L) 61 # ifdef COLOR_INFO 62 # define INFO(str, ...) \ 63 fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__) 64 # else 65 # define INFO(...) \ 66 fprintf(stdout, __VA_ARGS__) 67 # endif 68 #else 69 #define INFO(...) do { } while (0) 70 #endif 71 72 #if (LOG_LEVEL >= Warning_L) 73 # ifdef COLOR_WARNING 74 # define WARNING(str, ...) \ 75 fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END, ##__VA_ARGS__) 76 # else 77 # define WARNING(...) \ 78 fprintf(stderr, "WARNING: " __VA_ARGS__) 79 # endif 80 #else 81 #define WARNING(...) do { } while (0) 82 #endif 83 84 #if (LOG_LEVEL >= Error_L) 85 # ifdef COLOR_ERROR 86 # define ERROR(str, ...) \ 87 fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, ##__VA_ARGS__) 88 # else 89 # define ERROR(...) \ 90 fprintf(stderr, "ERROR: " __VA_ARGS__) 91 # endif 92 #else 93 #define ERROR(...) do { } while (0) 94 #endif 95 96 #endif 97