Vendor main dependencies.
This commit is contained in:
parent
49a09ab7dd
commit
dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions
23
vendor/github.com/ArthurHlt/gominlog/LICENSE
generated
vendored
Normal file
23
vendor/github.com/ArthurHlt/gominlog/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Arthur Halet
|
||||
|
||||
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 should rather be used for Good, not Evil.
|
||||
|
||||
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.
|
185
vendor/github.com/ArthurHlt/gominlog/gominlog.go
generated
vendored
Normal file
185
vendor/github.com/ArthurHlt/gominlog/gominlog.go
generated
vendored
Normal file
|
@ -0,0 +1,185 @@
|
|||
package gominlog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/daviddengcn/go-colortext"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Level int
|
||||
|
||||
const (
|
||||
Loff = Level(^uint(0) >> 1)
|
||||
Lsevere = Level(1000)
|
||||
Lerror = Level(900)
|
||||
Lwarning = Level(800)
|
||||
Linfo = Level(700)
|
||||
Ldebug = Level(600)
|
||||
Lall = Level(-Loff - 1)
|
||||
)
|
||||
|
||||
type MinLog struct {
|
||||
log *log.Logger
|
||||
level Level
|
||||
packageName string
|
||||
isColorized bool
|
||||
}
|
||||
|
||||
func NewClassicMinLog() *MinLog {
|
||||
minLog := &MinLog{}
|
||||
logWriter := os.Stdout
|
||||
flags := log.Lshortfile | log.Ldate | log.Ltime
|
||||
minLog.log = log.New(logWriter, "", flags)
|
||||
minLog.isColorized = true
|
||||
minLog.packageName = ""
|
||||
minLog.level = Lall
|
||||
return minLog
|
||||
}
|
||||
func NewClassicMinLogWithPackageName(packageName string) *MinLog {
|
||||
minLog := NewClassicMinLog()
|
||||
minLog.SetPackageName(packageName)
|
||||
return minLog
|
||||
}
|
||||
func NewMinLog(appName string, level Level, withColor bool, flag int) *MinLog {
|
||||
minLog := &MinLog{}
|
||||
logWriter := os.Stdout
|
||||
minLog.log = log.New(logWriter, "", flag)
|
||||
minLog.isColorized = withColor
|
||||
minLog.packageName = appName
|
||||
minLog.level = level
|
||||
return minLog
|
||||
}
|
||||
func NewMinLogWithLogger(packageName string, level Level, withColor bool, logger *log.Logger) *MinLog {
|
||||
minLog := &MinLog{}
|
||||
minLog.log = logger
|
||||
minLog.isColorized = withColor
|
||||
minLog.packageName = packageName
|
||||
minLog.level = level
|
||||
return minLog
|
||||
}
|
||||
func (this *MinLog) GetLevel() Level {
|
||||
return Level(this.level)
|
||||
}
|
||||
|
||||
func (this *MinLog) SetWriter(writer io.Writer) {
|
||||
this.log.SetOutput(writer)
|
||||
}
|
||||
|
||||
func (this *MinLog) SetLevel(level Level) {
|
||||
this.level = level
|
||||
}
|
||||
func (this *MinLog) SetPackageName(newPackageName string) {
|
||||
this.packageName = newPackageName
|
||||
}
|
||||
func (this *MinLog) GetPackageName() string {
|
||||
return this.packageName
|
||||
}
|
||||
func (this *MinLog) SetLogger(l *log.Logger) {
|
||||
this.log = l
|
||||
}
|
||||
func (this *MinLog) WithColor(isColorized bool) {
|
||||
this.isColorized = isColorized
|
||||
}
|
||||
func (this *MinLog) IsColorized() bool {
|
||||
return this.isColorized
|
||||
}
|
||||
func (this *MinLog) GetLogger() *log.Logger {
|
||||
return this.log
|
||||
}
|
||||
|
||||
func (this *MinLog) logMessage(typeLog string, colorFg ct.Color, colorBg ct.Color, args ...interface{}) {
|
||||
var text string
|
||||
msg := ""
|
||||
flags := this.log.Flags()
|
||||
if (log.Lshortfile | flags) == flags {
|
||||
msg += this.trace()
|
||||
this.log.SetFlags(flags - log.Lshortfile)
|
||||
}
|
||||
text, ok := args[0].(string)
|
||||
if !ok {
|
||||
panic("Firt argument should be a string")
|
||||
}
|
||||
if len(args) > 1 {
|
||||
newArgs := args[1:]
|
||||
msg += typeLog + ": " + fmt.Sprintf(text, newArgs...)
|
||||
} else {
|
||||
msg += typeLog + ": " + text
|
||||
}
|
||||
this.writeMsgInLogger(msg, colorFg, colorBg)
|
||||
this.log.SetFlags(flags)
|
||||
}
|
||||
func (this *MinLog) writeMsgInLogger(msg string, colorFg ct.Color, colorBg ct.Color) {
|
||||
if this.isColorized && colorFg > 0 {
|
||||
ct.Foreground(colorFg, false)
|
||||
}
|
||||
if this.isColorized && colorBg > 0 {
|
||||
ct.ChangeColor(colorFg, false, colorBg, false)
|
||||
}
|
||||
this.log.Print(msg)
|
||||
if this.isColorized {
|
||||
ct.ResetColor()
|
||||
}
|
||||
}
|
||||
func (this *MinLog) Error(args ...interface{}) {
|
||||
if this.level > Lerror {
|
||||
return
|
||||
}
|
||||
this.logMessage("ERROR", ct.Red, 0, args...)
|
||||
}
|
||||
|
||||
func (this *MinLog) Severe(args ...interface{}) {
|
||||
if this.level > Lsevere {
|
||||
return
|
||||
}
|
||||
this.logMessage("SEVERE", ct.Red, ct.Yellow, args...)
|
||||
}
|
||||
|
||||
func (this *MinLog) Debug(args ...interface{}) {
|
||||
if this.level > Ldebug {
|
||||
return
|
||||
}
|
||||
this.logMessage("DEBUG", ct.Blue, 0, args...)
|
||||
}
|
||||
|
||||
func (this *MinLog) Info(args ...interface{}) {
|
||||
if this.level > Linfo {
|
||||
return
|
||||
}
|
||||
this.logMessage("INFO", ct.Cyan, 0, args...)
|
||||
}
|
||||
|
||||
func (this *MinLog) Warning(args ...interface{}) {
|
||||
if this.level > Lwarning {
|
||||
return
|
||||
}
|
||||
this.logMessage("WARNING", ct.Yellow, 0, args...)
|
||||
}
|
||||
func (this *MinLog) trace() string {
|
||||
var shortFile string
|
||||
pc := make([]uintptr, 10)
|
||||
runtime.Callers(2, pc)
|
||||
f := runtime.FuncForPC(pc[2])
|
||||
file, line := f.FileLine(pc[2])
|
||||
if this.packageName == "" {
|
||||
execFileSplit := strings.Split(os.Args[0], "/")
|
||||
this.packageName = execFileSplit[len(execFileSplit)-1]
|
||||
}
|
||||
regex, err := regexp.Compile(regexp.QuoteMeta(this.packageName) + "/(.*)")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
subMatch := regex.FindStringSubmatch(file)
|
||||
if len(subMatch) < 2 {
|
||||
fileSplit := strings.Split(file, "/")
|
||||
shortFile = fileSplit[len(fileSplit)-1]
|
||||
} else {
|
||||
shortFile = subMatch[1]
|
||||
}
|
||||
|
||||
return fmt.Sprintf("/%s/%s:%d ", this.packageName, shortFile, line)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue