log.h
Go to the documentation of this file.
/*********************************************************
* Copyright (c) 2011-2021 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>
#include "vmware/tools/guestrpc.h"
#include "vm_basic_types.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)
/* Checks if a string is null before it is passed in logging function */
#define VM_SAFE_STR(string) (string != NULL ? string : "(NULL)")
G_BEGIN_DECLS
void
VMTools_ConfigLogToStdio(const gchar *domain);
void
VMTools_ConfigLogging(const gchar *defaultDomain,
GKeyFile *cfg,
gboolean force,
gboolean reset);
void
VMTools_UseVmxGuestLog(const gchar *appName);
void
VMTools_SetupVmxGuestLog(gboolean refreshRpcChannel, GKeyFile *cfg,
const gchar *level);
void
VMTools_TeardownVmxGuestLog(void);
typedef enum {
TO_HOST,
IN_GUEST
} LogWhere;
void
VMTools_Log(LogWhere where,
GLogLevelFlags level,
const gchar *domain,
const gchar *fmt,
...);
void
VMTools_VmxLog(RpcChannel *chan,
const gchar *fmt,
...);
void
VMTools_VmxLogThrottled(uint32 *count,
RpcChannel *chan,
const gchar *fmt,
...);
G_END_DECLS
#define host_warning(fmt, ...) \
VMTools_Log(TO_HOST, G_LOG_LEVEL_WARNING, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#define guest_warning(fmt, ...) \
VMTools_Log(IN_GUEST, G_LOG_LEVEL_WARNING, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#define host_message(fmt, ...) \
VMTools_Log(TO_HOST, G_LOG_LEVEL_MESSAGE, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#define guest_message(fmt, ...) \
VMTools_Log(IN_GUEST, G_LOG_LEVEL_MESSAGE, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#define host_info(fmt, ...) \
VMTools_Log(TO_HOST, G_LOG_LEVEL_INFO, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#define guest_info(fmt, ...) \
VMTools_Log(IN_GUEST, G_LOG_LEVEL_INFO, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#define host_debug(fmt, ...) \
VMTools_Log(TO_HOST, G_LOG_LEVEL_DEBUG, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#define guest_debug(fmt, ...) \
VMTools_Log(IN_GUEST, G_LOG_LEVEL_DEBUG, G_LOG_DOMAIN, fmt, ## __VA_ARGS__)
#endif /* _VMTOOLS_LOG_H_ */
VMTools_UseVmxGuestLog
void VMTools_UseVmxGuestLog(const gchar *appName)
Definition vmtoolsLog.c:2541
VMTools_ConfigLogToStdio
G_BEGIN_DECLS void VMTools_ConfigLogToStdio(const gchar *domain)
Definition vmtoolsLog.c:1401
VMTools_Log
void VMTools_Log(LogWhere where, GLogLevelFlags level, const gchar *domain, const gchar *fmt,...)
Definition vmtoolsLog.c:2779
VMTools_TeardownVmxGuestLog
void VMTools_TeardownVmxGuestLog(void)
Definition vmtoolsLog.c:2663
VMTools_ConfigLogging
void VMTools_ConfigLogging(const gchar *defaultDomain, GKeyFile *cfg, gboolean force, gboolean reset)
Definition vmtoolsLog.c:1694
VMTools_SetupVmxGuestLog
void VMTools_SetupVmxGuestLog(gboolean refreshRpcChannel, GKeyFile *cfg, const gchar *level)
Definition vmtoolsLog.c:2600
guestrpc.h