blob: 7e17c568b8d4a62f2573f3ab7242baa459348e07 [file] [log] [blame]
Serge Bazanski6c8ee0b2023-04-05 12:29:57 +02001package logtree
2
Serge Bazanski3c5d0632024-09-12 10:49:12 +00003import (
4 "google.golang.org/grpc/grpclog"
5
6 "source.monogon.dev/go/logging"
7)
Serge Bazanski6c8ee0b2023-04-05 12:29:57 +02008
9// GRPCify turns a LeveledLogger into a go-grpc compatible logger.
Serge Bazanski3c5d0632024-09-12 10:49:12 +000010func GRPCify(logger logging.Leveled) grpclog.LoggerV2 {
Serge Bazanski6c8ee0b2023-04-05 12:29:57 +020011 lp, ok := logger.(*leveledPublisher)
12 if !ok {
13 // Fail fast, as this is a programming error.
14 panic("Expected *leveledPublisher in LeveledLogger from supervisor")
15 }
16
17 lp2 := *lp
18 lp2.depth += 1
19
20 return &leveledGRPCV2{
21 lp: &lp2,
22 }
23}
24
25type leveledGRPCV2 struct {
26 lp *leveledPublisher
27}
28
29func (g *leveledGRPCV2) Info(args ...interface{}) {
30 g.lp.Info(args...)
31}
32
33func (g *leveledGRPCV2) Infoln(args ...interface{}) {
34 g.lp.Info(args...)
35}
36
37func (g *leveledGRPCV2) Infof(format string, args ...interface{}) {
38 g.lp.Infof(format, args...)
39}
40
41func (g *leveledGRPCV2) Warning(args ...interface{}) {
42 g.lp.Warning(args...)
43}
44
45func (g *leveledGRPCV2) Warningln(args ...interface{}) {
46 g.lp.Warning(args...)
47}
48
49func (g *leveledGRPCV2) Warningf(format string, args ...interface{}) {
50 g.lp.Warningf(format, args...)
51}
52
53func (g *leveledGRPCV2) Error(args ...interface{}) {
54 g.lp.Error(args...)
55}
56
57func (g *leveledGRPCV2) Errorln(args ...interface{}) {
58 g.lp.Error(args...)
59}
60
61func (g *leveledGRPCV2) Errorf(format string, args ...interface{}) {
62 g.lp.Errorf(format, args...)
63}
64
65func (g *leveledGRPCV2) Fatal(args ...interface{}) {
66 g.lp.Fatal(args...)
67}
68
69func (g *leveledGRPCV2) Fatalln(args ...interface{}) {
70 g.lp.Fatal(args...)
71}
72
73func (g *leveledGRPCV2) Fatalf(format string, args ...interface{}) {
74 g.lp.Fatalf(format, args...)
75}
76
77func (g *leveledGRPCV2) V(l int) bool {
Serge Bazanski3c5d0632024-09-12 10:49:12 +000078 return g.lp.V(logging.VerbosityLevel(l)).Enabled()
Serge Bazanski6c8ee0b2023-04-05 12:29:57 +020079}