Skip to content
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

v1.1.1 - Add a logger option to print timestamps in UTC for log traces #15

Merged
merged 1 commit into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Documentation/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ into the corresponding `Format-*` command.
### Logging

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

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

**`$global:SBUseUTC`** [bool] Defaults to `$false`. If `$false`, times are logged in local time.
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))

> **PowerShell Tip**
>
> If you wish to always use a different value for these, set the new values in your PowerShell
Expand Down
18 changes: 15 additions & 3 deletions StoreBroker/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ function Initialize-HelpersGlobalVariables
{
$global:SBNotifyCredential = [PSCredential]$null
}

if (!(Get-Variable -Name SBUseUTC -Scope Global -ValueOnly -ErrorAction SilentlyContinue))
{
$global:SBUseUTC = $false
}
}

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

Process
{
$date = Get-Date
$dateString = $date.ToString("yyyy-MM-dd HH:mm:ss")
if ($global:SBUseUTC)
{
$dateString = $date.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ")
}

Copy link
Contributor

@danbelcher-MSFT danbelcher-MSFT Jan 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like both the Local Time and UTC are being presented in the same format.  How can we tell if a given log file uses UTC or Local Time? Are we logging the value of $global:SBUseUTC?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use the 'Z' postfix or offsets for the timestamps: http://www.w3.org/TR/NOTE-datetime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Done.

$logFileMessage = '{0}{1} : {2} : {3} : {4}' -f
(" " * $Indent),
(Get-Date -Format "yyyy-MM-dd HH:mm:ss"),
$dateString,
$env:username,
$Level.ToUpper(),
$Message

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

Expand All @@ -433,7 +445,7 @@ function Write-Log
'Error' { Write-Error $ConsoleMessage }
'Warning' { Write-Warning $ConsoleMessage }
'Verbose' { Write-Verbose $ConsoleMessage }
'Debug' { Write-Degbug $ConsoleMessage }
'Debug' { Write-Debug $ConsoleMessage }
'Info' {
# We'd prefer to use Write-Information to enable users to redirect that pipe if
# they want, unfortunately it's only available on v5 and above. We'll fallback to
Expand Down
2 changes: 1 addition & 1 deletion StoreBroker/StoreBroker.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CompanyName = 'Microsoft Corporation'
Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.'

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

RootModule = 'StoreIngestionApi'
Expand Down