Skip to content

Commit aff905a

Browse files
committed
v1.1.1 - Add a logger option to print timestamps in UTC for log traces
Write-Log is used for writing all messages to the console and the log file. It embeds a timestamp with each message, but this timestamp uses LocalTime. A request has come in to optionally allow users to have this timestamp recorded in UTC instead of LocalTime. This adds a new global variable $global:SBUseUTC that defaults to $false. If set to $true, then Write-Log will use UTC for the timestamps, appending a "Z" to the end of the timestamp based on http://www.w3.org/TR/NOTE-datetime. The documentation has been updated to reflect this new configuration option. * Additionally fixed a typo in Write-Log where it was trying to call Write-Debug. Resolves #10: Add a logger option to print timestamps in UTC for log traces
1 parent 52585e1 commit aff905a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

Documentation/USAGE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ into the corresponding `Format-*` command.
5656
### Logging
5757

5858
All commands will log to the console, as well as to a log file, by default.
59-
The logging is affected by two global variables. The pre-existing values of these
59+
The logging is affected by three global variables. The pre-existing values of these
6060
variables will be honored if they already exist, otherwise they will be created (with defaults)
6161
when the module is loaded.
6262

@@ -66,6 +66,10 @@ when the module is loaded.
6666
**`$global:SBLoggingEnabled`** [bool] Defaults to `$true`. To disable file-based logging,
6767
set to `$false`
6868

69+
**`$global:SBUseUTC`** [bool] Defaults to `$false`. If `$false`, times are logged in local time.
70+
When `$true`, times are logged using UTC (and those timestamps will end with a Z per the
71+
[W3C standard](http://www.w3.org/TR/NOTE-datetime))
72+
6973
> **PowerShell Tip**
7074
>
7175
> If you wish to always use a different value for these, set the new values in your PowerShell

StoreBroker/Helpers.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ function Initialize-HelpersGlobalVariables
7171
{
7272
$global:SBNotifyCredential = [PSCredential]$null
7373
}
74+
75+
if (!(Get-Variable -Name SBUseUTC -Scope Global -ValueOnly -ErrorAction SilentlyContinue))
76+
{
77+
$global:SBUseUTC = $false
78+
}
7479
}
7580

7681
# We need to be sure to call this explicitly so that the global variables get initialized.
@@ -415,16 +420,23 @@ function Write-Log
415420

416421
Process
417422
{
423+
$date = Get-Date
424+
$dateString = $date.ToString("yyyy-MM-dd HH:mm:ss")
425+
if ($global:SBUseUTC)
426+
{
427+
$dateString = $date.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ")
428+
}
429+
418430
$logFileMessage = '{0}{1} : {2} : {3} : {4}' -f
419431
(" " * $Indent),
420-
(Get-Date -Format "yyyy-MM-dd HH:mm:ss"),
432+
$dateString,
421433
$env:username,
422434
$Level.ToUpper(),
423435
$Message
424436

425437
$consoleMessage = '{0}{1} : {2} : {3}' -f
426438
(" " * $Indent),
427-
(Get-Date -Format "yyyy-MM-dd HH:mm:ss"),
439+
$dateString,
428440
$env:username,
429441
$Message
430442

@@ -433,7 +445,7 @@ function Write-Log
433445
'Error' { Write-Error $ConsoleMessage }
434446
'Warning' { Write-Warning $ConsoleMessage }
435447
'Verbose' { Write-Verbose $ConsoleMessage }
436-
'Debug' { Write-Degbug $ConsoleMessage }
448+
'Debug' { Write-Debug $ConsoleMessage }
437449
'Info' {
438450
# We'd prefer to use Write-Information to enable users to redirect that pipe if
439451
# they want, unfortunately it's only available on v5 and above. We'll fallback to

StoreBroker/StoreBroker.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
CompanyName = 'Microsoft Corporation'
77
Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.'
88

9-
ModuleVersion = '1.1.0'
9+
ModuleVersion = '1.1.1'
1010
Description = 'Provides command-line access to the Windows Store Submission REST API.'
1111

1212
RootModule = 'StoreIngestionApi'

0 commit comments

Comments
 (0)