forked from brocaar/chirpstack-application-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (50 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//go:generate go-bindata -prefix ../../migrations/ -pkg migrations -o ../../internal/migrations/migrations_gen.go ../../migrations/
//go:generate go-bindata -prefix ../../static/ -pkg static -o ../../internal/static/static_gen.go ../../static/...
package main
import (
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/grpclog"
"github.com/brocaar/lora-app-server/cmd/lora-app-server/cmd"
)
// grpcLogger implements a wrapper around the logrus Logger to make it
// compatible with the grpc LoggerV2. It seems that V is not (always)
// called, therefore the Info* methods are overridden as we want to
// log these as debug info.
type grpcLogger struct {
*log.Logger
}
func (gl *grpcLogger) V(l int) bool {
level, ok := map[log.Level]int{
log.DebugLevel: 0,
log.InfoLevel: 1,
log.WarnLevel: 2,
log.ErrorLevel: 3,
log.FatalLevel: 4,
}[log.GetLevel()]
if !ok {
return false
}
return l >= level
}
func (gl *grpcLogger) Info(args ...interface{}) {
if log.GetLevel() == log.DebugLevel {
log.Debug(args...)
}
}
func (gl *grpcLogger) Infoln(args ...interface{}) {
if log.GetLevel() == log.DebugLevel {
log.Debug(args...)
}
}
func (gl *grpcLogger) Infof(format string, args ...interface{}) {
if log.GetLevel() == log.DebugLevel {
log.Debugf(format, args...)
}
}
func init() {
grpclog.SetLoggerV2(&grpcLogger{log.StandardLogger()})
}
var version string // set by the compiler
func main() {
cmd.Execute(version)
}