fpi-log.h 2.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
 * Copyright (C) 2018 Bastien Nocera <hadess@hadess.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef __FPI_LOG_H__
#define __FPI_LOG_H__

23 24 25
/**
 * SECTION:fpi-log
 * @title: Logging
26
 * @short_description: Logging functions
27 28 29 30 31 32 33 34 35 36
 *
 * Logging in libfprint is handled through GLib's logging system, and behave the same
 * way as in the GLib [Message Output and Debugging Functions](https://developer.gnome.org/glib/stable/glib-Message-Logging.html)
 * documentation.
 *
 * You should include `fpi-log.h` as early as possible in your sources, just after
 * setting the `FP_COMPONENT` define to a string unique to your sources. This will
 * set the suffix of the `G_LOG_DOMAIN` used for printing.
 */

37 38
#ifdef FP_COMPONENT
#undef G_LOG_DOMAIN
39
#ifndef __GTK_DOC_IGNORE__
40 41
#define G_LOG_DOMAIN "libfprint-"FP_COMPONENT
#endif
42
#endif
43 44 45

#include <glib.h>

46 47 48 49 50 51
/**
 * fp_dbg:
 *
 * Same as g_debug().
 *
 */
52
#define fp_dbg g_debug
53 54 55 56 57 58

/**
 * fp_info:
 *
 * Same as g_debug().
 */
59
#define fp_info g_debug
60 61 62 63 64 65

/**
 * fp_warn:
 *
 * Same as g_warning().
 */
66
#define fp_warn g_warning
67 68 69 70 71 72 73 74

/**
 * fp_err:
 *
 * Same as g_warning(). In the future, this might be changed to a
 * g_assert() instead, so bear this in mind when adding those calls
 * to your driver.
 */
75 76
#define fp_err g_warning

77 78 79 80 81 82
/**
 * BUG_ON:
 * @condition: the condition to check
 *
 * Uses fp_err() to print an error if the @condition is true.
 */
83 84 85 86
#define BUG_ON(condition) G_STMT_START		\
	if (condition) {			\
		char *s;			\
		s = g_strconcat ("BUG: (", #condition, ")", NULL); \
87
		fp_err ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \
88 89
		g_free (s);			\
	} G_STMT_END
90 91 92 93 94 95

/**
 * BUG:
 *
 * Same as BUG_ON() but is always true.
 */
96 97 98
#define BUG() BUG_ON(1)

#endif