aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/Xe
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2018-10-04 19:44:06 -0700
committerChristine Dodrill <me@christine.website>2018-10-04 19:44:06 -0700
commit1c1d089725dd9f98b7ac73276d07dbadb388b748 (patch)
treeb0e783f5e2d485050e0072faf3b303bdc66e3539 /vendor/github.com/Xe
parente36f755db2198a96e2b87781f5f5432fcee092dd (diff)
downloadx-1c1d089725dd9f98b7ac73276d07dbadb388b748.tar.xz
x-1c1d089725dd9f98b7ac73276d07dbadb388b748.zip
add Dockerfile
Diffstat (limited to 'vendor/github.com/Xe')
-rw-r--r--vendor/github.com/Xe/ln/.travis.yml8
-rw-r--r--vendor/github.com/Xe/ln/LICENSE25
-rw-r--r--vendor/github.com/Xe/ln/README.md29
-rw-r--r--vendor/github.com/Xe/ln/action.go11
-rw-r--r--vendor/github.com/Xe/ln/context.go34
-rw-r--r--vendor/github.com/Xe/ln/doc.go25
-rw-r--r--vendor/github.com/Xe/ln/filter.go67
-rw-r--r--vendor/github.com/Xe/ln/formatter.go117
-rw-r--r--vendor/github.com/Xe/ln/go.mod6
-rw-r--r--vendor/github.com/Xe/ln/go.sum4
-rw-r--r--vendor/github.com/Xe/ln/logger.go183
-rw-r--r--vendor/github.com/Xe/ln/message.go19
-rw-r--r--vendor/github.com/Xe/ln/opname/opname.go31
-rw-r--r--vendor/github.com/Xe/ln/stack.go44
14 files changed, 603 insertions, 0 deletions
diff --git a/vendor/github.com/Xe/ln/.travis.yml b/vendor/github.com/Xe/ln/.travis.yml
new file mode 100644
index 0000000..e2af85b
--- /dev/null
+++ b/vendor/github.com/Xe/ln/.travis.yml
@@ -0,0 +1,8 @@
+language: go
+
+go:
+ - "1.x"
+ - "1.9"
+
+script:
+ - go test -v -race -cover ./...
diff --git a/vendor/github.com/Xe/ln/LICENSE b/vendor/github.com/Xe/ln/LICENSE
new file mode 100644
index 0000000..7202b64
--- /dev/null
+++ b/vendor/github.com/Xe/ln/LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2015, Andrew Gwozdziewycz
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
diff --git a/vendor/github.com/Xe/ln/README.md b/vendor/github.com/Xe/ln/README.md
new file mode 100644
index 0000000..61fc941
--- /dev/null
+++ b/vendor/github.com/Xe/ln/README.md
@@ -0,0 +1,29 @@
+# ln: The Natural Logger for Go
+
+`ln` provides a simple interface to logging, and metrics, and
+obviates the need to utilize purpose built metrics packages, like
+`go-metrics` for simple use cases.
+
+The design of `ln` centers around the idea of key-value pairs, which
+can be interpreted on the fly, but "Filters" to do things such as
+aggregated metrics, and report said metrics to, say Librato, or
+statsd.
+
+"Filters" are like WSGI, or Rack Middleware. They are run "top down"
+and can abort an emitted log's output at any time, or continue to let
+it through the chain. However, the interface is slightly different
+than that. Rather than encapsulating the chain with partial function
+application, we utilize a simpler method, namely, each plugin defines
+an `Apply` function, which takes as an argument the log event, and
+performs the work of the plugin, only if the Plugin "Applies" to this
+log event.
+
+If `Apply` returns `false`, the iteration through the rest of the
+filters is aborted, and the log is dropped from further processing.
+
+## Current Status: Initial Development / Concept
+
+## Copyright
+
+(c) 2015, Andrew Gwozdziewycz, BSD Licensed. See LICENSE for more
+info.
diff --git a/vendor/github.com/Xe/ln/action.go b/vendor/github.com/Xe/ln/action.go
new file mode 100644
index 0000000..54f8954
--- /dev/null
+++ b/vendor/github.com/Xe/ln/action.go
@@ -0,0 +1,11 @@
+package ln
+
+// Action is a convenience helper for logging the "action" being performed as
+// part of a log line.
+//
+// It is a convenience wrapper for the following:
+//
+// ln.Log(ctx, fer, f, ln.Action("writing frozberry sales reports to database"))
+func Action(act string) Fer {
+ return F{"action": act}
+}
diff --git a/vendor/github.com/Xe/ln/context.go b/vendor/github.com/Xe/ln/context.go
new file mode 100644
index 0000000..4b6ebce
--- /dev/null
+++ b/vendor/github.com/Xe/ln/context.go
@@ -0,0 +1,34 @@
+package ln
+
+import (
+ "context"
+)
+
+type ctxKey int
+
+const (
+ fKey = iota
+)
+
+// WithF stores or appends a given F instance into a context.
+func WithF(ctx context.Context, f F) context.Context {
+ pf, ok := FFromContext(ctx)
+ if !ok {
+ return context.WithValue(ctx, fKey, f)
+ }
+
+ pf.Extend(f)
+
+ return context.WithValue(ctx, fKey, pf)
+}
+
+// FFromContext fetches the `F` out of the context if it exists.
+func FFromContext(ctx context.Context) (F, bool) {
+ fvp := ctx.Value(fKey)
+ if fvp == nil {
+ return nil, false
+ }
+
+ f, ok := fvp.(F)
+ return f, ok
+}
diff --git a/vendor/github.com/Xe/ln/doc.go b/vendor/github.com/Xe/ln/doc.go
new file mode 100644
index 0000000..ab81c3c
--- /dev/null
+++ b/vendor/github.com/Xe/ln/doc.go
@@ -0,0 +1,25 @@
+/*
+Package ln is the Natural Logger for Go
+
+`ln` provides a simple interface to logging, and metrics, and
+obviates the need to utilize purpose built metrics packages, like
+`go-metrics` for simple use cases.
+
+The design of `ln` centers around the idea of key-value pairs, which
+can be interpreted on the fly, but "Filters" to do things such as
+aggregated metrics, and report said metrics to, say Librato, or
+statsd.
+
+"Filters" are like WSGI, or Rack Middleware. They are run "top down"
+and can abort an emitted log's output at any time, or continue to let
+it through the chain. However, the interface is slightly different
+than that. Rather than encapsulating the chain with partial function
+application, we utilize a simpler method, namely, each plugin defines
+an `Apply` function, which takes as an argument the log event, and
+performs the work of the plugin, only if the Plugin "Applies" to this
+log event.
+
+If `Apply` returns `false`, the iteration through the rest of the
+filters is aborted, and the log is dropped from further processing.
+*/
+package ln
diff --git a/vendor/github.com/Xe/ln/filter.go b/vendor/github.com/Xe/ln/filter.go
new file mode 100644
index 0000000..4f2d006
--- /dev/null
+++ b/vendor/github.com/Xe/ln/filter.go
@@ -0,0 +1,67 @@
+package ln
+
+import (
+ "context"
+ "io"
+ "sync"
+)
+
+// Filter interface for defining chain filters
+type Filter interface {
+ Apply(ctx context.Context, e Event) bool
+ Run()
+ Close()
+}
+
+// FilterFunc allows simple functions to implement the Filter interface
+type FilterFunc func(ctx context.Context, e Event) bool
+
+// Apply implements the Filter interface
+func (ff FilterFunc) Apply(ctx context.Context, e Event) bool {
+ return ff(ctx, e)
+}
+
+// Run implements the Filter interface
+func (ff FilterFunc) Run() {}
+
+// Close implements the Filter interface
+func (ff FilterFunc) Close() {}
+
+// WriterFilter implements a filter, which arbitrarily writes to an io.Writer
+type WriterFilter struct {
+ sync.Mutex
+ Out io.Writer
+ Formatter Formatter
+}
+
+// NewWriterFilter creates a filter to add to the chain
+func NewWriterFilter(out io.Writer, format Formatter) *WriterFilter {
+ if format == nil {
+ format = DefaultFormatter
+ }
+ return &WriterFilter{
+ Out: out,
+ Formatter: format,
+ }
+}
+
+// Apply implements the Filter interface
+func (w *WriterFilter) Apply(ctx context.Context, e Event) bool {
+ output, err := w.Formatter.Format(ctx, e)
+ if err == nil {
+ w.Lock()
+ w.Out.Write(output)
+ w.Unlock()
+ }
+
+ return true
+}
+
+// Run implements the Filter interface
+func (w *WriterFilter) Run() {}
+
+// Close implements the Filter interface
+func (w *WriterFilter) Close() {}
+
+// NilFilter is safe to return as a Filter, but does nothing
+var NilFilter = FilterFunc(func(_ context.Context, e Event) bool { return true })
diff --git a/vendor/github.com/Xe/ln/formatter.go b/vendor/github.com/Xe/ln/formatter.go
new file mode 100644
index 0000000..687371a
--- /dev/null
+++ b/vendor/github.com/Xe/ln/formatter.go
@@ -0,0 +1,117 @@
+package ln
+
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "time"
+
+ "github.com/Xe/ln/opname"
+)
+
+var (
+ // DefaultTimeFormat represents the way in which time will be formatted by default
+ DefaultTimeFormat = time.RFC3339
+)
+
+// Formatter defines the formatting of events
+type Formatter interface {
+ Format(ctx context.Context, e Event) ([]byte, error)
+}
+
+// DefaultFormatter is the default way in which to format events
+var DefaultFormatter Formatter
+
+func init() {
+ DefaultFormatter = NewTextFormatter()
+}
+
+// TextFormatter formats events as key value pairs.
+// Any remaining text not wrapped in an instance of `F` will be
+// placed at the end.
+type TextFormatter struct {
+ TimeFormat string
+}
+
+// NewTextFormatter returns a Formatter that outputs as text.
+func NewTextFormatter() Formatter {
+ return &TextFormatter{TimeFormat: DefaultTimeFormat}
+}
+
+// Format implements the Formatter interface
+func (t *TextFormatter) Format(ctx context.Context, e Event) ([]byte, error) {
+ var writer bytes.Buffer
+
+ writer.WriteString("time=\"")
+ writer.WriteString(e.Time.Format(t.TimeFormat))
+ writer.WriteString("\"")
+
+ if op, ok := opname.Get(ctx); ok {
+ e.Data["operation"] = op
+ }
+
+ keys := make([]string, len(e.Data))
+ i := 0
+
+ for k := range e.Data {
+ keys[i] = k
+ i++
+ }
+
+ for _, k := range keys {
+ v := e.Data[k]
+
+ writer.WriteByte(' ')
+ if shouldQuote(k) {
+ writer.WriteString(fmt.Sprintf("%q", k))
+ } else {
+ writer.WriteString(k)
+ }
+
+ writer.WriteByte('=')
+
+ switch v.(type) {
+ case string:
+ vs, _ := v.(string)
+ if shouldQuote(vs) {
+ fmt.Fprintf(&writer, "%q", vs)
+ } else {
+ writer.WriteString(vs)
+ }
+ case error:
+ tmperr, _ := v.(error)
+ es := tmperr.Error()
+
+ if shouldQuote(es) {
+ fmt.Fprintf(&writer, "%q", es)
+ } else {
+ writer.WriteString(es)
+ }
+ case time.Time:
+ tmptime, _ := v.(time.Time)
+ writer.WriteString(tmptime.Format(time.RFC3339))
+ default:
+ fmt.Fprint(&writer, v)
+ }
+ }
+
+ if len(e.Message) > 0 {
+ fmt.Fprintf(&writer, " _msg=%q", e.Message)
+ }
+
+ writer.WriteByte('\n')
+ return writer.Bytes(), nil
+}
+
+func shouldQuote(s string) bool {
+ for _, b := range s {
+ if !((b >= 'A' && b <= 'Z') ||
+ (b >= 'a' && b <= 'z') ||
+ (b >= '0' && b <= '9') ||
+ (b == '-' || b == '.' || b == '#' ||
+ b == '/' || b == '_')) {
+ return true
+ }
+ }
+ return false
+}
diff --git a/vendor/github.com/Xe/ln/go.mod b/vendor/github.com/Xe/ln/go.mod
new file mode 100644
index 0000000..cb01aab
--- /dev/null
+++ b/vendor/github.com/Xe/ln/go.mod
@@ -0,0 +1,6 @@
+module github.com/Xe/ln
+
+require (
+ github.com/pkg/errors v0.8.0
+ golang.org/x/net v0.0.0-20180811021610-c39426892332
+)
diff --git a/vendor/github.com/Xe/ln/go.sum b/vendor/github.com/Xe/ln/go.sum
new file mode 100644
index 0000000..089034d
--- /dev/null
+++ b/vendor/github.com/Xe/ln/go.sum
@@ -0,0 +1,4 @@
+github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
+github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+golang.org/x/net v0.0.0-20180811021610-c39426892332 h1:efGso+ep0DjyCBJPjvoz0HI6UldX4Md2F1rZFe1ir0E=
+golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
diff --git a/vendor/github.com/Xe/ln/logger.go b/vendor/github.com/Xe/ln/logger.go
new file mode 100644
index 0000000..a49c8a0
--- /dev/null
+++ b/vendor/github.com/Xe/ln/logger.go
@@ -0,0 +1,183 @@
+package ln
+
+import (
+ "context"
+ "os"
+ "time"
+
+ "github.com/pkg/errors"
+)
+
+// Logger holds the current priority and list of filters
+type Logger struct {
+ Filters []Filter
+}
+
+// DefaultLogger is the default implementation of Logger
+var DefaultLogger *Logger
+
+func init() {
+ var defaultFilters []Filter
+
+ // Default to STDOUT for logging, but allow LN_OUT to change it.
+ out := os.Stdout
+ if os.Getenv("LN_OUT") == "<stderr>" {
+ out = os.Stderr
+ }
+
+ defaultFilters = append(
+ defaultFilters,
+ NewWriterFilter(out, nil),
+ )
+
+ DefaultLogger = &Logger{
+ Filters: defaultFilters,
+ }
+}
+
+// F is a key-value mapping for structured data.
+type F map[string]interface{}
+
+// Extend concatentates one F with one or many Fer instances.
+func (f F) Extend(other ...Fer) {
+ for _, ff := range other {
+ for k, v := range ff.F() {
+ f[k] = v
+ }
+ }
+}
+
+// F makes F an Fer
+func (f F) F() F {
+ return f
+}
+
+// Fer allows any type to add fields to the structured logging key->value pairs.
+type Fer interface {
+ F() F
+}
+
+// Event represents an event
+type Event struct {
+ Time time.Time
+ Data F
+ Message string
+}
+
+// Log is the generic logging method.
+func (l *Logger) Log(ctx context.Context, xs ...Fer) {
+ event := Event{Time: time.Now()}
+
+ addF := func(bf F) {
+ if event.Data == nil {
+ event.Data = bf
+ } else {
+ for k, v := range bf {
+ event.Data[k] = v
+ }
+ }
+ }
+
+ for _, f := range xs {
+ addF(f.F())
+ }
+
+ ctxf, ok := FFromContext(ctx)
+ if ok {
+ addF(ctxf)
+ }
+
+ if os.Getenv("LN_DEBUG_ALL_EVENTS") == "1" {
+ frame := callersFrame()
+ if event.Data == nil {
+ event.Data = make(F)
+ }
+ event.Data["_lineno"] = frame.lineno
+ event.Data["_function"] = frame.function
+ event.Data["_filename"] = frame.filename
+ }
+
+ l.filter(ctx, event)
+}
+
+func (l *Logger) filter(ctx context.Context, e Event) {
+ for _, f := range l.Filters {
+ if !f.Apply(ctx, e) {
+ return
+ }
+ }
+}
+
+// Error logs an error and information about the context of said error.
+func (l *Logger) Error(ctx context.Context, err error, xs ...Fer) {
+ data := F{}
+ frame := callersFrame()
+
+ data["_lineno"] = frame.lineno
+ data["_function"] = frame.function
+ data["_filename"] = frame.filename
+ data["err"] = err
+
+ cause := errors.Cause(err)
+ if cause != nil && cause.Error() != err.Error() {
+ data["cause"] = cause.Error()
+ }
+
+ xs = append(xs, data)
+
+ l.Log(ctx, xs...)
+}
+
+// Fatal logs this set of values, then exits with status code 1.
+func (l *Logger) Fatal(ctx context.Context, xs ...Fer) {
+ xs = append(xs, F{"fatal": true})
+
+ l.Log(ctx, xs...)
+
+ os.Exit(1)
+}
+
+// FatalErr combines Fatal and Error.
+func (l *Logger) FatalErr(ctx context.Context, err error, xs ...Fer) {
+ xs = append(xs, F{"fatal": true})
+
+ data := F{}
+ frame := callersFrame()
+
+ data["_lineno"] = frame.lineno
+ data["_function"] = frame.function
+ data["_filename"] = frame.filename
+ data["err"] = err
+
+ cause := errors.Cause(err)
+ if cause != nil && cause.Error() != err.Error() {
+ data["cause"] = cause.Error()
+ }
+
+ xs = append(xs, data)
+ l.Log(ctx, xs...)
+
+ os.Exit(1)
+}
+
+// Default Implementation
+
+// Log is the generic logging method.
+func Log(ctx context.Context, xs ...Fer) {
+ DefaultLogger.Log(ctx, xs...)
+}
+
+// Error logs an error and information about the context of said error.
+func Error(ctx context.Context, err error, xs ...Fer) {
+ DefaultLogger.Error(ctx, err, xs...)
+}
+
+// Fatal logs this set of values, then exits with status code 1.
+func Fatal(ctx context.Context, xs ...Fer) {
+ DefaultLogger.Fatal(ctx, xs...)
+}
+
+// FatalErr combines Fatal and Error.
+func FatalErr(ctx context.Context, err error, xs ...Fer) {
+ DefaultLogger.FatalErr(ctx, err, xs...)
+}
diff --git a/vendor/github.com/Xe/ln/message.go b/vendor/github.com/Xe/ln/message.go
new file mode 100644
index 0000000..03eca9e
--- /dev/null
+++ b/vendor/github.com/Xe/ln/message.go
@@ -0,0 +1,19 @@
+package ln
+
+import "fmt"
+
+func withLevel(level, format string, args ...interface{}) Fer {
+ return F{level: fmt.Sprintf(format, args...), "level": level}
+}
+
+// Info adds an informational connotation to this log line. This is the
+// "default" state for things that can be ignored.
+func Info(format string, args ...interface{}) Fer {
+ return withLevel("info", format, args...)
+}
+
+// Debug adds a debugging connotation to this log line. This may be ignored
+// or aggressively sampled in order to save ram.
+func Debug(format string, args ...interface{}) Fer {
+ return withLevel("debug", format, args...)
+} \ No newline at end of file
diff --git a/vendor/github.com/Xe/ln/opname/opname.go b/vendor/github.com/Xe/ln/opname/opname.go
new file mode 100644
index 0000000..a24c125
--- /dev/null
+++ b/vendor/github.com/Xe/ln/opname/opname.go
@@ -0,0 +1,31 @@
+// Package opname contains an extensible "operation name" construct for go
+// applications. This allows a user to create a base operation, eg:
+// "createWidget" and then sub-operations such as "pgSaveWidget" and they will
+// get composed such as "createWidget.pgSaveWidget" in log lines. Each
+// operation name adds a lightweight "layer" to the context.
+package opname
+
+import (
+ "context"
+)
+
+type ctxKey int
+
+const key ctxKey = iota
+
+// Get fetches the operation name from the given context.
+func Get(ctx context.Context) (string, bool) {
+ val, ok := ctx.Value(key).(string)
+ return val, ok
+}
+
+// With stores the current operation name to the context, optionally prepending
+// the existing operation name in the context if it exists.
+func With(ctx context.Context, name string) context.Context {
+ prep, ok := Get(ctx)
+ if ok {
+ name = prep + "." + name
+ }
+
+ return context.WithValue(ctx, key, name)
+} \ No newline at end of file
diff --git a/vendor/github.com/Xe/ln/stack.go b/vendor/github.com/Xe/ln/stack.go
new file mode 100644
index 0000000..1cf1e7a
--- /dev/null
+++ b/vendor/github.com/Xe/ln/stack.go
@@ -0,0 +1,44 @@
+package ln
+
+import (
+ "os"
+ "runtime"
+ "strings"
+)
+
+type frame struct {
+ filename string
+ function string
+ lineno int
+}
+
+// skips 2 frames, since Caller returns the current frame, and we need
+// the caller's caller.
+func callersFrame() frame {
+ var out frame
+ pc, file, line, ok := runtime.Caller(3)
+ if !ok {
+ return out
+ }
+ srcLoc := strings.LastIndex(file, "/src/")
+ if srcLoc >= 0 {
+ file = file[srcLoc+5:]
+ }
+ out.filename = file
+ out.function = functionName(pc)
+ out.lineno = line
+
+ return out
+}
+
+func functionName(pc uintptr) string {
+ fn := runtime.FuncForPC(pc)
+ if fn == nil {
+ return "???"
+ }
+ name := fn.Name()
+ beg := strings.LastIndex(name, string(os.PathSeparator))
+ return name[beg+1:]
+ // end := strings.LastIndex(name, string(os.PathSeparator))
+ // return name[end+1 : len(name)]
+}