I'm tinkering with a PowerShell script that will handle some files for me (which is a good excuse to finally learn PowerShell!) and in the script I have a set of basic logging functions that log to the screen in a standard format, e.g. LogOk($message), LogInfo($message), etc.
I also have this function, which is intended to let me log some of the settings to the console the same way:
function LogSetting($varName, $varVal)
{
echo " Setting $varName = «$varVal»"
}
(Note: The other functions are single-parameter, this is the only one with two parameters)
Example call:
$myVariableName = "example content"
LogSetting("myVariableName", $myVariableName)
The problem is the console output for that call looks like this:
Setting myVariableName example content = «»
But it should look like this:
Setting myVariableName = «example content»
I've tried various combinations of formats, even things like this:
function LogSetting($varName, $varVal)
{
echo " Setting $varName / $varVal blah"
}
Which then produces this:
Setting myVariableName example content / blah
I even went so far as to do this to try and isolate the two parameters in the function to see if I could figure out what is causing the problem:
function LogSetting($varName, $varVal)
{
echo " Setting.... "
echo " $varName"
echo " $varVal"
}
But then the output looks like this:
Setting....
myVariableName example content
(a blank line is here)
(Yes there is a blank line at the end of the output, it won't show up unless I type something in there)
Clearly something is messed up, but only for this function. All other functions correctly write output to the console, even with the angle brackets (which I use to wrap paths, to make accidental leading/trailing spaces obvious).
Why is this one function not writing to the console properly?