Merge branch 'stable' into 'main'
[ladish.git] / log.h
blob20905867755efc5e9511a338be032be00ed16bd2
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009, 2012 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"
38 #include <stdio.h>
39 #include <cdbus/log.h>
41 #include "config.h"
43 /* fallback for old gcc versions,
44 http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html */
45 #if __STDC_VERSION__ < 199901L
46 # if __GNUC__ >= 2
47 # define __func__ __FUNCTION__
48 # else
49 # define __func__ "<unknown>"
50 # endif
51 #endif
53 #ifdef __cplusplus
54 extern "C"
55 #endif
56 void
57 ladish_log(
58 unsigned int level,
59 const char * file,
60 unsigned int line,
61 const char * func,
62 const char * format,
63 ...)
64 #if defined (__GNUC__)
65 __attribute__((format(printf, 5, 6)))
66 #endif
69 #define log_debug(fmt, args...) ladish_log(CDBUS_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __func__, fmt, ## args)
70 #define log_info(fmt, args...) ladish_log(CDBUS_LOG_LEVEL_INFO, __FILE__, __LINE__, __func__, fmt, ## args)
71 #define log_warn(fmt, args...) ladish_log(CDBUS_LOG_LEVEL_WARN, __FILE__, __LINE__, __func__, fmt, ## args)
72 #define log_error(fmt, args...) ladish_log(CDBUS_LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, fmt, ## args)
73 #define log_error_plain(fmt, args...) ladish_log(CDBUS_LOG_LEVEL_ERROR_PLAIN, __FILE__, __LINE__, __func__, fmt, ## args)
75 #endif /* __LADISH_LOG__ */