Logrus a Logging framework in Go Lang

My notes while experimenting logrus as available here : https://github.com/sirupsen/logrus

Sample Program to start with :

 

package main

import (
   log "github.com/sirupsen/logrus"
)

func main() {


   log.WithFields(log.Fields{
      "animal": "walrus",
      "number": 1,
      "size":   10,
   }).Info("A walrus appears")

   Formatter := new(log.TextFormatter)
   Formatter.TimestampFormat = "02-01-2006 15:04:05"
   Formatter.FullTimestamp = true
   log.SetFormatter(Formatter)
   log.Info("Some info. Earth is not flat.")
   log.Warning("This is a warning")
   log.Error("Not fatal. An error. Won't stop execution")
   log.Fatal("MAYDAY MAYDAY MAYDAY. Execution will be stopped here")
   log.Panic("Do not panic")
}

Output :

esumits-MacBook-Pro:godev esumit$ go run golog.go 
INFO[0000] A walrus appears animal=walrus number=1 size=10
INFO[27-05-2018 09:53:26] Some info. Earth is not flat. 
WARN[27-05-2018 09:53:26] This is a warning 
ERRO[27-05-2018 09:53:26] Not fatal. An error. Won't stop execution 
FATA[27-05-2018 09:53:26] MAYDAY MAYDAY MAYDAY. Execution will be stopped here 
exit status 1

 

esumits-MacBook-Pro:godev esumit$ go version
go version go1.10.2 darwin/amd64
esumits-MacBook-Pro:godev esumit$

Reference :

http://callistaenterprise.se/blogg/teknik/2017/08/02/go-blog-series-part10/

https://esc.sh/blog/golang-logging-using-logrus/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s