Fix example

This commit is contained in:
Simon Eskildsen 2014-03-10 19:59:18 -04:00
parent afde6aea11
commit ec306913da
3 changed files with 33 additions and 7 deletions

View File

@ -3,6 +3,27 @@
Logrus is a simple, opinionated structured logging package for Go which is
completely API compatible with the standard library logger.
Nicely color-coded in development (when a TTY is attached):
[Imgur](http://i.imgur.com/PY7qMwd.png)
With `log.Formatter = new(logrus.JSONFormatter)`:
```json
{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the
ocean","size":"10","time":"2014-03-10 19:57:38.562264131 -0400 EDT"}
{"level":"warning","msg":"The group's number increased
tremendously!","number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297
-0400 EDT"}
{"animal":"walrus","level":"info","msg":"A giant walrus
appears!","size":"10","time":"2014-03-10 19:57:38.562500591 -0400 EDT"}
{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the
ocean.","size":"9","time":"2014-03-10 19:57:38.562527896 -0400 EDT"}
{"level":"fatal","msg":"The ice
breaks!","number":100,"omg":true,"time":"2014-03-10 19:57:38.562543128 -0400
EDT"}
```
#### Fields
Logrus encourages careful, structured logging. It encourages the use of logging

View File

@ -85,6 +85,10 @@ func (entry *Entry) Debug(args ...interface{}) {
}
}
func (entry *Entry) Print(args ...interface{}) {
entry.Info(args...)
}
func (entry *Entry) Info(args ...interface{}) {
if entry.logger.Level >= Info {
entry.log("info", fmt.Sprint(args...))

View File

@ -6,31 +6,32 @@ import (
func main() {
log := logrus.New()
log.Formatter = new(logrus.JSONFormatter)
for {
log.WithFields(logrus.Fields{
"animal": "walrus",
"size": "10",
}).Print("Hello WOrld!!")
}).Print("A group of walrus emerges from the ocean")
log.WithFields(logrus.Fields{
"omg": true,
"number": 122,
}).Warn("There were some omgs")
}).Warn("The group's number increased tremendously!")
log.WithFields(logrus.Fields{
"animal": "walrus",
"size": "10",
}).Print("Hello WOrld!!")
}).Print("A giant walrus appears!")
log.WithFields(logrus.Fields{
"animal": "walrus",
"size": "10",
}).Print("Hello WOrld!!")
"size": "9",
}).Print("Tremendously sized cow enters the ocean.")
log.WithFields(logrus.Fields{
"omg": true,
"number": 122,
}).Fatal("There were some omgs")
"number": 100,
}).Fatal("The ice breaks!")
}
}