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
+21
View File
@@ -3,6 +3,27 @@
Logrus is a simple, opinionated structured logging package for Go which is Logrus is a simple, opinionated structured logging package for Go which is
completely API compatible with the standard library logger. 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 #### Fields
Logrus encourages careful, structured logging. It encourages the use of logging Logrus encourages careful, structured logging. It encourages the use of logging
+4
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{}) { func (entry *Entry) Info(args ...interface{}) {
if entry.logger.Level >= Info { if entry.logger.Level >= Info {
entry.log("info", fmt.Sprint(args...)) entry.log("info", fmt.Sprint(args...))
+8 -7
View File
@@ -6,31 +6,32 @@ import (
func main() { func main() {
log := logrus.New() log := logrus.New()
log.Formatter = new(logrus.JSONFormatter)
for { for {
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"animal": "walrus", "animal": "walrus",
"size": "10", "size": "10",
}).Print("Hello WOrld!!") }).Print("A group of walrus emerges from the ocean")
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"omg": true, "omg": true,
"number": 122, "number": 122,
}).Warn("There were some omgs") }).Warn("The group's number increased tremendously!")
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"animal": "walrus", "animal": "walrus",
"size": "10", "size": "10",
}).Print("Hello WOrld!!") }).Print("A giant walrus appears!")
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"animal": "walrus", "animal": "walrus",
"size": "10", "size": "9",
}).Print("Hello WOrld!!") }).Print("Tremendously sized cow enters the ocean.")
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"omg": true, "omg": true,
"number": 122, "number": 100,
}).Fatal("There were some omgs") }).Fatal("The ice breaks!")
} }
} }