log.h
Go to the documentation of this file.
/*********************************************************
* Copyright (C) 2011-2016 VMware, Inc. All rights reserved.
*
* This program 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 version 2.1 and no later version.
*
* This program 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 Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
#ifndef _VMTOOLS_LOG_H_
#define _VMTOOLS_LOG_H_
#if !defined(G_LOG_DOMAIN)
# error "G_LOG_DOMAIN must be defined."
#endif
#include <glib.h>
#if defined(__GNUC__)
# define FUNC __func__
#else
# define FUNC __FUNCTION__
#endif
/*
*******************************************************************************
* g_info -- */
#if !defined(g_info)
# define g_info(fmt, ...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, fmt, ## __VA_ARGS__)
#endif
#ifdef VMX86_DEBUG
#define VMTOOLS_LOGGING_LEVEL_DEFAULT "info"
#else
#define VMTOOLS_LOGGING_LEVEL_DEFAULT "message"
#endif
/*
* As of version 2.46, glib thinks the Windows compiler where
* _MSC_VER >= 1400 can handle G_HAVE_ISO_VARARGS. This makes our
* magic macros wrapping their macros fail in the simplest case,
* where only the fmt arg is present (eg vm_debug("test").
* vm_debug("test %d", 123) works fine.
*
* Work around this by making g_debug() et all be inline functions,
* which is how it works if G_HAVE_ISO_VARARGS isn't set.
*
* Though experimentation we found that this also works:
*
* #define LOGHELPER(...) ,##_VA_ARGS__
* #define LOG(fmt, ...) g_debug_macro(__FUNCTION__, ": " fmt, LOGHELPER(__VA_ARGS__))
*
* but since its disgusting and even more magical, the inline variant was chosen
* instead.
*/
#if defined(_WIN32) && GLIB_CHECK_VERSION(2, 46, 0)
static inline void
g_critical_inline(const gchar *fmt,
...)
{
va_list args;
va_start(args, fmt);
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, fmt, args);
va_end(args);
}
/*
*******************************************************************************
* vm_{critical,debug,error,info,message,warning} -- */
#define vm_critical(fmt, ...) g_critical_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
static inline void
g_debug_inline(const gchar *fmt,
...)
{
va_list args;
va_start(args, fmt);
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, args);
va_end(args);
}
#define vm_debug(fmt, ...) g_debug_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
static inline void
g_error_inline(const gchar *fmt,
...)
{
va_list args;
va_start(args, fmt);
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, fmt, args);
va_end(args);
}
#define vm_error(fmt, ...) g_error_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
static inline void
g_info_inline(const gchar *fmt,
...)
{
va_list args;
va_start(args, fmt);
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, fmt, args);
va_end(args);
}
#define vm_info(fmt, ...) g_info_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
static inline void
g_message_inline(const gchar *fmt,
...)
{
va_list args;
va_start(args, fmt);
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, args);
va_end(args);
}
#define vm_message(fmt, ...) g_message_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
static inline void
g_warning_inline(const gchar *fmt,
...)
{
va_list args;
va_start(args, fmt);
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, fmt, args);
va_end(args);
}
#define vm_warning(fmt, ...) g_warning_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
#else // ! (windows & glib >= 2.46)
/*
*******************************************************************************
* vm_{critical,debug,error,info,message,warning} -- */
#define vm_critical(fmt, ...) g_critical("%s: " fmt, FUNC, ## __VA_ARGS__)
#define vm_debug(fmt, ...) g_debug("%s: " fmt, FUNC, ## __VA_ARGS__)
#define vm_error(fmt, ...) g_error("%s: " fmt, FUNC, ## __VA_ARGS__)
#define vm_info(fmt, ...) g_info("%s: " fmt, FUNC, ## __VA_ARGS__)
#define vm_message(fmt, ...) g_message("%s: " fmt, FUNC, ## __VA_ARGS__)
#define vm_warning(fmt, ...) g_warning("%s: " fmt, FUNC, ## __VA_ARGS__)
#endif // ! (windows & glib >= 2.46)
G_BEGIN_DECLS
void
VMTools_ConfigLogToStdio(const gchar *domain);
void
VMTools_ConfigLogging(const gchar *defaultDomain,
GKeyFile *cfg,
gboolean force,
gboolean reset);
G_END_DECLS
#endif /* _VMTOOLS_LOG_H_ */
VMTools_ConfigLogToStdio
G_BEGIN_DECLS void VMTools_ConfigLogToStdio(const gchar *domain)
Definition: vmtoolsLog.c:995
VMTools_ConfigLogging
void VMTools_ConfigLogging(const gchar *defaultDomain, GKeyFile *cfg, gboolean force, gboolean reset)
Definition: vmtoolsLog.c:1045