github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/util/logutil/format.go (about)

     1  package logutil
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"strings"
     7  
     8  	"github.com/sirupsen/logrus"
     9  )
    10  
    11  type Formatter struct {
    12  	logrus.TextFormatter
    13  }
    14  
    15  func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
    16  	msg := bytes.NewBuffer(nil)
    17  	fmt.Fprintf(msg, "%s: %s", strings.ToUpper(entry.Level.String()), entry.Message)
    18  	if v, ok := entry.Data[logrus.ErrorKey]; ok {
    19  		fmt.Fprintf(msg, ": %v", v)
    20  	}
    21  	fmt.Fprintf(msg, "\n")
    22  	return msg.Bytes(), nil
    23  }