Menu Close

[Golang] Ghi log với sirupsen/logrusgger

Thư viện

https://github.com/sirupsen/logrus

Ví dụ sử dụng

package main

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

func main() {
    log.WithFields(log.Fields{
        "anima": "walrus",
        "size":   10,
    }).Info("A group of walrus emerges from the ocean")

    log.WithFields(log.Fields{
        "omg":    true,
        "number": 122,
    }).Warn("The groups number increased tremendously")

    log.WithFields(log.Fields{
        "omg":    true,
        "number": 100,
    }).Fatal("The ice breaks!")
}

Minh họa kết quả

INFO[0000] A group of walrus emerges from the ocean      animal=walrus size=10
WARN[0000] The group's number increased tremendously!    number=122 omg=true
FATA[0000] The ice breaks!                               number=100 omg=true

Leave a Reply

Your email address will not be published. Required fields are marked *