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 | |
Paul Cercueil | cdcba90 | 2016-08-30 17:36:53 +0200 | [diff] [blame] | 22 | #include "iio-config.h" |
| 23 | |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | |
Paul Cercueil | cdcba90 | 2016-08-30 17:36:53 +0200 | [diff] [blame] | 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 |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 31 | |
Paul Cercueil | b12501b | 2014-03-19 15:36:35 +0100 | [diff] [blame] | 32 | /* -------------------- */ |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 33 | |
| 34 | #ifdef WITH_COLOR_DEBUG |
| 35 | #ifndef COLOR_DEBUG |
Paul Cercueil | 323d2d9 | 2017-04-03 18:38:27 +0200 | [diff] [blame] | 36 | #define COLOR_DEBUG "\e[0;32m" |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 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 | |
Paul Cercueil | cdcba90 | 2016-08-30 17:36:53 +0200 | [diff] [blame] | 48 | #if (LOG_LEVEL >= Debug_L) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 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 |
Paul Cercueil | 3207f2f | 2016-08-30 17:43:51 +0200 | [diff] [blame] | 57 | #define DEBUG(...) do { } while (0) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 58 | #endif |
| 59 | |
Paul Cercueil | cdcba90 | 2016-08-30 17:36:53 +0200 | [diff] [blame] | 60 | #if (LOG_LEVEL >= Info_L) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 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 |
Paul Cercueil | 3207f2f | 2016-08-30 17:43:51 +0200 | [diff] [blame] | 69 | #define INFO(...) do { } while (0) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 70 | #endif |
| 71 | |
Paul Cercueil | cdcba90 | 2016-08-30 17:36:53 +0200 | [diff] [blame] | 72 | #if (LOG_LEVEL >= Warning_L) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 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 |
Paul Cercueil | 3207f2f | 2016-08-30 17:43:51 +0200 | [diff] [blame] | 81 | #define WARNING(...) do { } while (0) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 82 | #endif |
| 83 | |
Paul Cercueil | cdcba90 | 2016-08-30 17:36:53 +0200 | [diff] [blame] | 84 | #if (LOG_LEVEL >= Error_L) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 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 |
Paul Cercueil | 3207f2f | 2016-08-30 17:43:51 +0200 | [diff] [blame] | 93 | #define ERROR(...) do { } while (0) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | #endif |