Sirupsen/logrus
package main
import (
"github.com/Sirupsen/logrus"
"os"
)
// Create a new instance of the logger. You can have any number of instances.
var log1 = logrus.New()
var log2 = logrus.New()
func main() {
// The API for setting attributes is a little different than the package level
// exported logger. See Godoc.
log1.Out = os.Stderr
log1.Formatter = &logrus.TextFormatter{}
LogOutputFile, err := os.OpenFile("out.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil {
logrus.Fatalf("error opening file: %v", err)
}
log2.Out = LogOutputFile
log2.Formatter = &logrus.JSONFormatter{}
log1.WithFields(logrus.Fields{
"animal": "walrus",
"size": 10,
}).Info("A group of walrus emerges from the ocean")
log2.WithFields(logrus.Fields{
"animal": "walrus",
"size": 10,
}).Info("A group of walrus emerges from the ocean")
}
サンプルのフック( 'logrus'ページにリストされている以外)のために' lumberjack'のフックを実装しましたログ):https://github.com/dc0d/lumberjackhook –