Remove the useless gladep file
[ladish.git] / common / debug.h
blob4edd48ec58c43a554cb69dc89389200ea487f77c
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
7 * Copyright (C) 2002 Robert Ham <rah@bash.sh>
9 **************************************************************************
10 * This file contains log macros
11 **************************************************************************
13 * LADI Session Handler is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * LADI Session Handler is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
25 * or write to the Free Software Foundation, Inc.,
26 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29 #ifndef __LASH_DEBUG_H__
30 #define __LASH_DEBUG_H__
32 #define ANSI_BOLD_ON "\033[1m"
33 #define ANSI_BOLD_OFF "\033[22m"
34 #define ANSI_COLOR_RED "\033[31m"
35 #define ANSI_COLOR_YELLOW "\033[33m"
36 #define ANSI_RESET "\033[0m"
38 #include <stdio.h>
40 #include "config.h"
42 /* fallback for old gcc versions,
43 http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html */
44 #if __STDC_VERSION__ < 199901L
45 # if __GNUC__ >= 2
46 # define __func__ __FUNCTION__
47 # else
48 # define __func__ "<unknown>"
49 # endif
50 #endif
52 #ifndef DEBUG_OUTPUT_TERMINAL
54 # define LASH_LOG_LEVEL_DEBUG 0
55 # define LASH_LOG_LEVEL_INFO 1
56 # define LASH_LOG_LEVEL_WARN 2
57 # define LASH_LOG_LEVEL_ERROR 3
58 # define LASH_LOG_LEVEL_ERROR_PLAIN 4
60 void
61 lash_log(unsigned int level,
62 const char *format,
63 ...);
65 # ifdef LASH_DEBUG
66 # define lash_debug(fmt, args...) \
67 lash_log(LASH_LOG_LEVEL_DEBUG, "%s:%d:%s: " fmt "\n", __FILE__, __LINE__, __func__, ## args)
68 # else
69 # define lash_debug(fmt, args...)
70 # endif /* LASH_DEBUG */
72 # define lash_info(fmt, args...) lash_log(LASH_LOG_LEVEL_INFO, fmt "\n", ## args)
73 # define lash_warn(fmt, args...) lash_log(LASH_LOG_LEVEL_WARN, ANSI_COLOR_YELLOW "WARNING: " ANSI_RESET "%s: " fmt "\n", __func__, ## args)
74 # define lash_error(fmt, args...) lash_log(LASH_LOG_LEVEL_ERROR, ANSI_COLOR_RED "ERROR: " ANSI_RESET "%s: " fmt "\n", __func__, ## args)
75 # define lash_error_plain(fmt, args...) lash_log(LASH_LOG_LEVEL_ERROR_PLAIN, ANSI_COLOR_RED "ERROR: " ANSI_RESET fmt "\n", ## args)
77 #else /* DEBUG_OUTPUT_TERMINAL */
79 # ifdef LASH_DEBUG
80 # define lash_debug(fmt, args...) \
81 printf("%s:%d:%s: " fmt "\n", __FILE__, __LINE__, __func__, ## args)
82 # else
83 # define lash_debug(fmt, args...)
84 # endif /* LASH_DEBUG */
86 # define lash_info(fmt, args...) printf(fmt "\n", ## args)
87 # define lash_warn(fmt, args...) printf(fmt "\n", ## args)
88 # define lash_error(fmt, args...) fprintf(stderr, "%s: " fmt "\n", __func__, ## args)
89 # define lash_error_plain(fmt, args...) fprintf(stderr, fmt "\n", ## args)
91 #endif /* DEBUG_OUTPUT_TERMINAL */
93 #endif /* __LASH_DEBUG_H__ */