Permalink
Browse files

add grpclion

Signed-off-by: Peter Edge <peter.edge@gmail.com>
  • Loading branch information...
peter-edge committed Mar 25, 2016
1 parent 5ce7fd4 commit 7db37edc2411c8ce17649c276621a9e0521867d5
Showing with 37 additions and 0 deletions.
  1. +2 −0 env/env.go
  2. +35 −0 grpc/grpclion.go
View
@@ -11,6 +11,7 @@ import (
"go.pedge.io/env"
"go.pedge.io/lion"
"go.pedge.io/lion/current"
"go.pedge.io/lion/grpc"
"go.pedge.io/lion/syslog"
)
@@ -85,6 +86,7 @@ func SetupEnv(env Env) error {
lion.SetLogger(lion.NewLogger(lion.NewMultiPusher(pushers...)))
}
lion.RedirectStdLogger()
grpclion.RedirectGrpclog()
if env.LogLevel != "" {
level, err := lion.NameToLevel(strings.ToUpper(env.LogLevel))
if err != nil {
View
@@ -0,0 +1,35 @@
/*
Package grpclion provides a logger for grpclog.
*/
package grpclion // import "go.pedge.io/lion/grpc"
import (
"go.pedge.io/lion"
"google.golang.org/grpc/grpclog"
)
// RedirectGrpclog will redirect grpclog to lion.
func RedirectGrpclog() {
lion.AddGlobalHook(
func(l lion.Logger) {
grpclog.SetLogger(NewLogger(l))
},
)
}
// NewLogger returns a new grpclog.Logger for the BaseLogger.
func NewLogger(baseLogger lion.BaseLogger) grpclog.Logger {
return &logger{baseLogger}
}
type logger struct {
lion.BaseLogger
}
func (l *logger) Fatal(args ...interface{}) {
l.BaseLogger.Fatalln(args...)
}
func (l *logger) Print(args ...interface{}) {
l.BaseLogger.Println(args...)
}

0 comments on commit 7db37ed

Please sign in to comment.