Blame lasso/logging.h

Packit 228f82
/* $Id$
Packit 228f82
 *
Packit 228f82
 * Lasso - A free implementation of the Liberty Alliance specifications.
Packit 228f82
 *
Packit 228f82
 * Copyright (C) 2004-2007 Entr'ouvert
Packit 228f82
 * http://lasso.entrouvert.org
Packit 228f82
 *
Packit 228f82
 * Authors: See AUTHORS file in top-level directory.
Packit 228f82
 *
Packit 228f82
 * This program is free software; you can redistribute it and/or modify
Packit 228f82
 * it under the terms of the GNU General Public License as published by
Packit 228f82
 * the Free Software Foundation; either version 2 of the License, or
Packit 228f82
 * (at your option) any later version.
Packit 228f82
 *
Packit 228f82
 * This program is distributed in the hope that it will be useful,
Packit 228f82
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 228f82
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 228f82
 * GNU General Public License for more details.
Packit 228f82
 *
Packit 228f82
 * You should have received a copy of the GNU General Public License
Packit 228f82
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit 228f82
 */
Packit 228f82
Packit 228f82
#ifndef __LASSO_LOGGING_H__
Packit 228f82
#define __LASSO_LOGGING_H__ 1
Packit 228f82
Packit 228f82
#include <glib.h>
Packit 228f82
#include "errors.h"
Packit 228f82
Packit 228f82
#ifndef lasso_log
Packit 228f82
void lasso_log(GLogLevelFlags level, const char *filename, int line,
Packit 228f82
		const char *function, const char *format, ...);
Packit 228f82
#endif
Packit 228f82
Packit 228f82
int lasso_log_error_code(GLogLevelFlags level, int error, ...);
Packit 228f82
Packit 228f82
#ifndef __FUNCTION__
Packit 228f82
#  define __FUNCTION__  ""
Packit 228f82
#endif
Packit 228f82
Packit 228f82
#if defined(__GNUC__)
Packit 228f82
#  define message(level, format, args...) \
Packit 228f82
	lasso_log(level, __FILE__, __LINE__, __FUNCTION__, format, ##args)
Packit 228f82
#elif defined(HAVE_VARIADIC_MACROS)
Packit 228f82
#  define message(level, ...) \
Packit 228f82
	lasso_log(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
Packit 228f82
#else
Packit 228f82
static inline void message(GLogLevelFlags level, const char *format, ...)
Packit 228f82
{
Packit 228f82
	va_list ap;
Packit 228f82
	char s[1024];
Packit 228f82
	va_start(ap, format);
Packit 228f82
	g_vsnprintf(s, 1024, format, ap);
Packit 228f82
	va_end(ap);
Packit 228f82
	lasso_log(level, __FILE__, __LINE__, __FUNCTION__, s);
Packit 228f82
}
Packit 228f82
#endif
Packit 228f82
Packit 228f82
Packit 228f82
/* debug logging */
Packit 228f82
#if defined(LASSO_DEBUG)
Packit 228f82
#if defined(__GNUC__)
Packit 228f82
#define debug(format, args...) \
Packit 228f82
	message(G_LOG_LEVEL_DEBUG, format, ##args)
Packit 228f82
#elif defined(HAVE_VARIADIC_MACROS)
Packit 228f82
#define debug(...)     message(G_LOG_LEVEL_DEBUG, __VA_ARGS__)
Packit 228f82
#else
Packit 228f82
	static inline void debug(const char *format, ...)
Packit 228f82
	{
Packit 228f82
		va_list ap;
Packit 228f82
		char s[1024];
Packit 228f82
		va_start(ap, format);
Packit 228f82
		g_vsnprintf(s, 1024, format, ap);
Packit 228f82
		va_end(ap);
Packit 228f82
		message(G_LOG_LEVEL_DEBUG, "%s", s);
Packit 228f82
	}
Packit 228f82
#endif
Packit 228f82
#else
Packit 228f82
#if defined(__GNUC__)
Packit 228f82
#  define debug(format, args...) ;
Packit 228f82
#elif defined(HAVE_VARIADIC_MACROS)
Packit 228f82
#  define debug(...) ;
Packit 228f82
#else
Packit 228f82
	static inline void debug(const char *format, ...)
Packit 228f82
	{
Packit 228f82
		va_list ap;
Packit 228f82
		va_start(ap, format);
Packit 228f82
		va_end(ap);
Packit 228f82
	}
Packit 228f82
#endif
Packit 228f82
#endif
Packit 228f82
Packit 228f82
#if defined(__GNUC__)
Packit 228f82
#  define warning(format, args...) \
Packit 228f82
	message(G_LOG_LEVEL_WARNING, format, ##args)
Packit 228f82
#elif defined(HAVE_VARIADIC_MACROS)
Packit 228f82
#  define warning(...)     message(G_LOG_LEVEL_WARNING, __VA_ARGS__)
Packit 228f82
#else
Packit 228f82
static inline void warning(const char *format, ...)
Packit 228f82
{
Packit 228f82
	va_list ap;
Packit 228f82
	char s[1024];
Packit 228f82
	va_start(ap, format);
Packit 228f82
	g_vsnprintf(s, 1024, format, ap);
Packit 228f82
	va_end(ap);
Packit 228f82
	message(G_LOG_LEVEL_WARNING, "%s", s);
Packit 228f82
}
Packit 228f82
#endif
Packit 228f82
Packit 228f82
#if defined(__GNUC__)
Packit 228f82
#  define critical(format, args...) \
Packit 228f82
	message(G_LOG_LEVEL_CRITICAL, format, ##args)
Packit 228f82
#elif defined(HAVE_VARIADIC_MACROS)
Packit 228f82
#  define critical(...)     message(G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
Packit 228f82
#else
Packit 228f82
static inline void critical(const char *format, ...)
Packit 228f82
{
Packit 228f82
	va_list ap;
Packit 228f82
	char s[1024];
Packit 228f82
	va_start(ap, format);
Packit 228f82
	g_vsnprintf(s, 1024, format, ap);
Packit 228f82
	va_end(ap);
Packit 228f82
	message(G_LOG_LEVEL_CRITICAL, "%s", s);
Packit 228f82
}
Packit 228f82
#endif
Packit 228f82
Packit 228f82
#if defined(__GNUC__)
Packit 228f82
#  define error(format, args...) \
Packit 228f82
	message(G_LOG_LEVEL_ERROR, format, ##args)
Packit 228f82
#elif defined(HAVE_VARIADIC_MACROS)
Packit 228f82
#  define error(...)     message(G_LOG_LEVEL_ERROR, __VA_ARGS__)
Packit 228f82
#else
Packit 228f82
static inline void error(const char *format, ...)
Packit 228f82
{
Packit 228f82
	va_list ap;
Packit 228f82
	char s[1024];
Packit 228f82
	va_start(ap, format);
Packit 228f82
	g_vsnprintf(s, 1024, format, ap);
Packit 228f82
	va_end(ap);
Packit 228f82
	message(G_LOG_LEVEL_ERROR, "%s", s);
Packit 228f82
}
Packit 228f82
#endif
Packit 228f82
Packit 228f82
#define critical_error(rc) (critical("%s", lasso_strerror(rc)), rc)
Packit 228f82
Packit 228f82
#endif /* __LASSO_LOGGING_H_ */