Repository: hashicorp/go-hclog (go)

Issue:
Change default time format
Is there any option to change default time format? I've found it's declared as a const now
```go
const TimeFormat = "2006-01-02T15:04:05.000Z0700"
```
It would be very helpful to have an option to pass format with `LoggerOptions`.

Pull request description:
Add support for custom time formats.
Fixes #15

Patch:
diff --git a/int.go b/int.go
index 20adcfb..8b13493 100644
--- a/int.go
+++ b/int.go
@@ -45,22 +45,28 @@ func New(opts *LoggerOptions) Logger {
 		mtx = new(sync.Mutex)
 	}
 
-	return &intLogger{
-		m:      mtx,
-		json:   opts.JSONFormat,
-		caller: opts.IncludeLocation,
-		name:   opts.Name,
-		w:      bufio.NewWriter(output),
-		level:  level,
+	ret := &intLogger{
+		m:          mtx,
+		json:       opts.JSONFormat,
+		caller:     opts.IncludeLocation,
+		name:       opts.Name,
+		timeFormat: TimeFormat,
+		w:          bufio.NewWriter(output),
+		level:      level,
 	}
+	if opts.TimeFormat != "" {
+		ret.timeFormat = opts.TimeFormat
+	}
+	return ret
 }
 
 // The internal logger implementation. Internal in that it is defined entirely
 // by this package.
 type intLogger struct {
-	json   bool
-	caller bool
-	name   string
+	json       bool
+	caller     bool
+	name       string
+	timeFormat string
 
 	// this is a pointer so that it's shared by any derived loggers, since
 	// those derived loggers share the bufio.Writer as well.
@@ -132,7 +138,7 @@ func trimCallerPath(path string) string {
 
 // Non-JSON logging format function
 func (z *intLogger) log(t time.Time, level Level, msg string, args ...interface{}) {
-	z.w.WriteString(t.Format(TimeFormat))
+	z.w.WriteString(t.Format(z.timeFormat))
 	z.w.WriteByte(' ')
 
 	s, ok := _levelToBracket[level]
diff --git a/log.go b/log.go
index dbc4198..6be9839 100644
--- a/log.go
+++ b/log.go
@@ -139,4 +139,7 @@ type LoggerOptions struct {
 
 	// Include file and line information in each log line
 	IncludeLocation bool
+
+	// The time format to use instead of the default
+	TimeFormat string
 }


Test patch:
diff --git a/logger_test.go b/logger_test.go
index 729d273..5249c52 100644
--- a/logger_test.go
+++ b/logger_test.go
@@ -8,6 +8,7 @@ import (
 	"strconv"
 	"strings"
 	"testing"
+	"time"
 
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
@@ -107,7 +108,7 @@ func TestLogger(t *testing.T) {
 		rest := str[dataIdx+1:]
 
 		// This test will break if you move this around, it's line dependent, just fyi
-		assert.Equal(t, "[INFO ] go-hclog/logger_test.go:100: test: this is test: who=programmer why=\"testing is fun\"\n", rest)
+		assert.Equal(t, "[INFO ] go-hclog/logger_test.go:101: test: this is test: who=programmer why=\"testing is fun\"\n", rest)
 	})
 
 	t.Run("prefixes the name", func(t *testing.T) {
@@ -133,6 +134,24 @@ func TestLogger(t *testing.T) {
 		rest = str[dataIdx+1:]
 		assert.Equal(t, "[INFO ] sublogger: this is test\n", rest)
 	})
+
+	t.Run("use a different time format", func(t *testing.T) {
+		var buf bytes.Buffer
+
+		logger := New(&LoggerOptions{
+			Name:       "test",
+			Output:     &buf,
+			TimeFormat: time.Kitchen,
+		})
+
+		logger.Info("this is test", "who", "programmer", "why", "testing is fun")
+
+		str := buf.String()
+
+		dataIdx := strings.IndexByte(str, ' ')
+
+		assert.Equal(t, str[:dataIdx], time.Now().Format(time.Kitchen))
+	})
 }
 
 func TestLogger_JSON(t *testing.T) {