sirupsen / logrus

Structured, pluggable logging for Go.
MIT License
24.79k stars 2.27k forks source link

How to apply colours for a custom log format? #1411

Closed rodrigorodrigues closed 10 months ago

rodrigorodrigues commented 11 months ago

Hi all,

I was able to change the log format for the one that I need but I was wondering how can I apply the colours like the ones for default TextFormatter?

type MyFormatter struct {
}

func (f *MyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
    msg := fmt.Sprintf("%v %v sanctin-service-go %v", entry.Time, entry.Level, entry.Message)
    return []byte(msg), nil
}
func main() {
log = logrus.New()
   // Default formatter
/*formatter := &logrus.TextFormatter{
    ForceColors:      false, //Enable this for coloured output
    DisableColors:    false,
    TimestampFormat:  "2006-01-02T15:04:05.000",
    DisableTimestamp: false,
    FullTimestamp:    true,
}*/
log.SetFormatter(new(MyFormatter))

output with custom format. image

output with default format. image

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 10 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.