1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009 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 __LADISH_LOG_H__
30 #define __LADISH_LOG_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"
42 /* fallback for old gcc versions,
43 http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html */
44 #if __STDC_VERSION__ < 199901L
46 # define __func__ __FUNCTION__
48 # define __func__ "<unknown>"
52 #ifndef LOG_OUTPUT_STDOUT
54 # define LADISH_LOG_LEVEL_DEBUG 0
55 # define LADISH_LOG_LEVEL_INFO 1
56 # define LADISH_LOG_LEVEL_WARN 2
57 # define LADISH_LOG_LEVEL_ERROR 3
58 # define LADISH_LOG_LEVEL_ERROR_PLAIN 4
61 ladish_log(unsigned int level
,
66 # define log_debug(fmt, args...) \
67 ladish_log(LADISH_LOG_LEVEL_DEBUG, "%s:%d:%s: " fmt "\n", __FILE__, __LINE__, __func__, ## args)
69 # define log_debug(fmt, args...)
70 # endif /* LADISH_DEBUG */
72 # define log_info(fmt, args...) ladish_log(LADISH_LOG_LEVEL_INFO, fmt "\n", ## args)
73 # define log_warn(fmt, args...) ladish_log(LADISH_LOG_LEVEL_WARN, ANSI_COLOR_YELLOW "WARNING: " ANSI_RESET "%s: " fmt "\n", __func__, ## args)
74 # define log_error(fmt, args...) ladish_log(LADISH_LOG_LEVEL_ERROR, ANSI_COLOR_RED "ERROR: " ANSI_RESET "%s: " fmt "\n", __func__, ## args)
75 # define log_error_plain(fmt, args...) ladish_log(LADISH_LOG_LEVEL_ERROR_PLAIN, ANSI_COLOR_RED "ERROR: " ANSI_RESET fmt "\n", ## args)
77 #else /* LOG_OUTPUT_STDOUT */
80 # define log_debug(fmt, args...) \
81 printf("%s:%d:%s: " fmt "\n", __FILE__, __LINE__, __func__, ## args)
83 # define log_debug(fmt, args...)
84 # endif /* LADISH_DEBUG */
86 # define log_info(fmt, args...) printf(fmt "\n", ## args)
87 # define log_warn(fmt, args...) printf(fmt "\n", ## args)
88 # define log_error(fmt, args...) fprintf(stderr, "%s: " fmt "\n", __func__, ## args)
89 # define log_error_plain(fmt, args...) fprintf(stderr, fmt "\n", ## args)
91 #endif /* LOG_OUTPUT_STDOUT */
93 #endif /* __LADISH_LOG__ */