diff --git a/go.mod b/go.mod index 5a1fdf2c8..1dab40bee 100644 --- a/go.mod +++ b/go.mod @@ -53,7 +53,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/go-gcp-common v0.5.0 - github.com/hashicorp/go-hclog v0.10.1 + github.com/hashicorp/go-hclog v0.12.0 github.com/hashicorp/go-kms-wrapping v0.5.0 github.com/hashicorp/go-memdb v1.0.2 github.com/hashicorp/go-msgpack v0.5.5 @@ -86,7 +86,7 @@ require ( github.com/hashicorp/vault-plugin-secrets-gcpkms v0.5.2-0.20190814210149-315cdbf5de6e github.com/hashicorp/vault-plugin-secrets-kv v0.5.2-0.20191017213228-e8cf7060a4d0 github.com/hashicorp/vault/api v1.0.5-0.20200111014044-ba76c080ad1f - github.com/hashicorp/vault/sdk v0.1.14-0.20200123190015-7dd0e8af0bee + github.com/hashicorp/vault/sdk v0.1.14-0.20200123191138-967978cb67c0 github.com/influxdata/influxdb v0.0.0-20190411212539-d24b7ba8c4c4 github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect github.com/jackc/pgx v3.3.0+incompatible // indirect diff --git a/go.sum b/go.sum index c680772f4..0f4547c21 100644 --- a/go.sum +++ b/go.sum @@ -303,6 +303,8 @@ github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj github.com/hashicorp/go-hclog v0.10.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v0.10.1 h1:uyt/l0dWjJ879yiAu+T7FG3/6QX+zwm4bQ8P7XsYt3o= github.com/hashicorp/go-hclog v0.10.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v0.12.0 h1:d4QkX8FRTYaKaCZBoXYY8zJX2BXjWxurN/GA2tkrmZM= +github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.1.0 h1:vN9wG1D6KG6YHRTWr8512cxGOVgTMEfgEdSj/hr8MPc= github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= diff --git a/vendor/github.com/hashicorp/go-hclog/interceptlogger.go b/vendor/github.com/hashicorp/go-hclog/interceptlogger.go index 7b76b4b89..7e86dc878 100644 --- a/vendor/github.com/hashicorp/go-hclog/interceptlogger.go +++ b/vendor/github.com/hashicorp/go-hclog/interceptlogger.go @@ -30,6 +30,19 @@ func NewInterceptLogger(opts *LoggerOptions) InterceptLogger { return intercept } +func (i *interceptLogger) Log(level Level, msg string, args ...interface{}) { + i.Logger.Log(level, msg, args...) + if atomic.LoadInt32(i.sinkCount) == 0 { + return + } + + i.mu.Lock() + defer i.mu.Unlock() + for s := range i.Sinks { + s.Accept(i.Name(), level, msg, i.retrieveImplied(args...)...) + } +} + // Emit the message and args at TRACE level to log and sinks func (i *interceptLogger) Trace(msg string, args ...interface{}) { i.Logger.Trace(msg, args...) diff --git a/vendor/github.com/hashicorp/go-hclog/intlogger.go b/vendor/github.com/hashicorp/go-hclog/intlogger.go index 65129ff74..5d76ee3fb 100644 --- a/vendor/github.com/hashicorp/go-hclog/intlogger.go +++ b/vendor/github.com/hashicorp/go-hclog/intlogger.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding" "encoding/json" + "errors" "fmt" "io" "log" @@ -120,7 +121,7 @@ func newLogger(opts *LoggerOptions) *intLogger { // Log a message and a set of key/value pairs if the given level is at // or more severe that the threshold configured in the Logger. -func (l *intLogger) Log(name string, level Level, msg string, args ...interface{}) { +func (l *intLogger) log(name string, level Level, msg string, args ...interface{}) { if level < Level(atomic.LoadInt32(l.level)) { return } @@ -133,7 +134,7 @@ func (l *intLogger) Log(name string, level Level, msg string, args ...interface{ if l.json { l.logJSON(t, name, level, msg, args...) } else { - l.log(t, name, level, msg, args...) + l.logPlain(t, name, level, msg, args...) } l.writer.Flush(level) @@ -171,7 +172,7 @@ func trimCallerPath(path string) string { var logImplFile = regexp.MustCompile(`github.com/hashicorp/go-hclog/.+logger.go$`) // Non-JSON logging format function -func (l *intLogger) log(t time.Time, name string, level Level, msg string, args ...interface{}) { +func (l *intLogger) logPlain(t time.Time, name string, level Level, msg string, args ...interface{}) { l.writer.WriteString(t.Format(l.timeFormat)) l.writer.WriteByte(' ') @@ -431,29 +432,34 @@ func (l intLogger) jsonMapEntry(t time.Time, name string, level Level, msg strin return vals } +// Emit the message and args at the provided level +func (l *intLogger) Log(level Level, msg string, args ...interface{}) { + l.log(l.Name(), level, msg, args...) +} + // Emit the message and args at DEBUG level func (l *intLogger) Debug(msg string, args ...interface{}) { - l.Log(l.Name(), Debug, msg, args...) + l.log(l.Name(), Debug, msg, args...) } // Emit the message and args at TRACE level func (l *intLogger) Trace(msg string, args ...interface{}) { - l.Log(l.Name(), Trace, msg, args...) + l.log(l.Name(), Trace, msg, args...) } // Emit the message and args at INFO level func (l *intLogger) Info(msg string, args ...interface{}) { - l.Log(l.Name(), Info, msg, args...) + l.log(l.Name(), Info, msg, args...) } // Emit the message and args at WARN level func (l *intLogger) Warn(msg string, args ...interface{}) { - l.Log(l.Name(), Warn, msg, args...) + l.log(l.Name(), Warn, msg, args...) } // Emit the message and args at ERROR level func (l *intLogger) Error(msg string, args ...interface{}) { - l.Log(l.Name(), Error, msg, args...) + l.log(l.Name(), Error, msg, args...) } // Indicate that the logger would emit TRACE level logs @@ -556,6 +562,41 @@ func (l *intLogger) ResetNamed(name string) Logger { return &sl } +func (l *intLogger) ResetOutput(opts *LoggerOptions) error { + if opts.Output == nil { + return errors.New("given output is nil") + } + + l.mutex.Lock() + defer l.mutex.Unlock() + + return l.resetOutput(opts) +} + +func (l *intLogger) ResetOutputWithFlush(opts *LoggerOptions, flushable Flushable) error { + if opts.Output == nil { + return errors.New("given output is nil") + } + if flushable == nil { + return errors.New("flushable is nil") + } + + l.mutex.Lock() + defer l.mutex.Unlock() + + if err := flushable.Flush(); err != nil { + return err + } + + return l.resetOutput(opts) +} + +func (l *intLogger) resetOutput(opts *LoggerOptions) error { + l.writer = newWriter(opts.Output, opts.Color) + l.setColorization(opts) + return nil +} + // Update the logging level on-the-fly. This will affect all subloggers as // well. func (l *intLogger) SetLevel(level Level) { @@ -593,7 +634,7 @@ func (l *intLogger) checkWriterIsFile() *os.File { // Accept implements the SinkAdapter interface func (i *intLogger) Accept(name string, level Level, msg string, args ...interface{}) { - i.Log(name, level, msg, args...) + i.log(name, level, msg, args...) } // ImpliedArgs returns the loggers implied args diff --git a/vendor/github.com/hashicorp/go-hclog/logger.go b/vendor/github.com/hashicorp/go-hclog/logger.go index 48d608714..147bd2d78 100644 --- a/vendor/github.com/hashicorp/go-hclog/logger.go +++ b/vendor/github.com/hashicorp/go-hclog/logger.go @@ -95,6 +95,9 @@ type Logger interface { // Args are alternating key, val pairs // keys must be strings // vals can be any type, but display is implementation specific + // Emit a message and key/value pairs at a provided log level + Log(level Level, msg string, args ...interface{}) + // Emit a message and key/value pairs at the TRACE level Trace(msg string, args ...interface{}) @@ -238,3 +241,22 @@ type InterceptLogger interface { type SinkAdapter interface { Accept(name string, level Level, msg string, args ...interface{}) } + +// Flushable represents a method for flushing an output buffer. It can be used +// if Resetting the log to use a new output, in order to flush the writes to +// the existing output beforehand. +type Flushable interface { + Flush() error +} + +// OutputResettable provides ways to swap the output in use at runtime +type OutputResettable interface { + // ResetOutput swaps the current output writer with the one given in the + // opts. Color options given in opts will be used for the new output. + ResetOutput(opts *LoggerOptions) error + + // ResetOutputWithFlush swaps the current output writer with the one given + // in the opts, first calling Flush on the given Flushable. Color options + // given in opts will be used for the new output. + ResetOutputWithFlush(opts *LoggerOptions, flushable Flushable) error +} diff --git a/vendor/github.com/hashicorp/go-hclog/nulllogger.go b/vendor/github.com/hashicorp/go-hclog/nulllogger.go index 4abdd5583..bc14f7708 100644 --- a/vendor/github.com/hashicorp/go-hclog/nulllogger.go +++ b/vendor/github.com/hashicorp/go-hclog/nulllogger.go @@ -15,6 +15,8 @@ func NewNullLogger() Logger { type nullLogger struct{} +func (l *nullLogger) Log(level Level, msg string, args ...interface{}) {} + func (l *nullLogger) Trace(msg string, args ...interface{}) {} func (l *nullLogger) Debug(msg string, args ...interface{}) {} diff --git a/vendor/github.com/hashicorp/vault/sdk/helper/gatedwriter/writer.go b/vendor/github.com/hashicorp/vault/sdk/helper/gatedwriter/writer.go new file mode 100644 index 000000000..59c904440 --- /dev/null +++ b/vendor/github.com/hashicorp/vault/sdk/helper/gatedwriter/writer.go @@ -0,0 +1,42 @@ +package gatedwriter + +import ( + "bytes" + "io" + "sync" +) + +// Writer is an io.Writer implementation that buffers all of its +// data into an internal buffer until it is told to let data through. +type Writer struct { + writer io.Writer + + buf bytes.Buffer + flush bool + lock sync.Mutex +} + +func NewWriter(underlying io.Writer) *Writer { + return &Writer{writer: underlying} +} + +// Flush tells the Writer to flush any buffered data and to stop +// buffering. +func (w *Writer) Flush() { + w.lock.Lock() + defer w.lock.Unlock() + + w.flush = true + w.buf.WriteTo(w.writer) +} + +func (w *Writer) Write(p []byte) (n int, err error) { + w.lock.Lock() + defer w.lock.Unlock() + + if w.flush { + return w.writer.Write(p) + } + + return w.buf.Write(p) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index af8f3b09e..1c2d578bc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -301,7 +301,7 @@ github.com/hashicorp/errwrap github.com/hashicorp/go-cleanhttp # github.com/hashicorp/go-gcp-common v0.5.0 github.com/hashicorp/go-gcp-common/gcputil -# github.com/hashicorp/go-hclog v0.10.1 +# github.com/hashicorp/go-hclog v0.12.0 github.com/hashicorp/go-hclog # github.com/hashicorp/go-immutable-radix v1.1.0 github.com/hashicorp/go-immutable-radix @@ -445,7 +445,7 @@ github.com/hashicorp/vault-plugin-secrets-gcpkms github.com/hashicorp/vault-plugin-secrets-kv # github.com/hashicorp/vault/api v1.0.5-0.20200111014044-ba76c080ad1f => ./api github.com/hashicorp/vault/api -# github.com/hashicorp/vault/sdk v0.1.14-0.20200111013952-157e805b97be => ./sdk +# github.com/hashicorp/vault/sdk v0.1.14-0.20200123191138-967978cb67c0 => ./sdk github.com/hashicorp/vault/sdk/database/dbplugin github.com/hashicorp/vault/sdk/database/helper/connutil github.com/hashicorp/vault/sdk/database/helper/credsutil @@ -460,6 +460,7 @@ github.com/hashicorp/vault/sdk/helper/consts github.com/hashicorp/vault/sdk/helper/cryptoutil github.com/hashicorp/vault/sdk/helper/dbtxn github.com/hashicorp/vault/sdk/helper/errutil +github.com/hashicorp/vault/sdk/helper/gatedwriter github.com/hashicorp/vault/sdk/helper/hclutil github.com/hashicorp/vault/sdk/helper/identitytpl github.com/hashicorp/vault/sdk/helper/jsonutil