From 95d9e83bc37cbac7f0c77249ede89ebd3dfcef29 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 2 Apr 2018 15:58:31 -0400 Subject: [PATCH] Merge in go-hclog --- vendor/github.com/hashicorp/go-hclog/README.md | 14 ++++++++++++-- vendor/github.com/hashicorp/go-hclog/int.go | 18 ++++++++++++------ vendor/github.com/hashicorp/go-hclog/log.go | 12 ++++++++++++ vendor/vendor.json | 6 +++--- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/vendor/github.com/hashicorp/go-hclog/README.md b/vendor/github.com/hashicorp/go-hclog/README.md index 614342b2d..1153e2853 100644 --- a/vendor/github.com/hashicorp/go-hclog/README.md +++ b/vendor/github.com/hashicorp/go-hclog/README.md @@ -10,8 +10,7 @@ interface for use in development and production environments. It provides logging levels that provide decreased output based upon the desired amount of output, unlike the standard library `log` package. -It does not provide `Printf` style logging, only key/value logging that is -exposed as arguments to the logging functions for simplicity. +It provides `Printf` style logging of values via `hclog.Fmt()`. It provides a human readable output mode for use in development as well as JSON output mode for production. @@ -100,6 +99,17 @@ requestLogger.Info("we are transporting a request") This allows sub Loggers to be context specific without having to thread that into all the callers. +### Using `hclog.Fmt()` + +```go +var int totalBandwidth = 200 +appLogger.Info("total bandwidth exceeded", "bandwidth", hclog.Fmt("%d GB/s", totalBandwidth)) +``` + +```text +... [INFO ] my-app: total bandwidth exceeded: bandwidth="200 GB/s" +``` + ### Use this with code that uses the standard library logger If you want to use the standard library's `log.Logger` interface you can wrap diff --git a/vendor/github.com/hashicorp/go-hclog/int.go b/vendor/github.com/hashicorp/go-hclog/int.go index 340cfdffd..0166c3dd2 100644 --- a/vendor/github.com/hashicorp/go-hclog/int.go +++ b/vendor/github.com/hashicorp/go-hclog/int.go @@ -214,6 +214,8 @@ func (z *intLogger) log(t time.Time, level Level, msg string, args ...interface{ case CapturedStacktrace: stacktrace = st continue FOR + case Format: + val = fmt.Sprintf(st[0].(string), st[1:]...) default: val = fmt.Sprintf("%v", st) } @@ -294,16 +296,20 @@ func (z *intLogger) logJson(t time.Time, level Level, msg string, args ...interf continue } val := args[i+1] - // Check if val is of type error. If error type doesn't - // implement json.Marshaler or encoding.TextMarshaler - // then set val to err.Error() so that it gets marshaled - if err, ok := val.(error); ok { - switch err.(type) { + switch sv := val.(type) { + case error: + // Check if val is of type error. If error type doesn't + // implement json.Marshaler or encoding.TextMarshaler + // then set val to err.Error() so that it gets marshaled + switch sv.(type) { case json.Marshaler, encoding.TextMarshaler: default: - val = err.Error() + val = sv.Error() } + case Format: + val = fmt.Sprintf(sv[0].(string), sv[1:]...) } + vals[args[i].(string)] = val } } diff --git a/vendor/github.com/hashicorp/go-hclog/log.go b/vendor/github.com/hashicorp/go-hclog/log.go index 6be9839e8..362924887 100644 --- a/vendor/github.com/hashicorp/go-hclog/log.go +++ b/vendor/github.com/hashicorp/go-hclog/log.go @@ -37,6 +37,18 @@ const ( Error Level = 5 ) +// When processing a value of this type, the logger automatically treats the first +// argument as a Printf formatting string and passes the rest as the values to be +// formatted. For example: L.Info(Fmt{"%d beans/day", beans}). This is a simple +// convience type for when formatting is required. +type Format []interface{} + +// Fmt returns a Format type. This is a convience function for creating a Format +// type. +func Fmt(str string, args ...interface{}) Format { + return append(Format{str}, args...) +} + // LevelFromString returns a Level type for the named log level, or "NoLevel" if // the level string is invalid. This facilitates setting the log level via // config or environment variable by name in a predictable way. diff --git a/vendor/vendor.json b/vendor/vendor.json index 52bb2e542..0e4ce7833 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1087,10 +1087,10 @@ "revisionTime": "2018-02-23T19:15:17Z" }, { - "checksumSHA1": "fg18dhgqDts2CI/Dz+6v5jX/xow=", + "checksumSHA1": "OEBNuHhYGJwXWNyZ2i+sAiOLtDs=", "path": "github.com/hashicorp/go-hclog", - "revision": "9b9aacd44f1c18bbf913afa45ecd1cb8ec515713", - "revisionTime": "2018-04-02T16:24:28Z" + "revision": "ad26ae78d4726a0d9fd16afcdff629babc1fc661", + "revisionTime": "2018-04-02T19:56:19Z" }, { "checksumSHA1": "y+AeKVZoX0gB+DZW4Arzkb3tTVc=",