Files
weave-scope/vendor/github.com/weaveworks/weave/common/logging.go
Marc CARRE 76807eb54f Fix: cannot find package github.com/Sirupsen/logrus in dependencies.
Fix:
```
vendor/github.com/docker/docker/pkg/archive/archive.go:20:2: cannot find package "github.com/Sirupsen/logrus" in any of:
    /go/src/github.com/weaveworks/scope/vendor/github.com/Sirupsen/logrus (vendor tree)
    /usr/local/go/src/github.com/Sirupsen/logrus (from $GOROOT)
    /go/src/github.com/Sirupsen/logrus (from $GOPATH)
```
via:
```
$ git grep -l Sirupsen | xargs sed -i 's:github.com/Sirupsen/logrus:github.com/sirupsen/logrus:g'
```
2017-10-08 18:37:28 +01:00

67 lines
1.2 KiB
Go

package common
import (
"bytes"
"fmt"
"strings"
"github.com/sirupsen/logrus"
)
type textFormatter struct {
}
// Based off logrus.TextFormatter, which behaves completely
// differently when you don't want colored output
func (f *textFormatter) Format(entry *logrus.Entry) ([]byte, error) {
b := &bytes.Buffer{}
levelText := strings.ToUpper(entry.Level.String())[0:4]
timeStamp := entry.Time.Format("2006/01/02 15:04:05.000000")
if len(entry.Data) > 0 {
fmt.Fprintf(b, "%s: %s %-44s ", levelText, timeStamp, entry.Message)
for k, v := range entry.Data {
fmt.Fprintf(b, " %s=%v", k, v)
}
} else {
// No padding when there's no fields
fmt.Fprintf(b, "%s: %s %s", levelText, timeStamp, entry.Message)
}
b.WriteByte('\n')
return b.Bytes(), nil
}
var (
standardTextFormatter = &textFormatter{}
)
var (
Log *logrus.Logger
)
func init() {
Log = logrus.New()
Log.Formatter = standardTextFormatter
}
func SetLogLevel(levelname string) {
level, err := logrus.ParseLevel(levelname)
if err != nil {
Log.Fatal(err)
}
Log.Level = level
}
func CheckFatal(e error) {
if e != nil {
Log.Fatal(e)
}
}
func CheckWarn(e error) {
if e != nil {
Log.Warnln(e)
}
}