github.com/cilium/cilium@v1.16.2/pkg/bgpv1/gobgp/logger.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package gobgp 5 6 import ( 7 gobgpLog "github.com/osrg/gobgp/v3/pkg/log" 8 "github.com/sirupsen/logrus" 9 ) 10 11 // implement github.com/osrg/gobgp/v3/pkg/log/Logger interface 12 type ServerLogger struct { 13 l *logrus.Logger 14 asn uint32 15 component string 16 subsys string 17 } 18 19 type LogParams struct { 20 AS uint32 21 Component string 22 SubSys string 23 } 24 25 func NewServerLogger(l *logrus.Logger, params LogParams) *ServerLogger { 26 return &ServerLogger{ 27 l: l, 28 asn: params.AS, 29 component: params.Component, 30 subsys: params.SubSys, 31 } 32 } 33 34 func (l *ServerLogger) Panic(msg string, fields gobgpLog.Fields) { 35 fields["asn"] = l.asn 36 fields["component"] = l.component 37 fields["subsys"] = l.subsys 38 l.l.WithFields(logrus.Fields(fields)).Panic(msg) 39 } 40 41 func (l *ServerLogger) Fatal(msg string, fields gobgpLog.Fields) { 42 fields["asn"] = l.asn 43 fields["component"] = l.component 44 fields["subsys"] = l.subsys 45 l.l.WithFields(logrus.Fields(fields)).Fatal(msg) 46 } 47 48 func (l *ServerLogger) Error(msg string, fields gobgpLog.Fields) { 49 fields["asn"] = l.asn 50 fields["component"] = l.component 51 fields["subsys"] = l.subsys 52 l.l.WithFields(logrus.Fields(fields)).Error(msg) 53 } 54 55 func (l *ServerLogger) Warn(msg string, fields gobgpLog.Fields) { 56 fields["asn"] = l.asn 57 fields["component"] = l.component 58 fields["subsys"] = l.subsys 59 l.l.WithFields(logrus.Fields(fields)).Warn(msg) 60 } 61 62 func (l *ServerLogger) Info(msg string, fields gobgpLog.Fields) { 63 fields["asn"] = l.asn 64 fields["component"] = l.component 65 fields["subsys"] = l.subsys 66 l.l.WithFields(logrus.Fields(fields)).Info(msg) 67 } 68 69 func (l *ServerLogger) Debug(msg string, fields gobgpLog.Fields) { 70 fields["asn"] = l.asn 71 fields["component"] = l.component 72 fields["subsys"] = l.subsys 73 l.l.WithFields(logrus.Fields(fields)).Debug(msg) 74 } 75 76 func (l *ServerLogger) SetLevel(level gobgpLog.LogLevel) { 77 l.l.SetLevel(logrus.Level(level)) 78 } 79 80 func (l *ServerLogger) GetLevel() gobgpLog.LogLevel { 81 return gobgpLog.LogLevel(l.l.GetLevel()) 82 }