-
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
Process ID (PID) of StoreBroker PowerShell session now captured in log #62
Conversation
Documentation/USAGE.md
Outdated
@@ -72,6 +72,18 @@ when the module is loaded. | |||
When `$true`, times are logged using UTC (and those timestamps will end with a Z per the | |||
[W3C standard](http://www.w3.org/TR/NOTE-datetime)) | |||
|
|||
**`$global:SBLogPid`** [bool] Defaults to `$false`. If `$true`, the |
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.
The name by itself sounds like a numerical value, or a variable for a Pid to use for logging. Maybe 'SBShouldLogPid'?
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.
Sounds reasonable.
StoreBroker/Helpers.ps1
Outdated
$logFileMessage = '{0}{1} : [{2}]{3}: {4} : {5} : {6}' -f | ||
(" " * $Indent), | ||
$dateString, | ||
$pid, |
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.
$pid is the same syntax we use for local variables. Can we go with $global:PID
?
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.
indeed
StoreBroker/Helpers.ps1
Outdated
if ($global:SBLogPid) | ||
{ | ||
$MaxPidDigits = 10 # This is an estimate (see https://stackoverflow.com/questions/17868218/what-is-the-maximum-process-id-on-windows) | ||
$pidPadding = $MaxPidDigits - "$pid".length |
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.
There should be format specifiers for adding appropriate padding. Would save you a variable and some logic.
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.
PS C:> $MaxPidDigits = 10
PS C:> "'{0,$MaxPidDigits}'" -f 12341
' 12341'
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.
Well, GitHub removed the extra spaces, but you get the idea :)
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.
While interesting, that doesn't get me the formatting that I want. I want the padding on the end, not the beginning.
StoreBroker/Helpers.ps1
Outdated
$Message | ||
if ($global:SBLogPid) | ||
{ | ||
$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.
Shouldn't this have $maxPidDigits syntax?
Since we're estimating, it seems safer to go with:
$maxPidDigits = [Math]::Max(10, "$global:PID".Length)
Just in case.
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 was considering this a constant, hence SentenceCase as opposed to camelCase (for a varaible). Your suggestion on using Max
for this scenario sounds good though.
Some users have scenarios where they are running concurrent instances of StoreBroker, and for reasons specific to their situation, have chosen to have the logs always go to the same log file (instead of using `$global:SBLogPath` to set a different log file for each session. In these scenarios, it can be challenging to read the logs and understand what was happening exactly since there are entries from multiple commands intermixed. This change introduces adding the `$pid` of the StoreBroker PowerShell session to every log entry so that on post-mortem analysis, it would be easy to filter to just the logs for the specific `$pid`. For more info on `$pid`, [see here](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-5.1&viewFallbackFrom=powershell-Microsoft.PowerShell.Core#pid)
f508d37
to
1f01a04
Compare
Some users have scenarios where they are running concurrent instances of StoreBroker,
and for reasons specific to their situation, have chosen to have the logs always go
to the same log file (instead of using
$global:SBLogPath
to set a differentlog file for each session.
In these scenarios, it can be challenging to read the logs and understand what exactly
was happening since there are entries from multiple commands intermixed. This
change introduces adding the
$pid
of the StoreBroker PowerShell session to everylog entry so that on post-mortem analysis, it would be easy to filter to just the
logs for the specific
$pid
.For more info on
$pid
, see here