Generric JSON Formatted logger written in Go
var debug = flag.Bool("debug", false, "")
init (
logger.SetAppName("app_name")
)
func main() {
flag.Parse()
if *debug {
logger.SetLevel(logger.DebugLevel)
}
...
logger.WithFields(Fields{
"animal": "walrus",
}).Print("hello")
}
SetAppName("appname") // applicaton name
SetLevel(InfoLevel) // default: InfoLevel
Type("hoge") // set "type": "hoge"
WithFields(Fields{}) // set data fields
Print("hoge")
Printf("%s","hoge")
Println("hoge")
Debug, Debugf, Debugln
Info, Infof, Infoln
Warn, Warnf, Warnln
Error, Errorf, Errorln
Fatal, Fatalf, Fatalln
Panic, Panicf, Panicln
To use sentry logger, please initialize as the below, you need to pass the environemnt(local/develop/stg/prod)
env := util.GetEnv()
logger.InitSentry(env)
Now you can send the log to sentry.
logger.LogToSentry(fmt.Sprintf("Successfully updated portfolio chart for user %d", userID), "INFO")
- Logger factory for different logrus hooks (ElasticSearch, for example)