From: Oliver Kurth Date: Fri, 20 Dec 2019 20:25:52 +0000 (-0800) Subject: Implement better logging for deploypkg plugin if vmware-imc cannot be created. X-Git-Tag: stable-11.1.0~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5f6d338c4bdbaa4b317e730dd48a7e9155f0245;p=thirdparty%2Fopen-vm-tools.git Implement better logging for deploypkg plugin if vmware-imc cannot be created. If vmware-imc cannot be created, log the error message and also redirect the customization log to tools log. --- diff --git a/open-vm-tools/services/plugins/deployPkg/deployPkgLog.c b/open-vm-tools/services/plugins/deployPkg/deployPkgLog.c index f02585507..da2a93f8a 100644 --- a/open-vm-tools/services/plugins/deployPkg/deployPkgLog.c +++ b/open-vm-tools/services/plugins/deployPkg/deployPkgLog.c @@ -37,6 +37,8 @@ #include "win32Access.h" #endif +#define G_LOG_DOMAIN "deployPkg" + static FILE* _file = NULL; @@ -87,7 +89,13 @@ DeployPkgLog_Open() (void)Win32Access_SetFileOwnerRW(logPath); #endif DeployPkgLog_Log(log_debug, "## Starting deploy pkg operation"); + } else { + g_debug("%s: failed to open DeployPkg log file: %s\n", + __FUNCTION__, logPath); } + } else { + g_debug("%s: failed to create DeployPkg log directory: %s\n", + __FUNCTION__, logPath); } } @@ -125,6 +133,8 @@ DeployPkgLog_Close() * DeployPkgLog_Log -- * * If the log file was opened successfully, write to it. + * Otherwise call the glib logger, messages are logged + * per tools logging configuration. * * Results: * None. @@ -143,37 +153,56 @@ DeployPkgLog_Log(int level, // IN va_list args; gchar *tstamp; const char *logLevel; + GLogLevelFlags glogLevel; + va_start(args, fmtstr); - /* Make sure init succeeded */ - if (_file == NULL) { - return; - } + if (_file != NULL) { + switch (level) { + case log_debug: + logLevel = "debug"; + break; + case log_info: + logLevel = "info"; + break; + case log_warning: + logLevel = "warning"; + break; + case log_error: + logLevel = "error"; + break; + default: + logLevel = "unknown"; + break; + } + + tstamp = VMTools_GetTimeAsString(); + fprintf(_file, "[%s] [%8s] ", + (tstamp != NULL) ? tstamp : "no time", logLevel); + vfprintf(_file, fmtstr, args); + fprintf(_file, "\n"); + g_free(tstamp); + } else { + switch (level) { + case log_debug: + glogLevel = G_LOG_LEVEL_DEBUG; + break; + case log_info: + glogLevel = G_LOG_LEVEL_INFO; + break; + case log_warning: + glogLevel = G_LOG_LEVEL_WARNING; + break; + case log_error: + glogLevel = G_LOG_LEVEL_ERROR; + break; + default: + glogLevel = G_LOG_LEVEL_INFO; + break; + } - switch (level) { - case log_debug: - logLevel = "debug"; - break; - case log_info: - logLevel = "info"; - break; - case log_warning: - logLevel = "warning"; - break; - case log_error: - logLevel = "error"; - break; - default: - logLevel = "unknown"; - break; + g_logv(G_LOG_DOMAIN, glogLevel, fmtstr, args); } - va_start(args, fmtstr); - tstamp = VMTools_GetTimeAsString(); - fprintf(_file, "[%s] [%8s] ", - (tstamp != NULL) ? tstamp : "no time", logLevel); - vfprintf(_file, fmtstr, args); - fprintf(_file, "\n"); - g_free(tstamp); va_end(args); }