From: VMware, Inc <> Date: Sat, 28 May 2011 19:05:56 +0000 (-0700) Subject: Add some log wrappers to tools. X-Git-Tag: 2011.05.27-420096~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=929425c8b447d7abdada1513d29eaa25e824ecf8;p=thirdparty%2Fopen-vm-tools.git Add some log wrappers to tools. Basically, add missing glib functionality (g_info()) and create versions that automatically prepend the function name to log messages. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/vmware/tools/log.h b/open-vm-tools/lib/include/vmware/tools/log.h new file mode 100644 index 000000000..841cb6013 --- /dev/null +++ b/open-vm-tools/lib/include/vmware/tools/log.h @@ -0,0 +1,94 @@ +/********************************************************* + * Copyright (C) 2011 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_ + +/** + * @file log.h + * + * Some wrappers around glib log functions, expanding their functionality to + * support common usage patterns at VMware. + * + * @addtogroup vmtools_utils + * @{ + */ + +#if !defined(G_LOG_DOMAIN) +# error "G_LOG_DOMAIN must be defined." +#endif + +#include + +#if defined(__GNUC__) +# define FUNC __func__ +#else +# define FUNC __FUNCTION__ +#endif + +/* + ******************************************************************************* + * g_info -- */ /** + * + * Log a message with G_LOG_LEVEL_INFO; this function is missing in glib for + * whatever reason. + * + * @param[in] fmt Log message format. + * @param[in] ... Message arguments. + * + ******************************************************************************* + */ + +#define g_info(fmt, ...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, fmt, ## __VA_ARGS__) + + +/* + ******************************************************************************* + * vm_{critical,debug,error,info,message,warning} -- */ /** + * + * Wrapper around the corresponding glib function that automatically includes + * the calling function name in the log message. The "fmt" parameter must be + * a string constant. + * + * @param[in] fmt Log message format. + * @param[in] ... Message arguments. + * + ******************************************************************************* + */ + +#define vm_critical(fmt, ...) g_critical("%s: " fmt, FUNC, ## __VA_ARGS__) + +/** @copydoc vm_critical */ +#define vm_debug(fmt, ...) g_debug("%s: " fmt, FUNC, ## __VA_ARGS__) + +/** @copydoc vm_critical */ +#define vm_error(fmt, ...) g_error("%s: " fmt, FUNC, ## __VA_ARGS__) + +/** @copydoc vm_critical */ +#define vm_info(fmt, ...) g_info("%s: " fmt, FUNC, ## __VA_ARGS__) + +/** @copydoc vm_critical */ +#define vm_message(fmt, ...) g_message("%s: " fmt, FUNC, ## __VA_ARGS__) + +/** @copydoc vm_critical */ +#define vm_warning(fmt, ...) g_warning("%s: " fmt, FUNC, ## __VA_ARGS__) + +/** @} */ + +#endif /* _VMTOOLS_LOG_H_ */ + diff --git a/open-vm-tools/tests/testPlugin/testPlugin.c b/open-vm-tools/tests/testPlugin/testPlugin.c index 8b42cc0ad..8e1c093d8 100644 --- a/open-vm-tools/tests/testPlugin/testPlugin.c +++ b/open-vm-tools/tests/testPlugin/testPlugin.c @@ -32,6 +32,7 @@ #include "testData.h" #include "util.h" +#include "vmware/tools/log.h" #include "vmware/tools/plugin.h" #include "vmware/tools/rpcdebug.h" #include "vmware/tools/utils.h" @@ -85,16 +86,16 @@ TestPluginRpc1(RpcInData *data) testdata, &cmd, &cmdLen)) { - g_error("Failed to create test.rpcout.msg1 command.\n"); + vm_error("Failed to create test.rpcout.msg1 command."); } if (!RpcChannel_Send(ctx->rpc, cmd, cmdLen, NULL, NULL)) { - g_error("Failed to send 'test.rpcout.msg1' message.\n"); + vm_error("Failed to send 'test.rpcout.msg1' message."); } vm_free(cmd); - g_debug("Successfully handled rpc %s\n", data->name); + vm_debug("Successfully handled rpc %s", data->name); return RPCIN_SETRETVALS(data, "", TRUE); } @@ -110,7 +111,7 @@ TestPluginRpc1(RpcInData *data) static gboolean TestPluginRpc2(RpcInData *data) { - g_debug("%s: %s\n", __FUNCTION__, data->name); + vm_debug("%s", data->name); return RPCIN_SETRETVALS(data, "", TRUE); } @@ -128,7 +129,7 @@ static gboolean TestPluginRpc3(RpcInData *data) { TestPluginData *ret; - g_debug("%s: %s\n", __FUNCTION__, data->name); + vm_debug("%s", data->name); ret = g_malloc(sizeof *ret); ret->data = Util_SafeStrdup("Hello World!"); @@ -165,7 +166,7 @@ TestPluginCapabilities(gpointer src, { TOOLS_CAP_NEW, NULL, GHI_CAP_SHELL_ACTION_BROWSE, 1 } }; - g_debug("%s: got capability signal, setting = %d.\n", __FUNCTION__, set); + vm_debug("got capability signal, setting = %d.", set); return VMTools_WrapArray(caps, sizeof *caps, ARRAYSIZE(caps)); } @@ -190,7 +191,7 @@ TestPluginReset(gpointer src, ToolsPluginData *plugin) { RPCDEBUG_ASSERT(ctx != NULL, FALSE); - g_debug("%s: reset signal for app %s\n", __FUNCTION__, ctx->name); + vm_debug("reset signal for app %s", ctx->name); return TRUE; } @@ -219,8 +220,8 @@ TestPluginServiceControl(gpointer src, gpointer eventData, gpointer data) { - g_debug("Got service control signal, code = %u, event = %u\n", - controlCode, eventType); + vm_debug("Got service control signal, code = %u, event = %u", + controlCode, eventType); return ERROR_CALL_NOT_IMPLEMENTED; } #endif @@ -241,7 +242,7 @@ TestPluginShutdown(gpointer src, ToolsAppCtx *ctx, ToolsPluginData *plugin) { - g_debug("%s: shutdown signal.\n", __FUNCTION__); + vm_debug("shutdown signal."); CU_ASSERT(gInvalidSigError); CU_ASSERT(gInvalidAppError); CU_ASSERT(gInvalidAppProvider); @@ -270,7 +271,7 @@ TestPluginSetOption(gpointer src, const gchar *value, ToolsPluginData *plugin) { - g_debug("%s: set '%s' to '%s'\n", __FUNCTION__, option, value); + vm_debug("set '%s' to '%s'", option, value); return TRUE; } @@ -294,7 +295,7 @@ TestProviderRegisterApp(ToolsAppCtx *ctx, gpointer reg) { TestApp *app = reg; - g_debug("%s: registration data is '%s'\n", __FUNCTION__, app->name); + vm_debug("registration data is '%s'", app->name); gValidAppRegistration |= strcmp(app->name, TEST_APP_NAME) == 0; CU_ASSERT(strcmp(app->name, TEST_APP_DONT_REGISTER) != 0); return (strcmp(app->name, TEST_APP_ERROR) != 0); @@ -398,6 +399,8 @@ ToolsOnLoad(ToolsAppCtx *ctx) { 43, VMTOOLS_WRAP_ARRAY(tnoprov) }, }; + vm_info("loading test plugin..."); + g_signal_new("test-signal", G_OBJECT_TYPE(ctx->serviceObj), 0,