Add {whenISO} to record timestamp in ISO 8601 format in UTC. (#1353)

* Add {whenISO} to record timestamp in ISO 8601 format in UTC.

ISO 8601 is the standard time format and is easy to parse.

This change assumes users desiring ISO 8016 generally prefer UTC for simplicity.
This results in {whenISO} to be significantly shorter than {when}:
{when}    = "02/Jan/2006:15:04:05 +0000"
{whenISO} = "2006-01-02T15:04:12Z"

Add unit test to verify both, as there was no unit test for {when}.

* Rename {whenISO} to {when_iso}
This commit is contained in:
M-A
2017-01-14 17:54:27 -05:00
committed by Matt Holt
parent 0155b0c5fb
commit 8464020f7c
2 changed files with 15 additions and 1 deletions
+6 -1
View File
@@ -23,6 +23,8 @@ var requestReplacer = strings.NewReplacer(
"\n", "\\n",
)
var now = time.Now
// Replacer is a type which can replace placeholder
// substrings in a string with actual values from a
// http.Request and ResponseRecorder. Always use
@@ -249,7 +251,9 @@ func (r *replacer) getSubstitution(key string) string {
case "{uri_escaped}":
return url.QueryEscape(r.request.URL.RequestURI())
case "{when}":
return time.Now().Format(timeFormat)
return now().Format(timeFormat)
case "{when_iso}":
return now().UTC().Format(timeFormatISOUTC)
case "{file}":
_, file := path.Split(r.request.URL.Path)
return file
@@ -311,6 +315,7 @@ func (r *replacer) Set(key, value string) {
const (
timeFormat = "02/Jan/2006:15:04:05 -0700"
timeFormatISOUTC = "2006-01-02T15:04:05Z" // ISO 8601 with timezone to be assumed as UTC
headerContentType = "Content-Type"
contentTypeJSON = "application/json"
contentTypeXML = "application/xml"