mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 22:26:30 +00:00
eeca435064
Update vendor Integrate rendezvous into status node Add a test with failover using rendezvous Use multiple servers in client Use discovery V5 by default and test that node can be started with rendezvous discovet Fix linter Update rendezvous client to one with instrumented stream Address feedback Fix test with updated topic limits Apply several suggestions Change log to debug for request errors because we continue execution Remove web3js after rebase Update rendezvous package
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
// Copyright 2013, Örjan Persson. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package logging
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
)
|
|
|
|
// TODO initialize here
|
|
var colors []string
|
|
var boldcolors []string
|
|
|
|
type color int
|
|
|
|
const (
|
|
colorBlack = (iota + 30)
|
|
colorRed
|
|
colorGreen
|
|
colorYellow
|
|
colorBlue
|
|
colorMagenta
|
|
colorCyan
|
|
colorWhite
|
|
)
|
|
|
|
// LogBackend utilizes the standard log module.
|
|
type LogBackend struct {
|
|
Logger *log.Logger
|
|
Color bool
|
|
}
|
|
|
|
// NewLogBackend creates a new LogBackend.
|
|
func NewLogBackend(out io.Writer, prefix string, flag int) *LogBackend {
|
|
return &LogBackend{Logger: log.New(out, prefix, flag)}
|
|
}
|
|
|
|
func (b *LogBackend) Log(level Level, calldepth int, rec *Record) error {
|
|
if b.Color {
|
|
buf := &bytes.Buffer{}
|
|
buf.Write([]byte(colors[level]))
|
|
buf.Write([]byte(rec.Formatted(calldepth + 1)))
|
|
buf.Write([]byte("\033[0m"))
|
|
// For some reason, the Go logger arbitrarily decided "2" was the correct
|
|
// call depth...
|
|
return b.Logger.Output(calldepth+2, buf.String())
|
|
} else {
|
|
return b.Logger.Output(calldepth+2, rec.Formatted(calldepth+1))
|
|
}
|
|
panic("should not be reached")
|
|
}
|
|
|
|
func colorSeq(color color) string {
|
|
return fmt.Sprintf("\033[%dm", int(color))
|
|
}
|
|
|
|
func colorSeqBold(color color) string {
|
|
return fmt.Sprintf("\033[%d;1m", int(color))
|
|
}
|
|
|
|
func init() {
|
|
colors = []string{
|
|
CRITICAL: colorSeq(colorMagenta),
|
|
ERROR: colorSeq(colorRed),
|
|
WARNING: colorSeq(colorYellow),
|
|
NOTICE: colorSeq(colorGreen),
|
|
DEBUG: colorSeq(colorCyan),
|
|
}
|
|
boldcolors = []string{
|
|
CRITICAL: colorSeqBold(colorMagenta),
|
|
ERROR: colorSeqBold(colorRed),
|
|
WARNING: colorSeqBold(colorYellow),
|
|
NOTICE: colorSeqBold(colorGreen),
|
|
DEBUG: colorSeqBold(colorCyan),
|
|
}
|
|
}
|