func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
	output := f.LogFormat
	if output == "" {
		output = defaultLogFormat
	}
	timestampFormat := f.TimestampFormat
	if timestampFormat == "" {
		timestampFormat = defaultTimestampFormat
	}
	output = strings.Replace(output, "%time%", entry.Time.Format(timestampFormat), 1)
	output = strings.Replace(output, "%msg%", entry.Message, 1)
	level := strings.ToUpper(entry.Level.String())
	output = strings.Replace(output, "%lvl%", strings.ToLower(level), 1)
	fields := entry.Data
	runID, ok := fields[RunID]
	if ok {
		output = strings.Replace(output, "%runid%", fmt.Sprintf("runid=%v", runID), 1)
	} else {
		output = strings.Replace(output, "%runid%", "", 1)
	}
	clusterName, ok := fields[ClusterName]
	if ok {
		output = strings.Replace(output, "%clusterName%", fmt.Sprintf("clusterName=%v", clusterName), 1)
	} else {
		output = strings.Replace(output, "%clusterName%", "", 1)
	}
	for k, val := range entry.Data {
		switch v := val.(type) {
		case string:
			output = strings.Replace(output, "%"+k+"%", v, 1)
		case int:
			s := strconv.Itoa(v)
			output = strings.Replace(output, "%"+k+"%", s, 1)
		case bool:
			s := strconv.FormatBool(v)
			output = strings.Replace(output, "%"+k+"%", s, 1)
		}
	}
	var fileVal string
	if entry.HasCaller() {
		if f.CallerPrettyfier != nil {
			_, fileVal = f.CallerPrettyfier(entry.Caller)
		} else {
			fileVal = fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line)
		}
		if fileVal != "" {
			output = fmt.Sprintf("%s file=\"%s\"", output, fileVal)
		}
	}
	output = fmt.Sprintf("%s\n", output)
	return []byte(output), nil
}
Format building log message.
package utils
import (
	"context"
	"fmt"
	"github.com/dell/csi-isilon/common/constants"
	"github.com/sirupsen/logrus"
	"reflect"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"time"
)
var singletonLog *logrus.Logger
var once sync.Once
const (
	defaultLogFormat       = "time=\"%time%\" level=%lvl% %clusterName% %runid% msg=\"%msg%\""
	defaultTimestampFormat = time.RFC3339
	ClusterName            = "clusterName"
	PowerScaleLogger       = "powerscalelog"
	LogFields              = "fields"
	RequestID              = "requestid"
	RunID                  = "runid"
)
type Formatter struct {
	TimestampFormat string
	LogFormat string
	CallerPrettyfier func(*runtime.Frame) (function string, file string)
}