-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve use of Write-Log and exceptions #97
Improve use of Write-Log and exceptions #97
Conversation
…roper support of pipelining.
This optional parameter will enable easier logging of exception information. - Implement pipeline support for -Message parameter This parameter always accepted pipeline input but didn't follow existing PoSh paradigms for pipelining. Note that there is no performance benefit to pipelining, but the option is there. - Add Write-LogHelper. This cmdlet is not intended to be used by itself, but instead should support Write-Log. The cmdlet performs the actual act of writing to screen/log.
…ception parameter.
While it was nice to break things up, keeping the actual writing logic in Write-Log will lead to better exception information if the Write-* cmdlets fail, because the exception will show as originating from Write-Log (which makes sense), instead of Write-LogHelper (which makes less sense).
… in Invoke-SBRestMethod, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a whole lot of goodness...thanks.
The space normalization is appreciated too. In the future though, it would be great to have that come in as a separate change.
StoreBroker/Helpers.ps1
Outdated
|
||
Logs the message: | ||
|
||
Write-LogHelper : 2018-01-23 12:57:37 : dabelc : There was a problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not Write-LogHelper
anymore, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
|
||
if ($global:SBShouldLogPid) | ||
{ | ||
$MaxPidDigits = 10 # This is an estimate (see https://stackoverflow.com/questions/17868218/what-is-the-maximum-process-id-on-windows) | ||
$pidColumnLength = $MaxPidDigits + "[]".Length | ||
$maxPidDigits = 10 # This is an estimate (see https://stackoverflow.com/questions/17868218/what-is-the-maximum-process-id-on-windows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This had been capitalized to signify it as a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I'd say it failed to signify that because I thought it was using the parameter naming convention. Why not all caps? Or local variable naming convention and use Set-Variable with the Constant/ReadOnly option to show that the value shouldn't be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the time, I was unaware of the ReadOnly
/Constant
options for the -Option
switch with Set-Variable
....thanks for that. PowerShell best practices indicates PascalCase for constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Revert this change.
- Use Set-Variable with ReadOnly
Let me know which you'd prefer.
@@ -1142,7 +1142,7 @@ function Update-ApplicationSubmission | |||
$output = @() | |||
$output += "We can only modify a submission that is in the '$script:keywordPendingCommit' state." | |||
$output += "The submission that you requested to modify ($SubmissionId) is in '$($submissionToUpdate.status)' state." | |||
|
|||
$newLineOutput = ($output -join [Environment]::NewLine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like there are probably a lot of opportunities throughout the code to now remove this type of line and just directly pass-in the array of strings, now that Write-Log
will take care of NewLine'ing them for the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I'll fix them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -528,14 +526,13 @@ function Show-ImageFileNames | |||
$output += " * [$langCode]: " + ($LangImageNames.$langCode -join ", ") | |||
} | |||
|
|||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're here, I'd ask that you explicitly add the -Message
at the same time, just to help us get up to the consistency we've been working towards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went all-in and replaced all instances of Write-Log that used implicit -Message parameter.
@@ -1058,14 +1056,13 @@ function Show-ImageFileNames | |||
$output += " * [$langCode]: " + ($LangImageNames.$langCode -join ", ") | |||
} | |||
|
|||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
StoreBroker/StoreIngestionApi.psm1
Outdated
@@ -1377,7 +1377,7 @@ function Start-SubmissionMonitor | |||
$shouldMonitor = $false | |||
} | |||
|
|||
Write-Log $($body -join [Environment]::NewLine) | |||
Write-Log $body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only remaining thing would be to add the -Message
to those simple Write-Log
lines that you were touching, and then to run an internal build and validate that packaging/submission still works fine and that the logs look reasonable.
@@ -300,7 +300,7 @@ function Format-Application | |||
|
|||
End | |||
{ | |||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -524,7 +524,7 @@ function Format-ApplicationSubmission | |||
|
|||
End | |||
{ | |||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -321,7 +321,7 @@ function Format-ApplicationFlight | |||
|
|||
End | |||
{ | |||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -734,7 +733,7 @@ function Format-ApplicationFlightSubmission | |||
|
|||
End | |||
{ | |||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
StoreBroker/StoreIngestionIapApi.ps1
Outdated
@@ -296,7 +296,7 @@ function Format-InAppProduct | |||
|
|||
End | |||
{ | |||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
StoreBroker/StoreIngestionIapApi.ps1
Outdated
@@ -854,7 +854,7 @@ function Format-InAppProductSubmission | |||
|
|||
End | |||
{ | |||
Write-Log $($output -join [Environment]::NewLine) | |||
Write-Log $output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
This commit replaces all (most?) instances of using Write-Log with implicit -Message parameter. Modified lines were found with the following regex replacement: Find : Write-Log\s([^-]) Replace: Write-Log -Message $1
Previously, users of Write-Log were left to handle creating messages themselves when logging an exception. Typically, our use has been to extract the exception's message and log this string. The issue with this approach is that we lose other valuable information, such as the originating script, line, exception type, etc.
With this change, Write-Log now accepts a -Exception parameter and handles logging the full exception information. This new functionality works in combination with the existing -Message parameter, so that users can log some context before logging the exception information. We hope that this change will make debugging StoreBroker issues faster and more intuitive for the reader.
Additional changes: