Today Steve Jin published a post called How to Enable ESX Server Logs for Troubleshooting. A very useful tip when you are looking for those hard-to-find “features” in your script.
Steve’s tipĀ reminded me that I have a similar small function in my toolchest to do something similar for the vCenter log.
The function allows you to switch the vCenter log between “warning” and “verbose” on the fly. No need to go into the vCenter client to change the logging option anymore while debugging.
The script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function Set-vLogging{ param([switch]$verbose = $false) $optMgr = Get-View (Get-View ServiceInstance).content.setting $log = New-Object VMware.Vim.OptionValue $log.key = "log.level" if($verbose){ $log.Value = "verbose" } else{ $log.Value = "warning" } $optmgr.UpdateOptions($log) } Set-vLogging -verbose:$true # The code you are debugging # Between the 2 calls to Set-Vlogging, the vpxd log will be in "verbose" mode # Set-vLogging -verbose:$false |
Annotation
Line 1-14: The actual function. You can place this in one of the profile files and then you can call the function anytime.
Line 2: The only parameter is a switch, which allows you switch between “warning” and ” verbose” logging mode. If you don’t specify the -Verbose parameter the default is used. The default switches logging to “warning” mode
Line 16,22: Before and after the code where you want extra logging, you place a call to the Set-vLogging function with the desiredĀ mode.
You can consult the vCenter log(s) via the vSphere client but you can also access them directly with, for example notepad. The logs are located in %allusersprofile%\VMware\VMware VirtualCenter\Logs.
Update May 12th 2010: as William pointed out there are some other vpxd logging levels available.
Value | Description |
none | Disable logging |
error | Errors only |
warning | Errors and warnings |
info | Normal logging |
verbose | Verbose logging |
trivia | Trivia. Shows the SOAP packages |
The following is a slightly adapted function that lets you chose which of the 6 logging levels you want
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function Set-vLoggingLevel{ param($level) $optMgr = Get-View (Get-View ServiceInstance).content.setting $log = New-Object VMware.Vim.OptionValue $log.key = "log.level" if("none","error","warning","info","verbose","trivia" -contains $level){ $log.Value = $level $optmgr.UpdateOptions($log) } } Set-vLoggingLevel -level "trivia" # The code you are debugging # Between the 2 calls to Set-VloggingLevel, # the vpxd log will be in the selected mode # Set-vLoggingLevel -level "warning" |
Annotations
Line 7: Only if the -Level parameter contains 1 of the 6 accepted values, will the logging level be changed.