aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com')
-rw-r--r--vendor/github.com/felix/logger/.travis.yml3
-rw-r--r--vendor/github.com/felix/logger/Gopkg.lock21
-rw-r--r--vendor/github.com/felix/logger/Gopkg.toml30
-rw-r--r--vendor/github.com/felix/logger/LICENSE21
-rw-r--r--vendor/github.com/felix/logger/README.md80
-rw-r--r--vendor/github.com/felix/logger/keyvalue.go50
-rw-r--r--vendor/github.com/felix/logger/level.go50
-rw-r--r--vendor/github.com/felix/logger/log.go137
-rw-r--r--vendor/github.com/felix/logger/logger.go17
-rw-r--r--vendor/github.com/felix/logger/logger_test.go114
-rw-r--r--vendor/github.com/felix/logger/message.go18
-rw-r--r--vendor/github.com/felix/logger/options.go16
-rw-r--r--vendor/github.com/felix/logger/util.go36
13 files changed, 593 insertions, 0 deletions
diff --git a/vendor/github.com/felix/logger/.travis.yml b/vendor/github.com/felix/logger/.travis.yml
new file mode 100644
index 0000000..fb5b8f4
--- /dev/null
+++ b/vendor/github.com/felix/logger/.travis.yml
@@ -0,0 +1,3 @@
+language: go
+go:
+ - 1.x
diff --git a/vendor/github.com/felix/logger/Gopkg.lock b/vendor/github.com/felix/logger/Gopkg.lock
new file mode 100644
index 0000000..d4d1b3d
--- /dev/null
+++ b/vendor/github.com/felix/logger/Gopkg.lock
@@ -0,0 +1,21 @@
+# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
+
+
+[[projects]]
+ name = "github.com/google/go-cmp"
+ packages = ["cmp","cmp/internal/diff","cmp/internal/function","cmp/internal/value"]
+ revision = "8099a9787ce5dc5984ed879a3bda47dc730a8e97"
+ version = "v0.1.0"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/streadway/amqp"
+ packages = ["."]
+ revision = "ff791c2d22d3f1588b4e2cc71a9fba5e1da90654"
+
+[solve-meta]
+ analyzer-name = "dep"
+ analyzer-version = 1
+ inputs-digest = "0466292400ff73a16095355d9346fdac71cd0edbf0b7e0969124fb52e68535f9"
+ solver-name = "gps-cdcl"
+ solver-version = 1
diff --git a/vendor/github.com/felix/logger/Gopkg.toml b/vendor/github.com/felix/logger/Gopkg.toml
new file mode 100644
index 0000000..aa53638
--- /dev/null
+++ b/vendor/github.com/felix/logger/Gopkg.toml
@@ -0,0 +1,30 @@
+
+# Gopkg.toml example
+#
+# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
+# for detailed Gopkg.toml documentation.
+#
+# required = ["github.com/user/thing/cmd/thing"]
+# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
+#
+# [[constraint]]
+# name = "github.com/user/project"
+# version = "1.0.0"
+#
+# [[constraint]]
+# name = "github.com/user/project2"
+# branch = "dev"
+# source = "github.com/myfork/project2"
+#
+# [[override]]
+# name = "github.com/x/y"
+# version = "2.4.0"
+
+
+[[constraint]]
+ name = "github.com/google/go-cmp"
+ version = "0.1.0"
+
+[[constraint]]
+ branch = "master"
+ name = "github.com/streadway/amqp"
diff --git a/vendor/github.com/felix/logger/LICENSE b/vendor/github.com/felix/logger/LICENSE
new file mode 100644
index 0000000..3050c2d
--- /dev/null
+++ b/vendor/github.com/felix/logger/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2017 Felix Hanley
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/felix/logger/README.md b/vendor/github.com/felix/logger/README.md
new file mode 100644
index 0000000..c07e317
--- /dev/null
+++ b/vendor/github.com/felix/logger/README.md
@@ -0,0 +1,80 @@
+# Simple structured logger for Go
+
+[![Build Status](https://travis-ci.org/felix/logger.svg?branch=master)](https://travis-ci.org/felix/logger)
+
+A simple logger package that provides levels, a number of output formats, and
+named sub-logs. Output formats include plain text, key/value, JSON and
+AMQP/RabbitMQ
+
+## Installation
+
+Install using `go get github.com/felix/logger`.
+
+Documentation is available at http://godoc.org/github.com/felix/logger
+
+## Usage
+
+### Create a normal logger
+
+```go
+log := logger.New(&logger.Options{
+ Name: "app",
+ Level: logger.Debug,
+})
+log.Error("unable to do anything")
+```
+
+```text
+... [INFO ] app: unable to do anything
+```
+
+### Create a key/value logger
+
+```go
+import "github.com/felix/logger/outputs/keyvalue"
+
+log := logger.New(&logger.Options{
+ Name: "app",
+ Level: logger.Debug,
+ Formatter: keyvalue.New(),
+})
+log.Warn("invalid something", "id", 344, "error", "generally broken")
+```
+
+```text
+... [WARN ] app: invalid something id=344 error="generally broken"
+```
+
+```text
+... [WARN ] app: invalid something id=344 error="generally broken"
+```
+
+### Create a sub-logger
+
+```go
+sublog := log.Named("database")
+sublog.Info("connection initialised")
+```
+
+```text
+... [INFO ] app.database: connection initialised
+```
+
+### Create a new Logger with pre-defined values
+
+For major sub-systems there is no need to repeat values for each log call:
+
+```go
+reqID := "555"
+msgLog := sublog.WithFields("request", reqID)
+msgLog.Error("failed to process message")
+```
+
+```text
+... [INFO ] app.database: failed to process message request=555
+```
+
+## Credits
+
+Solidly based on all the other loggers around, particularly Hashicorp's simple
+hclog with additions and modifications as required.
diff --git a/vendor/github.com/felix/logger/keyvalue.go b/vendor/github.com/felix/logger/keyvalue.go
new file mode 100644
index 0000000..244cb11
--- /dev/null
+++ b/vendor/github.com/felix/logger/keyvalue.go
@@ -0,0 +1,50 @@
+package logger
+
+import (
+ "fmt"
+ "io"
+ "strings"
+)
+
+// DefaultWriter implementation
+type DefaultWriter struct{}
+
+// New creates a new writer
+func NewDefaultWriter() *DefaultWriter {
+ return &DefaultWriter{}
+}
+
+// Write implements the logger.MessageWriter interface
+func (kv DefaultWriter) Write(w io.Writer, m Message) {
+ prefix := fmt.Sprintf("%s [%-5s]", m.Time, strings.ToUpper(m.Level.String()))
+ io.WriteString(w, prefix)
+ if m.Name != "" {
+ io.WriteString(w, " ")
+ io.WriteString(w, m.Name)
+ io.WriteString(w, ":")
+ }
+
+ offset := len(m.Fields) % 2
+ if offset != 0 {
+ io.WriteString(w, writeKV("message", m.Fields[0]))
+ }
+
+ for i := offset; i < len(m.Fields); i = i + 2 {
+ io.WriteString(w, writeKV(m.Fields[i], m.Fields[i+1]))
+ }
+}
+
+func writeKV(k, v interface{}) string {
+ return fmt.Sprintf(
+ " %s=%s",
+ maybeQuote(ToString(k)),
+ maybeQuote(ToString(v)),
+ )
+}
+
+func maybeQuote(s string) string {
+ if strings.ContainsAny(s, " \t\n\r") {
+ return fmt.Sprintf("%q", s)
+ }
+ return s
+}
diff --git a/vendor/github.com/felix/logger/level.go b/vendor/github.com/felix/logger/level.go
new file mode 100644
index 0000000..73fa57d
--- /dev/null
+++ b/vendor/github.com/felix/logger/level.go
@@ -0,0 +1,50 @@
+package logger
+
+import "strings"
+
+// Level defines the logger output level
+type Level int
+
+const (
+ // NoLevel is prior to being defined
+ NoLevel Level = 0
+ // Debug is for development
+ Debug Level = 1
+ // Info are for interesting runtime events
+ Info Level = 2
+ // Warn is for almost errors
+ Warn Level = 3
+ // Error is a runtime problem
+ Error Level = 4
+)
+
+func (lvl Level) String() string {
+ switch lvl {
+ case 1:
+ return "debug"
+ case 2:
+ return "info"
+ case 3:
+ return "warn"
+ case 4:
+ return "error"
+ default:
+ return "unknown"
+ }
+}
+
+// LevelFromString helps select a level
+func LevelFromString(l string) Level {
+ switch strings.ToLower(l) {
+ case "debug":
+ return Debug
+ case "warn":
+ return Warn
+ case "Info":
+ return Info
+ case "Error":
+ return Error
+ default:
+ return NoLevel
+ }
+}
diff --git a/vendor/github.com/felix/logger/log.go b/vendor/github.com/felix/logger/log.go
new file mode 100644
index 0000000..103a4b8
--- /dev/null
+++ b/vendor/github.com/felix/logger/log.go
@@ -0,0 +1,137 @@
+package logger
+
+import (
+ "bufio"
+ "os"
+ "sync"
+ "time"
+)
+
+type logger struct {
+ name string
+ level Level
+ fields []interface{}
+ timeFormat string
+ lock *sync.Mutex
+ formatter MessageWriter
+ out *bufio.Writer
+}
+
+// New creates a new logger
+func New(opts *Options) Logger {
+ if opts == nil {
+ opts = &Options{}
+ }
+
+ output := opts.Output
+ if output == nil {
+ output = os.Stderr
+ }
+
+ timeFormat := opts.TimeFormat
+ if timeFormat == "" {
+ timeFormat = DefaultTimeFormat
+ }
+
+ level := opts.Level
+ if level == NoLevel {
+ level = Info
+ }
+
+ l := logger{
+ name: opts.Name,
+ lock: new(sync.Mutex),
+ level: level,
+ timeFormat: timeFormat,
+ out: bufio.NewWriter(output),
+ }
+
+ l.formatter = opts.Formatter
+ if l.formatter == nil {
+ l.formatter = NewDefaultWriter()
+ }
+
+ return &l
+}
+
+// Log is a generic logger function
+func (l logger) Log(lvl Level, args ...interface{}) {
+ if lvl < l.level {
+ return
+ }
+
+ ts := time.Now()
+
+ l.lock.Lock()
+ defer l.lock.Unlock()
+
+ // Place fields at the end
+ args = append(args, l.fields...)
+
+ msg := Message{
+ Name: l.name,
+ Time: ts.Format(l.timeFormat),
+ Level: lvl,
+ Fields: make([]interface{}, 0),
+ }
+
+ // Allow for map arguments
+ for _, f := range args {
+ switch c := f.(type) {
+ case map[string]string:
+ for k, v := range c {
+ msg.Fields = append(msg.Fields, k, v)
+ }
+ case map[string]int:
+ for k, v := range c {
+ msg.Fields = append(msg.Fields, k, v)
+ }
+ case map[int]string:
+ for k, v := range c {
+ msg.Fields = append(msg.Fields, k, v)
+ }
+ case map[string]interface{}:
+ for k, v := range c {
+ msg.Fields = append(msg.Fields, k, v)
+ }
+ default:
+ msg.Fields = append(msg.Fields, c)
+ }
+ }
+
+ l.formatter.Write(l.out, msg)
+ l.out.WriteByte('\n')
+
+ l.out.Flush()
+}
+
+// Convenience functions for logging at levels
+func (l logger) Debug(args ...interface{}) { l.Log(Debug, args...) }
+func (l logger) Warn(args ...interface{}) { l.Log(Warn, args...) }
+func (l logger) Error(args ...interface{}) { l.Log(Error, args...) }
+func (l logger) Info(args ...interface{}) { l.Log(Info, args...) }
+
+// Test for current logging level
+func (l logger) IsLevel(lvl Level) bool { return l.level <= lvl }
+func (l logger) IsDebug() bool { return l.IsLevel(Debug) }
+func (l logger) IsInfo() bool { return l.IsLevel(Info) }
+func (l logger) IsWarn() bool { return l.IsLevel(Warn) }
+func (l logger) IsError() bool { return l.IsLevel(Error) }
+
+// WithFields sets the default fields for a new logger
+func (l *logger) WithFields(args ...interface{}) Logger {
+ var nl = *l
+ nl.fields = append(nl.fields, args...)
+ return &nl
+}
+
+// Named sets the name for a new logger
+func (l *logger) Named(name string) Logger {
+ var nl = *l
+ if nl.name != "" {
+ nl.name = nl.name + "." + name
+ } else {
+ nl.name = name
+ }
+ return &nl
+}
diff --git a/vendor/github.com/felix/logger/logger.go b/vendor/github.com/felix/logger/logger.go
new file mode 100644
index 0000000..6bb7298
--- /dev/null
+++ b/vendor/github.com/felix/logger/logger.go
@@ -0,0 +1,17 @@
+package logger
+
+// Logger defines our methods
+type Logger interface {
+ Log(level Level, args ...interface{})
+ Info(args ...interface{})
+ Warn(args ...interface{})
+ Debug(args ...interface{})
+ Error(args ...interface{})
+
+ WithFields(args ...interface{}) Logger
+ Named(name string) Logger
+ IsDebug() bool
+ IsInfo() bool
+ IsWarn() bool
+ IsError() bool
+}
diff --git a/vendor/github.com/felix/logger/logger_test.go b/vendor/github.com/felix/logger/logger_test.go
new file mode 100644
index 0000000..3f64430
--- /dev/null
+++ b/vendor/github.com/felix/logger/logger_test.go
@@ -0,0 +1,114 @@
+package logger
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+)
+
+func TestKeyValueWriter(t *testing.T) {
+ var tests = []struct {
+ in []interface{}
+ out string
+ }{
+ {
+ in: []interface{}{"one"},
+ out: "[INFO ] test: message=one\n",
+ },
+ {
+ in: []interface{}{"one", "two", "2"},
+ out: "[INFO ] test: message=one two=2\n",
+ },
+ {
+ in: []interface{}{"one", "two", "2", "three", 3},
+ out: "[INFO ] test: message=one two=2 three=3\n",
+ },
+ {
+ in: []interface{}{"one", "two", "2", "three", 3, "fo ur", "# 4"},
+ out: "[INFO ] test: message=one two=2 three=3 \"fo ur\"=\"# 4\"\n",
+ },
+ }
+
+ for _, tt := range tests {
+ var buf bytes.Buffer
+ logger := New(&Options{
+ Name: "test",
+ Output: &buf,
+ })
+
+ logger.Info(tt.in...)
+
+ str := buf.String()
+
+ // Chop timestamp
+ dataIdx := strings.IndexByte(str, ' ')
+ rest := str[dataIdx+1:]
+
+ if rest != tt.out {
+ t.Errorf("Info(%q) => %q, expected %q\n", tt.in, rest, tt.out)
+ }
+ }
+}
+
+func TestKeyValueWriterWithFields(t *testing.T) {
+ var tests = []struct {
+ in []interface{}
+ out string
+ }{
+ {
+ in: []interface{}{"one"},
+ out: "[INFO ] test: message=one added=this\n",
+ },
+ {
+ in: []interface{}{"one", "two", "2"},
+ out: "[INFO ] test: message=one two=2 added=this\n",
+ },
+ {
+ in: []interface{}{"one", "two", "2", "three", 3},
+ out: "[INFO ] test: message=one two=2 three=3 added=this\n",
+ },
+ {
+ in: []interface{}{"one", "two", "2", "three", 3, "fo ur", "# 4"},
+ out: "[INFO ] test: message=one two=2 three=3 \"fo ur\"=\"# 4\" added=this\n",
+ },
+ }
+ for _, tt := range tests {
+ var buf bytes.Buffer
+ logger := New(&Options{
+ Name: "test",
+ Output: &buf,
+ }).WithFields("added", "this")
+
+ logger.Info(tt.in...)
+
+ str := buf.String()
+
+ // Chop timestamp
+ dataIdx := strings.IndexByte(str, ' ')
+ rest := str[dataIdx+1:]
+
+ if rest != tt.out {
+ t.Errorf("Info(%q) => %q, expected %q\n", tt.in, rest, tt.out)
+ }
+ }
+}
+
+func TestLevels(t *testing.T) {
+ logger := New(&Options{
+ Name: "test",
+ Level: Debug,
+ })
+
+ if !logger.IsDebug() {
+ t.Errorf("Level Debug check failed")
+ }
+
+ logger = New(&Options{
+ Name: "test",
+ Level: Error,
+ })
+
+ if !logger.IsError() {
+ t.Errorf("Level Error check failed")
+ }
+}
diff --git a/vendor/github.com/felix/logger/message.go b/vendor/github.com/felix/logger/message.go
new file mode 100644
index 0000000..5ceb517
--- /dev/null
+++ b/vendor/github.com/felix/logger/message.go
@@ -0,0 +1,18 @@
+package logger
+
+import (
+ "io"
+)
+
+// Message type for writers
+type Message struct {
+ Name string
+ Time string
+ Level Level
+ Fields []interface{}
+}
+
+// MessageWriter interface for writing messages
+type MessageWriter interface {
+ Write(io.Writer, Message)
+}
diff --git a/vendor/github.com/felix/logger/options.go b/vendor/github.com/felix/logger/options.go
new file mode 100644
index 0000000..e0347b5
--- /dev/null
+++ b/vendor/github.com/felix/logger/options.go
@@ -0,0 +1,16 @@
+package logger
+
+import "io"
+
+// DefaultTimeFormat unless specified by options
+const DefaultTimeFormat = "2006-01-02T15:04:05.000Z0700"
+
+// Options to configure the logger
+type Options struct {
+ Name string
+ Level Level
+ Fields []interface{}
+ Output io.Writer
+ TimeFormat string
+ Formatter MessageWriter
+}
diff --git a/vendor/github.com/felix/logger/util.go b/vendor/github.com/felix/logger/util.go
new file mode 100644
index 0000000..2431740
--- /dev/null
+++ b/vendor/github.com/felix/logger/util.go
@@ -0,0 +1,36 @@
+package logger
+
+import (
+ "fmt"
+ "strconv"
+)
+
+// ToString converts interface to string
+func ToString(v interface{}) string {
+ switch c := v.(type) {
+ case string:
+ return c
+ case int:
+ return strconv.FormatInt(int64(c), 10)
+ case int64:
+ return strconv.FormatInt(int64(c), 10)
+ case int32:
+ return strconv.FormatInt(int64(c), 10)
+ case int16:
+ return strconv.FormatInt(int64(c), 10)
+ case int8:
+ return strconv.FormatInt(int64(c), 10)
+ case uint:
+ return strconv.FormatUint(uint64(c), 10)
+ case uint64:
+ return strconv.FormatUint(uint64(c), 10)
+ case uint32:
+ return strconv.FormatUint(uint64(c), 10)
+ case uint16:
+ return strconv.FormatUint(uint64(c), 10)
+ case uint8:
+ return strconv.FormatUint(uint64(c), 10)
+ default:
+ return fmt.Sprintf("%v", c)
+ }
+}