]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Implement log redirection for the deployPkg plugin.
authorJohn Wolfe <jwolfe@vmware.com>
Fri, 26 Mar 2021 03:21:17 +0000 (20:21 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Fri, 26 Mar 2021 03:21:17 +0000 (20:21 -0700)
On Linux, /var/log/vmware-imc/toolsDeployPkg.log is the default deployPkgs
log file.  This change allows users to redirect that log to the vmware.log
on the host or to another file located on the guest VM.  Redirection is
controlled by settings in the "logging" section of the tools.conf file.

See the examples in the sample tools.conf file provided in the distribution.

open-vm-tools/services/plugins/deployPkg/deployPkg.c
open-vm-tools/tools.conf

index 7805f59ee47b023e1b60d47ce9c5a446b54ca05f..76e49fc22b498421fee86a4fa67846b8aa418144 100644 (file)
@@ -88,8 +88,39 @@ DeployPkgDeployPkgInGuest(ToolsAppCtx *ctx,    // IN: app context
    int processTimeout;
 #endif
 
-   /* Init the logger */
-   DeployPkgLog_Open();
+   /*
+    * Init the logger
+    * PR 2109109. If the deployPkg log handler has been configured explicitly in
+    * tools.conf, then output deployPkg log through the specified handler.
+    * https://wiki.eng.vmware.com/Configuring_Logging_for_the_VMware_Tools
+    * If not, output the log to the default log file defined in
+    * function DeployPkgLog_Open.
+    * The deployPkg log handler is mainly configured for debugging purpose.
+    */
+   char key[128];
+   char *handler;
+   snprintf(key, sizeof key, "%s.handler", G_LOG_DOMAIN);
+   handler = VMTools_ConfigGetString(ctx->config,
+                                     CONFGROUPNAME_LOGGING,
+                                     key,
+                                     NULL);
+   if (handler != NULL &&
+       (strcmp(handler, "vmx") == 0 || strcmp(handler, "file") == 0 ||
+        strcmp(handler, "file+") == 0)) {
+      g_debug("Using deployPkg log handler: %s", handler);
+      free(handler);
+   } else {
+      DeployPkgLog_Open();
+
+      if (handler != NULL) {
+         DeployPkgLog_Log(log_debug,
+                          "Log handler %s is not applicable for deployPkg,"
+                          " ignore it and ouput the log in GOS customization"
+                          " default log path.",
+                          handler);
+         free(handler);
+      }
+   }
    DeployPkg_SetLogger(DeployPkgLog_Log);
 
    DeployPkgLog_Log(log_debug, "Deploying %s", pkgFile);
index 4fac64d09aa6fb21a9532ccaaf36d15a955e2738..4d55ebd37ecdc6c6a12464788f70cfe076c2637d 100644 (file)
 #toolboxcmd.handler = file
 #toolboxcmd.data = c:/tmp/vmtoolboxcmd-${USER}.log
 
+# With no explicit logging configuration for deployPkg, its default log path in
+# Linux is /var/log/vmware-imc/toolsDeployPkg.log, and in Windows is
+# %WINDIR%/Temp/vmware-imc/toolsDeployPkg.log
+# Set the following configuration if you want to redirect the deployPkg log to
+# any existing location other than the default.
+#deployPkg.level = debug
+#deployPkg.handler = file
+#deployPkg.data = c:/tmp/toolsDeployPkg-${USER}.log
+
+# Redirecting the deployPkg log to the vmx log file. Please note that
+# "log = true" and the vmsvc log handler setting to vmx are also neccessary
+# if you want to redirect the deployPkg log to vmx.
+#log = true
+#vmsvc.level = debug
+#vmsvc.handler = vmx
+#deployPkg.level = debug
+#deployPkg.handler = vmx
+
 # Enable old VMwareUser/vmware-user logging to file.
 #log.file = c:/tmp/vmtools.log