Blame lasso/logging.h

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