logrus 安装 使用

安装

logrus
go get github.com/sirupsen/logrus

无法访问 golang 所以就 先 clone github.com/golang的源码 然后生成
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/crypto.git
go get -u golang.org/x/crypto/ssh/terminal


git clone https://github.com/golang/sys.git

go get -u golang.org/x/sys/unix


使用

package main

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

type Animal struct {
	Name string
	age int
}

func main() {
	//log.SetFormatter(&log.JSONFormatter{})
	a := Animal{"dog", 22}
	log.SetFormatter(&log.TextFormatter{
		FullTimestamp:true})
	log.WithFields(log.Fields{
		"event": "ne",
		"topic": "title",
		"key": "my key",
	}).Info("hello", a)
	
	log.Error("hello world")
	for {
		time.Sleep(time.Second)
		log.Printf("i am ok %s", "dock")
	}
	log.Fatal("kill ")
}


猜你喜欢

转载自blog.csdn.net/wangjunsheng/article/details/80754156
今日推荐