blob: cb84ad60460c9c1b08eb083059339369d320dc53 [file] [log] [blame]
Paul Cercueilbb4401d2014-02-28 16:10:49 +01001/*
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 Cercueil0b2ce712014-02-17 15:04:18 +010018
19#ifndef DEBUG_H
20#define DEBUG_H
21
Paul Cercueilcdcba902016-08-30 17:36:53 +020022#include "iio-config.h"
23
Paul Cercueil0b2ce712014-02-17 15:04:18 +010024#include <stdio.h>
25
Paul Cercueilcdcba902016-08-30 17:36:53 +020026#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 Cercueil0b2ce712014-02-17 15:04:18 +010031
Paul Cercueilb12501b2014-03-19 15:36:35 +010032/* -------------------- */
Paul Cercueil0b2ce712014-02-17 15:04:18 +010033
34#ifdef WITH_COLOR_DEBUG
35#ifndef COLOR_DEBUG
Paul Cercueil323d2d92017-04-03 18:38:27 +020036#define COLOR_DEBUG "\e[0;32m"
Paul Cercueil0b2ce712014-02-17 15:04:18 +010037#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 Cercueilcdcba902016-08-30 17:36:53 +020048#if (LOG_LEVEL >= Debug_L)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010049# 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 Cercueil3207f2f2016-08-30 17:43:51 +020057#define DEBUG(...) do { } while (0)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010058#endif
59
Paul Cercueilcdcba902016-08-30 17:36:53 +020060#if (LOG_LEVEL >= Info_L)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010061# 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 Cercueil3207f2f2016-08-30 17:43:51 +020069#define INFO(...) do { } while (0)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010070#endif
71
Paul Cercueilcdcba902016-08-30 17:36:53 +020072#if (LOG_LEVEL >= Warning_L)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010073# 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 Cercueil3207f2f2016-08-30 17:43:51 +020081#define WARNING(...) do { } while (0)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010082#endif
83
Paul Cercueilcdcba902016-08-30 17:36:53 +020084#if (LOG_LEVEL >= Error_L)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010085# 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 Cercueil3207f2f2016-08-30 17:43:51 +020093#define ERROR(...) do { } while (0)
Paul Cercueil0b2ce712014-02-17 15:04:18 +010094#endif
95
96#endif