To improve my command lines scripts, I want to add some optional console output, mainly for logging purposes. In my PowerShell modules, I use Write-Verbose
for this (but it should be clear this isn't specifically a Powershell question, presumably, the situation is similar in other languages). There are plenty of sites and lists about best practices regarding scripting in general, however, I could not find a proper description on how to adequately use a something like Write-Verbose
.
Should the output describe the next/previous command, hence become part of code documentation or would that be excessive?
For example I have the following code block:
$files = Get-ChildItem -Path C:\... -Recurse
Write-Verbose -Message "All files are retrieved"
foreach ($file in $files)
{
Do-Something
Write-Verbose -Message "Something has been done"
}
Export-Csv -Path .
Write-Verbose -Message "The report has been exported as CSV file"