diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
| commit | e9c24f4af7ed56760f6db7941827d09f6db9020b (patch) | |
| tree | 62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/labstack/gommon | |
| parent | 58d5e7cfda4781d8a57ec52aefd02983835c301a (diff) | |
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/labstack/gommon')
10 files changed, 1256 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/LICENSE b/teleirc/matterbridge/vendor/github.com/labstack/gommon/LICENSE new file mode 100644 index 0000000..fc718fa --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2018 labstack + +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/teleirc/matterbridge/vendor/github.com/labstack/gommon/bytes/README.md b/teleirc/matterbridge/vendor/github.com/labstack/gommon/bytes/README.md new file mode 100644 index 0000000..6e3b0fd --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/bytes/README.md @@ -0,0 +1,29 @@ +# Bytes + +- Format bytes integer to human readable bytes string. +- Parse human readable bytes string to bytes integer. + +## Installation + +```go +go get github.com/labstack/gommon/bytes +``` + +## [Usage](https://github.com/labstack/gommon/blob/master/bytes/bytes_test.go) + +### Format + +```go +println(bytes.Format(13231323)) +``` + +`12.62MB` + +### Parse + +```go +b, _ = Parse("2M") +println(b) +``` + +`2097152` diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/bytes/bytes.go b/teleirc/matterbridge/vendor/github.com/labstack/gommon/bytes/bytes.go new file mode 100644 index 0000000..b07e31c --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/bytes/bytes.go @@ -0,0 +1,216 @@ +package bytes + +import ( + "fmt" + "regexp" + "strconv" + "strings" +) + +type ( + // Bytes struct + Bytes struct{} +) + +// binary units (IEC 60027) +const ( + _ = 1.0 << (10 * iota) // ignore first value by assigning to blank identifier + KiB + MiB + GiB + TiB + PiB + EiB +) + +// decimal units (SI international system of units) +const ( + KB = 1000 + MB = KB * 1000 + GB = MB * 1000 + TB = GB * 1000 + PB = TB * 1000 + EB = PB * 1000 +) + +var ( + patternBinary = regexp.MustCompile(`(?i)^(-?\d+(?:\.\d+)?)\s?([KMGTPE]iB?)$`) + patternDecimal = regexp.MustCompile(`(?i)^(-?\d+(?:\.\d+)?)\s?([KMGTPE]B?|B?)$`) + global = New() +) + +// New creates a Bytes instance. +func New() *Bytes { + return &Bytes{} +} + +// Format formats bytes integer to human readable string according to IEC 60027. +// For example, 31323 bytes will return 30.59KB. +func (b *Bytes) Format(value int64) string { + return b.FormatBinary(value) +} + +// FormatBinary formats bytes integer to human readable string according to IEC 60027. +// For example, 31323 bytes will return 30.59KB. +func (*Bytes) FormatBinary(value int64) string { + multiple := "" + val := float64(value) + + switch { + case value >= EiB: + val /= EiB + multiple = "EiB" + case value >= PiB: + val /= PiB + multiple = "PiB" + case value >= TiB: + val /= TiB + multiple = "TiB" + case value >= GiB: + val /= GiB + multiple = "GiB" + case value >= MiB: + val /= MiB + multiple = "MiB" + case value >= KiB: + val /= KiB + multiple = "KiB" + case value == 0: + return "0" + default: + return strconv.FormatInt(value, 10) + "B" + } + + return fmt.Sprintf("%.2f%s", val, multiple) +} + +// FormatDecimal formats bytes integer to human readable string according to SI international system of units. +// For example, 31323 bytes will return 31.32KB. +func (*Bytes) FormatDecimal(value int64) string { + multiple := "" + val := float64(value) + + switch { + case value >= EB: + val /= EB + multiple = "EB" + case value >= PB: + val /= PB + multiple = "PB" + case value >= TB: + val /= TB + multiple = "TB" + case value >= GB: + val /= GB + multiple = "GB" + case value >= MB: + val /= MB + multiple = "MB" + case value >= KB: + val /= KB + multiple = "KB" + case value == 0: + return "0" + default: + return strconv.FormatInt(value, 10) + "B" + } + + return fmt.Sprintf("%.2f%s", val, multiple) +} + +// Parse parses human readable bytes string to bytes integer. +// For example, 6GiB (6Gi is also valid) will return 6442450944, and +// 6GB (6G is also valid) will return 6000000000. +func (b *Bytes) Parse(value string) (int64, error) { + + i, err := b.ParseBinary(value) + if err == nil { + return i, err + } + + return b.ParseDecimal(value) +} + +// ParseBinary parses human readable bytes string to bytes integer. +// For example, 6GiB (6Gi is also valid) will return 6442450944. +func (*Bytes) ParseBinary(value string) (i int64, err error) { + parts := patternBinary.FindStringSubmatch(value) + if len(parts) < 3 { + return 0, fmt.Errorf("error parsing value=%s", value) + } + bytesString := parts[1] + multiple := strings.ToUpper(parts[2]) + bytes, err := strconv.ParseFloat(bytesString, 64) + if err != nil { + return + } + + switch multiple { + case "KI", "KIB": + return int64(bytes * KiB), nil + case "MI", "MIB": + return int64(bytes * MiB), nil + case "GI", "GIB": + return int64(bytes * GiB), nil + case "TI", "TIB": + return int64(bytes * TiB), nil + case "PI", "PIB": + return int64(bytes * PiB), nil + case "EI", "EIB": + return int64(bytes * EiB), nil + default: + return int64(bytes), nil + } +} + +// ParseDecimal parses human readable bytes string to bytes integer. +// For example, 6GB (6G is also valid) will return 6000000000. +func (*Bytes) ParseDecimal(value string) (i int64, err error) { + parts := patternDecimal.FindStringSubmatch(value) + if len(parts) < 3 { + return 0, fmt.Errorf("error parsing value=%s", value) + } + bytesString := parts[1] + multiple := strings.ToUpper(parts[2]) + bytes, err := strconv.ParseFloat(bytesString, 64) + if err != nil { + return + } + + switch multiple { + case "K", "KB": + return int64(bytes * KB), nil + case "M", "MB": + return int64(bytes * MB), nil + case "G", "GB": + return int64(bytes * GB), nil + case "T", "TB": + return int64(bytes * TB), nil + case "P", "PB": + return int64(bytes * PB), nil + case "E", "EB": + return int64(bytes * EB), nil + default: + return int64(bytes), nil + } +} + +// Format wraps global Bytes's Format function. +func Format(value int64) string { + return global.Format(value) +} + +// FormatBinary wraps global Bytes's FormatBinary function. +func FormatBinary(value int64) string { + return global.FormatBinary(value) +} + +// FormatDecimal wraps global Bytes's FormatDecimal function. +func FormatDecimal(value int64) string { + return global.FormatDecimal(value) +} + +// Parse wraps global Bytes's Parse function. +func Parse(value string) (int64, error) { + return global.Parse(value) +} diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/color/README.md b/teleirc/matterbridge/vendor/github.com/labstack/gommon/color/README.md new file mode 100644 index 0000000..297c351 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/color/README.md @@ -0,0 +1,86 @@ +# Color + +Style terminal text. + +## Installation + +```sh +go get github.com/labstack/gommon/color +``` + +## Windows? + +Try [cmder](http://bliker.github.io/cmder) or https://github.com/mattn/go-colorable + +## [Usage](https://github.com/labstack/gommon/blob/master/color/color_test.go) + +```sh +import github.com/labstack/gommon/color +``` + +### Colored text + +```go +color.Println(color.Black("black")) +color.Println(color.Red("red")) +color.Println(color.Green("green")) +color.Println(color.Yellow("yellow")) +color.Println(color.Blue("blue")) +color.Println(color.Magenta("magenta")) +color.Println(color.Cyan("cyan")) +color.Println(color.White("white")) +color.Println(color.Grey("grey")) +``` + + +### Colored background + +```go +color.Println(color.BlackBg("black background", color.Wht)) +color.Println(color.RedBg("red background")) +color.Println(color.GreenBg("green background")) +color.Println(color.YellowBg("yellow background")) +color.Println(color.BlueBg("blue background")) +color.Println(color.MagentaBg("magenta background")) +color.Println(color.CyanBg("cyan background")) +color.Println(color.WhiteBg("white background")) +``` + + +### Emphasis + +```go +color.Println(color.Bold("bold")) +color.Println(color.Dim("dim")) +color.Println(color.Italic("italic")) +color.Println(color.Underline("underline")) +color.Println(color.Inverse("inverse")) +color.Println(color.Hidden("hidden")) +color.Println(color.Strikeout("strikeout")) +``` + + +### Mix and match + +```go +color.Println(color.Green("bold green with white background", color.B, color.WhtBg)) +color.Println(color.Red("underline red", color.U)) +color.Println(color.Yellow("dim yellow", color.D)) +color.Println(color.Cyan("inverse cyan", color.In)) +color.Println(color.Blue("bold underline dim blue", color.B, color.U, color.D)) +``` + + +### Enable/Disable the package + +```go +color.Disable() +color.Enable() +``` + +### New instance + +```go +c := New() +c.Green("green") +``` diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/color/color.go b/teleirc/matterbridge/vendor/github.com/labstack/gommon/color/color.go new file mode 100644 index 0000000..4131dcf --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/color/color.go @@ -0,0 +1,407 @@ +package color + +import ( + "bytes" + "fmt" + "io" + "os" + + "github.com/mattn/go-colorable" + "github.com/mattn/go-isatty" +) + +type ( + inner func(interface{}, []string, *Color) string +) + +// Color styles +const ( + // Blk Black text style + Blk = "30" + // Rd red text style + Rd = "31" + // Grn green text style + Grn = "32" + // Yel yellow text style + Yel = "33" + // Blu blue text style + Blu = "34" + // Mgn magenta text style + Mgn = "35" + // Cyn cyan text style + Cyn = "36" + // Wht white text style + Wht = "37" + // Gry grey text style + Gry = "90" + + // BlkBg black background style + BlkBg = "40" + // RdBg red background style + RdBg = "41" + // GrnBg green background style + GrnBg = "42" + // YelBg yellow background style + YelBg = "43" + // BluBg blue background style + BluBg = "44" + // MgnBg magenta background style + MgnBg = "45" + // CynBg cyan background style + CynBg = "46" + // WhtBg white background style + WhtBg = "47" + + // R reset emphasis style + R = "0" + // B bold emphasis style + B = "1" + // D dim emphasis style + D = "2" + // I italic emphasis style + I = "3" + // U underline emphasis style + U = "4" + // In inverse emphasis style + In = "7" + // H hidden emphasis style + H = "8" + // S strikeout emphasis style + S = "9" +) + +var ( + black = outer(Blk) + red = outer(Rd) + green = outer(Grn) + yellow = outer(Yel) + blue = outer(Blu) + magenta = outer(Mgn) + cyan = outer(Cyn) + white = outer(Wht) + grey = outer(Gry) + + blackBg = outer(BlkBg) + redBg = outer(RdBg) + greenBg = outer(GrnBg) + yellowBg = outer(YelBg) + blueBg = outer(BluBg) + magentaBg = outer(MgnBg) + cyanBg = outer(CynBg) + whiteBg = outer(WhtBg) + + reset = outer(R) + bold = outer(B) + dim = outer(D) + italic = outer(I) + underline = outer(U) + inverse = outer(In) + hidden = outer(H) + strikeout = outer(S) + + global = New() +) + +func outer(n string) inner { + return func(msg interface{}, styles []string, c *Color) string { + // TODO: Drop fmt to boost performance? + if c.disabled { + return fmt.Sprintf("%v", msg) + } + + b := new(bytes.Buffer) + b.WriteString("\x1b[") + b.WriteString(n) + for _, s := range styles { + b.WriteString(";") + b.WriteString(s) + } + b.WriteString("m") + return fmt.Sprintf("%s%v\x1b[0m", b.String(), msg) + } +} + +type ( + Color struct { + output io.Writer + disabled bool + } +) + +// New creates a Color instance. +func New() (c *Color) { + c = new(Color) + c.SetOutput(colorable.NewColorableStdout()) + return +} + +// Output returns the output. +func (c *Color) Output() io.Writer { + return c.output +} + +// SetOutput sets the output. +func (c *Color) SetOutput(w io.Writer) { + c.output = w + if w, ok := w.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) { + c.disabled = true + } +} + +// Disable disables the colors and styles. +func (c *Color) Disable() { + c.disabled = true +} + +// Enable enables the colors and styles. +func (c *Color) Enable() { + c.disabled = false +} + +// Print is analogous to `fmt.Print` with termial detection. +func (c *Color) Print(args ...interface{}) { + fmt.Fprint(c.output, args...) +} + +// Println is analogous to `fmt.Println` with termial detection. +func (c *Color) Println(args ...interface{}) { + fmt.Fprintln(c.output, args...) +} + +// Printf is analogous to `fmt.Printf` with termial detection. +func (c *Color) Printf(format string, args ...interface{}) { + fmt.Fprintf(c.output, format, args...) +} + +func (c *Color) Black(msg interface{}, styles ...string) string { + return black(msg, styles, c) +} + +func (c *Color) Red(msg interface{}, styles ...string) string { + return red(msg, styles, c) +} + +func (c *Color) Green(msg interface{}, styles ...string) string { + return green(msg, styles, c) +} + +func (c *Color) Yellow(msg interface{}, styles ...string) string { + return yellow(msg, styles, c) +} + +func (c *Color) Blue(msg interface{}, styles ...string) string { + return blue(msg, styles, c) +} + +func (c *Color) Magenta(msg interface{}, styles ...string) string { + return magenta(msg, styles, c) +} + +func (c *Color) Cyan(msg interface{}, styles ...string) string { + return cyan(msg, styles, c) +} + +func (c *Color) White(msg interface{}, styles ...string) string { + return white(msg, styles, c) +} + +func (c *Color) Grey(msg interface{}, styles ...string) string { + return grey(msg, styles, c) +} + +func (c *Color) BlackBg(msg interface{}, styles ...string) string { + return blackBg(msg, styles, c) +} + +func (c *Color) RedBg(msg interface{}, styles ...string) string { + return redBg(msg, styles, c) +} + +func (c *Color) GreenBg(msg interface{}, styles ...string) string { + return greenBg(msg, styles, c) +} + +func (c *Color) YellowBg(msg interface{}, styles ...string) string { + return yellowBg(msg, styles, c) +} + +func (c *Color) BlueBg(msg interface{}, styles ...string) string { + return blueBg(msg, styles, c) +} + +func (c *Color) MagentaBg(msg interface{}, styles ...string) string { + return magentaBg(msg, styles, c) +} + +func (c *Color) CyanBg(msg interface{}, styles ...string) string { + return cyanBg(msg, styles, c) +} + +func (c *Color) WhiteBg(msg interface{}, styles ...string) string { + return whiteBg(msg, styles, c) +} + +func (c *Color) Reset(msg interface{}, styles ...string) string { + return reset(msg, styles, c) +} + +func (c *Color) Bold(msg interface{}, styles ...string) string { + return bold(msg, styles, c) +} + +func (c *Color) Dim(msg interface{}, styles ...string) string { + return dim(msg, styles, c) +} + +func (c *Color) Italic(msg interface{}, styles ...string) string { + return italic(msg, styles, c) +} + +func (c *Color) Underline(msg interface{}, styles ...string) string { + return underline(msg, styles, c) +} + +func (c *Color) Inverse(msg interface{}, styles ...string) string { + return inverse(msg, styles, c) +} + +func (c *Color) Hidden(msg interface{}, styles ...string) string { + return hidden(msg, styles, c) +} + +func (c *Color) Strikeout(msg interface{}, styles ...string) string { + return strikeout(msg, styles, c) +} + +// Output returns the output. +func Output() io.Writer { + return global.output +} + +// SetOutput sets the output. +func SetOutput(w io.Writer) { + global.SetOutput(w) +} + +func Disable() { + global.Disable() +} + +func Enable() { + global.Enable() +} + +// Print is analogous to `fmt.Print` with termial detection. +func Print(args ...interface{}) { + global.Print(args...) +} + +// Println is analogous to `fmt.Println` with termial detection. +func Println(args ...interface{}) { + global.Println(args...) +} + +// Printf is analogous to `fmt.Printf` with termial detection. +func Printf(format string, args ...interface{}) { + global.Printf(format, args...) +} + +func Black(msg interface{}, styles ...string) string { + return global.Black(msg, styles...) +} + +func Red(msg interface{}, styles ...string) string { + return global.Red(msg, styles...) +} + +func Green(msg interface{}, styles ...string) string { + return global.Green(msg, styles...) +} + +func Yellow(msg interface{}, styles ...string) string { + return global.Yellow(msg, styles...) +} + +func Blue(msg interface{}, styles ...string) string { + return global.Blue(msg, styles...) +} + +func Magenta(msg interface{}, styles ...string) string { + return global.Magenta(msg, styles...) +} + +func Cyan(msg interface{}, styles ...string) string { + return global.Cyan(msg, styles...) +} + +func White(msg interface{}, styles ...string) string { + return global.White(msg, styles...) +} + +func Grey(msg interface{}, styles ...string) string { + return global.Grey(msg, styles...) +} + +func BlackBg(msg interface{}, styles ...string) string { + return global.BlackBg(msg, styles...) +} + +func RedBg(msg interface{}, styles ...string) string { + return global.RedBg(msg, styles...) +} + +func GreenBg(msg interface{}, styles ...string) string { + return global.GreenBg(msg, styles...) +} + +func YellowBg(msg interface{}, styles ...string) string { + return global.YellowBg(msg, styles...) +} + +func BlueBg(msg interface{}, styles ...string) string { + return global.BlueBg(msg, styles...) +} + +func MagentaBg(msg interface{}, styles ...string) string { + return global.MagentaBg(msg, styles...) +} + +func CyanBg(msg interface{}, styles ...string) string { + return global.CyanBg(msg, styles...) +} + +func WhiteBg(msg interface{}, styles ...string) string { + return global.WhiteBg(msg, styles...) +} + +func Reset(msg interface{}, styles ...string) string { + return global.Reset(msg, styles...) +} + +func Bold(msg interface{}, styles ...string) string { + return global.Bold(msg, styles...) +} + +func Dim(msg interface{}, styles ...string) string { + return global.Dim(msg, styles...) +} + +func Italic(msg interface{}, styles ...string) string { + return global.Italic(msg, styles...) +} + +func Underline(msg interface{}, styles ...string) string { + return global.Underline(msg, styles...) +} + +func Inverse(msg interface{}, styles ...string) string { + return global.Inverse(msg, styles...) +} + +func Hidden(msg interface{}, styles ...string) string { + return global.Hidden(msg, styles...) +} + +func Strikeout(msg interface{}, styles ...string) string { + return global.Strikeout(msg, styles...) +} diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/README.md b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/README.md new file mode 100644 index 0000000..d5b9e9f --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/README.md @@ -0,0 +1,5 @@ +## WORK IN PROGRESS + +### Usage + +[log_test.go](log_test.go) diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/color.go b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/color.go new file mode 100644 index 0000000..7351b39 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/color.go @@ -0,0 +1,13 @@ +// +build !appengine + +package log + +import ( + "io" + + "github.com/mattn/go-colorable" +) + +func output() io.Writer { + return colorable.NewColorableStdout() +} diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/log.go b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/log.go new file mode 100644 index 0000000..25f719a --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/log.go @@ -0,0 +1,418 @@ +package log + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "os" + "path" + "runtime" + "strconv" + "sync" + "sync/atomic" + "time" + + "github.com/mattn/go-isatty" + "github.com/valyala/fasttemplate" + + "github.com/labstack/gommon/color" +) + +type ( + Logger struct { + prefix string + level uint32 + skip int + output io.Writer + template *fasttemplate.Template + levels []string + color *color.Color + bufferPool sync.Pool + mutex sync.Mutex + } + + Lvl uint8 + + JSON map[string]interface{} +) + +const ( + DEBUG Lvl = iota + 1 + INFO + WARN + ERROR + OFF + panicLevel + fatalLevel +) + +var ( + global = New("-") + defaultHeader = `{"time":"${time_rfc3339_nano}","level":"${level}","prefix":"${prefix}",` + + `"file":"${short_file}","line":"${line}"}` +) + +func init() { + global.skip = 3 +} + +func New(prefix string) (l *Logger) { + l = &Logger{ + level: uint32(INFO), + skip: 2, + prefix: prefix, + template: l.newTemplate(defaultHeader), + color: color.New(), + bufferPool: sync.Pool{ + New: func() interface{} { + return bytes.NewBuffer(make([]byte, 256)) + }, + }, + } + l.initLevels() + l.SetOutput(output()) + return +} + +func (l *Logger) initLevels() { + l.levels = []string{ + "-", + l.color.Blue("DEBUG"), + l.color.Green("INFO"), + l.color.Yellow("WARN"), + l.color.Red("ERROR"), + "", + l.color.Yellow("PANIC", color.U), + l.color.Red("FATAL", color.U), + } +} + +func (l *Logger) newTemplate(format string) *fasttemplate.Template { + return fasttemplate.New(format, "${", "}") +} + +func (l *Logger) DisableColor() { + l.color.Disable() + l.initLevels() +} + +func (l *Logger) EnableColor() { + l.color.Enable() + l.initLevels() +} + +func (l *Logger) Prefix() string { + return l.prefix +} + +func (l *Logger) SetPrefix(p string) { + l.prefix = p +} + +func (l *Logger) Level() Lvl { + return Lvl(atomic.LoadUint32(&l.level)) +} + +func (l *Logger) SetLevel(level Lvl) { + atomic.StoreUint32(&l.level, uint32(level)) +} + +func (l *Logger) Output() io.Writer { + return l.output +} + +func (l *Logger) SetOutput(w io.Writer) { + l.output = w + if w, ok := w.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) { + l.DisableColor() + } +} + +func (l *Logger) Color() *color.Color { + return l.color +} + +func (l *Logger) SetHeader(h string) { + l.template = l.newTemplate(h) +} + +func (l *Logger) Print(i ...interface{}) { + l.log(0, "", i...) + // fmt.Fprintln(l.output, i...) +} + +func (l *Logger) Printf(format string, args ...interface{}) { + l.log(0, format, args...) +} + +func (l *Logger) Printj(j JSON) { + l.log(0, "json", j) +} + +func (l *Logger) Debug(i ...interface{}) { + l.log(DEBUG, "", i...) +} + +func (l *Logger) Debugf(format string, args ...interface{}) { + l.log(DEBUG, format, args...) +} + +func (l *Logger) Debugj(j JSON) { + l.log(DEBUG, "json", j) +} + +func (l *Logger) Info(i ...interface{}) { + l.log(INFO, "", i...) +} + +func (l *Logger) Infof(format string, args ...interface{}) { + l.log(INFO, format, args...) +} + +func (l *Logger) Infoj(j JSON) { + l.log(INFO, "json", j) +} + +func (l *Logger) Warn(i ...interface{}) { + l.log(WARN, "", i...) +} + +func (l *Logger) Warnf(format string, args ...interface{}) { + l.log(WARN, format, args...) +} + +func (l *Logger) Warnj(j JSON) { + l.log(WARN, "json", j) +} + +func (l *Logger) Error(i ...interface{}) { + l.log(ERROR, "", i...) +} + +func (l *Logger) Errorf(format string, args ...interface{}) { + l.log(ERROR, format, args...) +} + +func (l *Logger) Errorj(j JSON) { + l.log(ERROR, "json", j) +} + +func (l *Logger) Fatal(i ...interface{}) { + l.log(fatalLevel, "", i...) + os.Exit(1) +} + +func (l *Logger) Fatalf(format string, args ...interface{}) { + l.log(fatalLevel, format, args...) + os.Exit(1) +} + +func (l *Logger) Fatalj(j JSON) { + l.log(fatalLevel, "json", j) + os.Exit(1) +} + +func (l *Logger) Panic(i ...interface{}) { + l.log(panicLevel, "", i...) + panic(fmt.Sprint(i...)) +} + +func (l *Logger) Panicf(format string, args ...interface{}) { + l.log(panicLevel, format, args...) + panic(fmt.Sprintf(format, args...)) +} + +func (l *Logger) Panicj(j JSON) { + l.log(panicLevel, "json", j) + panic(j) +} + +func DisableColor() { + global.DisableColor() +} + +func EnableColor() { + global.EnableColor() +} + +func Prefix() string { + return global.Prefix() +} + +func SetPrefix(p string) { + global.SetPrefix(p) +} + +func Level() Lvl { + return global.Level() +} + +func SetLevel(level Lvl) { + global.SetLevel(level) +} + +func Output() io.Writer { + return global.Output() +} + +func SetOutput(w io.Writer) { + global.SetOutput(w) +} + +func SetHeader(h string) { + global.SetHeader(h) +} + +func Print(i ...interface{}) { + global.Print(i...) +} + +func Printf(format string, args ...interface{}) { + global.Printf(format, args...) +} + +func Printj(j JSON) { + global.Printj(j) +} + +func Debug(i ...interface{}) { + global.Debug(i...) +} + +func Debugf(format string, args ...interface{}) { + global.Debugf(format, args...) +} + +func Debugj(j JSON) { + global.Debugj(j) +} + +func Info(i ...interface{}) { + global.Info(i...) +} + +func Infof(format string, args ...interface{}) { + global.Infof(format, args...) +} + +func Infoj(j JSON) { + global.Infoj(j) +} + +func Warn(i ...interface{}) { + global.Warn(i...) +} + +func Warnf(format string, args ...interface{}) { + global.Warnf(format, args...) +} + +func Warnj(j JSON) { + global.Warnj(j) +} + +func Error(i ...interface{}) { + global.Error(i...) +} + +func Errorf(format string, args ...interface{}) { + global.Errorf(format, args...) +} + +func Errorj(j JSON) { + global.Errorj(j) +} + +func Fatal(i ...interface{}) { + global.Fatal(i...) +} + +func Fatalf(format string, args ...interface{}) { + global.Fatalf(format, args...) +} + +func Fatalj(j JSON) { + global.Fatalj(j) +} + +func Panic(i ...interface{}) { + global.Panic(i...) +} + +func Panicf(format string, args ...interface{}) { + global.Panicf(format, args...) +} + +func Panicj(j JSON) { + global.Panicj(j) +} + +func (l *Logger) log(level Lvl, format string, args ...interface{}) { + if level >= l.Level() || level == 0 { + buf := l.bufferPool.Get().(*bytes.Buffer) + buf.Reset() + defer l.bufferPool.Put(buf) + _, file, line, _ := runtime.Caller(l.skip) + message := "" + + if format == "" { + message = fmt.Sprint(args...) + } else if format == "json" { + b, err := json.Marshal(args[0]) + if err != nil { + panic(err) + } + message = string(b) + } else { + message = fmt.Sprintf(format, args...) + } + + _, err := l.template.ExecuteFunc(buf, func(w io.Writer, tag string) (int, error) { + switch tag { + case "time_rfc3339": + return w.Write([]byte(time.Now().Format(time.RFC3339))) + case "time_rfc3339_nano": + return w.Write([]byte(time.Now().Format(time.RFC3339Nano))) + case "level": + return w.Write([]byte(l.levels[level])) + case "prefix": + return w.Write([]byte(l.prefix)) + case "long_file": + return w.Write([]byte(file)) + case "short_file": + return w.Write([]byte(path.Base(file))) + case "line": + return w.Write([]byte(strconv.Itoa(line))) + } + return 0, nil + }) + + if err == nil { + s := buf.String() + i := buf.Len() - 1 + if i >= 0 && s[i] == '}' { + // JSON header + buf.Truncate(i) + buf.WriteByte(',') + if format == "json" { + buf.WriteString(message[1:]) + } else { + buf.WriteString(`"message":`) + buf.WriteString(strconv.Quote(message)) + buf.WriteString(`}`) + } + } else { + // Text header + if len(s) > 0 { + buf.WriteByte(' ') + } + buf.WriteString(message) + } + buf.WriteByte('\n') + l.mutex.Lock() + defer l.mutex.Unlock() + l.output.Write(buf.Bytes()) + } + } +} diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/white.go b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/white.go new file mode 100644 index 0000000..746cc56 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/log/white.go @@ -0,0 +1,12 @@ +// +build appengine + +package log + +import ( + "io" + "os" +) + +func output() io.Writer { + return os.Stdout +} diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/random/random.go b/teleirc/matterbridge/vendor/github.com/labstack/gommon/random/random.go new file mode 100644 index 0000000..482d052 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/random/random.go @@ -0,0 +1,48 @@ +package random + +import ( + "math/rand" + "strings" + "time" +) + +type ( + Random struct { + } +) + +// Charsets +const ( + Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + Lowercase = "abcdefghijklmnopqrstuvwxyz" + Alphabetic = Uppercase + Lowercase + Numeric = "0123456789" + Alphanumeric = Alphabetic + Numeric + Symbols = "`" + `~!@#$%^&*()-_+={}[]|\;:"<>,./?` + Hex = Numeric + "abcdef" +) + +var ( + global = New() +) + +func New() *Random { + rand.Seed(time.Now().UnixNano()) + return new(Random) +} + +func (r *Random) String(length uint8, charsets ...string) string { + charset := strings.Join(charsets, "") + if charset == "" { + charset = Alphanumeric + } + b := make([]byte, length) + for i := range b { + b[i] = charset[rand.Int63()%int64(len(charset))] + } + return string(b) +} + +func String(length uint8, charsets ...string) string { + return global.String(length, charsets...) +} |
