This commit is contained in:
2018-11-04 15:58:15 +01:00
commit f956bcee28
1178 changed files with 584552 additions and 0 deletions

21
vendor/github.com/asticode/go-astilog/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Quentin Renard
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.

30
vendor/github.com/asticode/go-astilog/configuration.go generated vendored Normal file
View File

@@ -0,0 +1,30 @@
package astilog
import "flag"
// Flags
var (
AppName = flag.String("logger-app-name", "", "the logger's app name")
Filename = flag.String("logger-filename", "", "the logger's filename")
Verbose = flag.Bool("v", false, "if true, then log level is debug")
)
// Configuration represents the configuration of the logger
type Configuration struct {
AppName string `toml:"app_name"`
DisableColors bool `toml:"disable_colors"`
Filename string `toml:"filename"`
Format string `toml:"format"`
MessageKey string `toml:"message_key"`
Out string `toml:"out"`
Verbose bool `toml:"verbose"`
}
// FlagConfig generates a Configuration based on flags
func FlagConfig() Configuration {
return Configuration{
AppName: *AppName,
Filename: *Filename,
Verbose: *Verbose,
}
}

25
vendor/github.com/asticode/go-astilog/hooks.go generated vendored Normal file
View File

@@ -0,0 +1,25 @@
package astilog
import "github.com/sirupsen/logrus"
type withFieldHook struct {
k, v string
}
func newWithFieldHook(k, v string) *withFieldHook {
return &withFieldHook{
k: k,
v: v,
}
}
func (h *withFieldHook) Fire(e *logrus.Entry) error {
if len(h.v) > 0 {
e.Data[h.k] = h.v
}
return nil
}
func (h *withFieldHook) Levels() []logrus.Level {
return logrus.AllLevels
}

149
vendor/github.com/asticode/go-astilog/logger.go generated vendored Normal file
View File

@@ -0,0 +1,149 @@
package astilog
import (
"io"
"log"
"os"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal"
)
// Logger represents a logger
type Logger interface {
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Info(v ...interface{})
Infof(format string, v ...interface{})
Warn(v ...interface{})
Warnf(format string, v ...interface{})
Error(v ...interface{})
Errorf(format string, v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
}
// LoggerSetter represents a logger setter
type LoggerSetter interface {
SetLogger(l Logger)
}
// Fields represents logger fields
type Fields map[string]string
// LoggerWithField represents a logger that can have fields
type LoggerWithFields interface {
WithField(k, v string)
WithFields(fs Fields)
}
// Outs
const (
OutFile = "file"
OutStdOut = "stdout"
OutSyslog = "syslog"
)
// New creates a new Logger
func New(c Configuration) Logger {
// Init
var l = NewLogrus()
// Hooks
l.AddHook(newWithFieldHook("app_name", c.AppName))
// Out
var out string
l.Out, out = Out(c)
// Formatter
l.Formatter = Formatter(c, out)
// Level
l.Level = Level(c)
return l
}
// Out returns the out based on the configuration
func Out(c Configuration) (w io.Writer, out string) {
switch c.Out {
case OutStdOut:
return stdOut(), c.Out
case OutSyslog:
return syslogOut(c), c.Out
default:
if isTerminal(os.Stdout) {
w = stdOut()
out = OutStdOut
} else {
w = syslogOut(c)
out = OutSyslog
}
if len(c.Filename) > 0 {
f, err := os.OpenFile(c.Filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Println(errors.Wrapf(err, "astilog: creating %s failed", c.Filename))
} else {
w = f
out = OutFile
}
}
return
}
}
func isTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
return terminal.IsTerminal(int(v.Fd()))
default:
return false
}
}
// Formats
const (
FormatJSON = "json"
FormatText = "text"
)
// Formatter returns the formatter based on the configuration
func Formatter(c Configuration, out string) logrus.Formatter {
switch c.Format {
case FormatJSON:
return jsonFormatter(c)
case FormatText:
return textFormatter(c, out)
default:
switch out {
case OutFile, OutStdOut:
return textFormatter(c, out)
default:
return jsonFormatter(c)
}
}
}
func jsonFormatter(c Configuration) logrus.Formatter {
f := &logrus.JSONFormatter{FieldMap: make(logrus.FieldMap)}
if len(c.MessageKey) > 0 {
f.FieldMap[logrus.FieldKeyMsg] = c.MessageKey
}
return f
}
func textFormatter(c Configuration, out string) logrus.Formatter {
return &logrus.TextFormatter{
DisableColors: c.DisableColors || out == OutFile,
ForceColors: !c.DisableColors && out != OutFile,
}
}
func Level(c Configuration) logrus.Level {
if c.Verbose {
return logrus.DebugLevel
}
return logrus.InfoLevel
}

27
vendor/github.com/asticode/go-astilog/logrus.go generated vendored Normal file
View File

@@ -0,0 +1,27 @@
package astilog
import (
"github.com/sirupsen/logrus"
)
// Logrus represents a logrus logger
type Logrus struct {
*logrus.Logger
}
// NewLogrus creates a new logrus logger
func NewLogrus() *Logrus {
return &Logrus{Logger: logrus.New()}
}
// WithField implements the LoggerWithFields interface
func (l *Logrus) WithField(k, v string) {
l.AddHook(newWithFieldHook(k, v))
}
// WithFields implements the LoggerWithFields interface
func (l *Logrus) WithFields(fs Fields) {
for k, v := range fs {
l.WithField(k, v)
}
}

22
vendor/github.com/asticode/go-astilog/nop.go generated vendored Normal file
View File

@@ -0,0 +1,22 @@
package astilog
import "os"
// NopLogger returns a nop logger
func NopLogger() Logger {
return &nop{}
}
// nop is a nop logger
type nop struct{}
func (n nop) Debug(v ...interface{}) {}
func (n nop) Debugf(format string, v ...interface{}) {}
func (n nop) Info(v ...interface{}) {}
func (n nop) Infof(format string, v ...interface{}) {}
func (n nop) Warn(v ...interface{}) {}
func (n nop) Warnf(format string, v ...interface{}) {}
func (n nop) Error(v ...interface{}) {}
func (n nop) Errorf(format string, v ...interface{}) {}
func (n nop) Fatal(v ...interface{}) { os.Exit(1) }
func (n nop) Fatalf(format string, v ...interface{}) { os.Exit(1) }

19
vendor/github.com/asticode/go-astilog/out.go generated vendored Normal file
View File

@@ -0,0 +1,19 @@
// +build windows
package astilog
import (
"io"
"log"
colorable "github.com/mattn/go-colorable"
)
func stdOut() io.Writer {
return colorable.NewColorableStdout()
}
func syslogOut(c Configuration) io.Writer {
log.Println("astilog: syslog is not implemented on this os, using stdout instead")
return stdOut()
}

26
vendor/github.com/asticode/go-astilog/out_syslog.go generated vendored Normal file
View File

@@ -0,0 +1,26 @@
// +build !windows
package astilog
import (
"io"
"log"
"log/syslog"
"os"
"github.com/pkg/errors"
)
func stdOut() io.Writer {
return os.Stdout
}
func syslogOut(c Configuration) (w io.Writer) {
var err error
if w, err = syslog.New(syslog.LOG_INFO|syslog.LOG_USER, c.AppName); err != nil {
log.Println(errors.Wrap(err, "astilog: new syslog failed"))
return os.Stdout
}
return
}

3
vendor/github.com/asticode/go-astilog/readme.md generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Astilog
Astilog is a wrapper on top of xlog to provide proper configuration

36
vendor/github.com/asticode/go-astilog/std.go generated vendored Normal file
View File

@@ -0,0 +1,36 @@
package astilog
// Global logger
var gb = NopLogger()
// FlagInit initializes the package based on flags
func FlagInit() {
SetLogger(New(FlagConfig()))
}
// SetLogger sets the global logger
func SetLogger(l Logger) {
gb = l
}
// SetDefaultLogger sets the default logger
func SetDefaultLogger() {
SetLogger(New(Configuration{Verbose: true}))
}
// GetLogger returns the global logger
func GetLogger() Logger {
return gb
}
// Global logger shortcuts
func Debug(v ...interface{}) { gb.Debug(v...) }
func Debugf(format string, v ...interface{}) { gb.Debugf(format, v...) }
func Info(v ...interface{}) { gb.Info(v...) }
func Infof(format string, v ...interface{}) { gb.Infof(format, v...) }
func Warn(v ...interface{}) { gb.Warn(v...) }
func Warnf(format string, v ...interface{}) { gb.Warnf(format, v...) }
func Error(v ...interface{}) { gb.Error(v...) }
func Errorf(format string, v ...interface{}) { gb.Errorf(format, v...) }
func Fatal(v ...interface{}) { gb.Fatal(v...) }
func Fatalf(format string, v ...interface{}) { gb.Fatalf(format, v...) }