Paul Cercueil | bb4401d | 2014-02-28 16:10:49 +0100 | [diff] [blame^] | 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 | * */ |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 18 | |
| 19 | #ifndef DEBUG_H |
| 20 | #define DEBUG_H |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | #define NODEBUG_L 0 |
| 25 | #define ERROR_L 1 |
| 26 | #define WARNING_L 2 |
| 27 | #define INFO_L 3 |
| 28 | #define DEBUG_L 4 |
| 29 | |
| 30 | #ifndef LOG_LEVEL |
| 31 | #define LOG_LEVEL INFO_L |
| 32 | #endif |
| 33 | |
| 34 | // ------------- |
| 35 | |
| 36 | #ifdef WITH_COLOR_DEBUG |
| 37 | #ifndef COLOR_DEBUG |
| 38 | #define COLOR_DEBUG "\e[0;34m" |
| 39 | #endif |
| 40 | #ifndef COLOR_WARNING |
| 41 | #define COLOR_WARNING "\e[01;35m" |
| 42 | #endif |
| 43 | #ifndef COLOR_ERROR |
| 44 | #define COLOR_ERROR "\e[01;31m" |
| 45 | #endif |
| 46 | |
| 47 | #define COLOR_END "\e[0m" |
| 48 | #endif |
| 49 | |
| 50 | #if (LOG_LEVEL >= DEBUG_L) |
| 51 | # ifdef COLOR_DEBUG |
| 52 | # define DEBUG(str, ...) \ |
| 53 | fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, ##__VA_ARGS__) |
| 54 | # else |
| 55 | # define DEBUG(...) \ |
| 56 | fprintf(stdout, "DEBUG: " __VA_ARGS__) |
| 57 | # endif |
| 58 | #else |
| 59 | #define DEBUG(...) |
| 60 | #endif |
| 61 | |
| 62 | #if (LOG_LEVEL >= INFO_L) |
| 63 | # ifdef COLOR_INFO |
| 64 | # define INFO(str, ...) \ |
| 65 | fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__) |
| 66 | # else |
| 67 | # define INFO(...) \ |
| 68 | fprintf(stdout, __VA_ARGS__) |
| 69 | # endif |
| 70 | #else |
| 71 | #define INFO(...) |
| 72 | #endif |
| 73 | |
| 74 | #if (LOG_LEVEL >= WARNING_L) |
| 75 | # ifdef COLOR_WARNING |
| 76 | # define WARNING(str, ...) \ |
| 77 | fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END, ##__VA_ARGS__) |
| 78 | # else |
| 79 | # define WARNING(...) \ |
| 80 | fprintf(stderr, "WARNING: " __VA_ARGS__) |
| 81 | # endif |
| 82 | #else |
| 83 | #define WARNING(...) |
| 84 | #endif |
| 85 | |
| 86 | #if (LOG_LEVEL >= ERROR_L) |
| 87 | # ifdef COLOR_ERROR |
| 88 | # define ERROR(str, ...) \ |
| 89 | fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, ##__VA_ARGS__) |
| 90 | # else |
| 91 | # define ERROR(...) \ |
| 92 | fprintf(stderr, "ERROR: " __VA_ARGS__) |
| 93 | # endif |
| 94 | #else |
| 95 | #define ERROR(...) |
| 96 | #endif |
| 97 | |
| 98 | #endif |