From 393d82f955cf432fb41871275566e16fc7992e3e Mon Sep 17 00:00:00 2001 From: Steve Shaw Date: Wed, 21 Oct 2020 13:25:38 -0400 Subject: Adding gRPC support for modified logging level Signed-off-by: Steve Shaw --- pkg/server/grpc_server.go | 4 ++++ pkg/server/server.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'pkg') diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index a9f621fb..25c8495e 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -1772,3 +1772,7 @@ func (s *server) StopBgp(ctx context.Context, r *api.StopBgpRequest) (*empty.Emp func (s *server) GetTable(ctx context.Context, r *api.GetTableRequest) (*api.GetTableResponse, error) { return s.bgpServer.GetTable(ctx, r) } + +func (s *server) SetLogLevel(ctx context.Context, r *api.SetLogLevelRequest) (*empty.Empty, error) { + return &empty.Empty{}, s.bgpServer.SetLogLevel(ctx, r) +} diff --git a/pkg/server/server.go b/pkg/server/server.go index ee58585f..5971bc6d 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -3796,6 +3796,22 @@ func (s *BgpServer) MonitorPeer(ctx context.Context, r *api.MonitorPeerRequest, return nil } +func (s *BgpServer) SetLogLevel(ctx context.Context, r *api.SetLogLevelRequest) error { + prevLevel := log.GetLevel() + newLevel := log.Level(r.Level) + if prevLevel == newLevel { + log.WithFields(log.Fields{ + "Topic": "Config", + }).Infof("Logging level unchanged -- level already set to %v", newLevel) + } else { + log.SetLevel(newLevel) + log.WithFields(log.Fields{ + "Topic": "Config", + }).Infof("Logging level changed -- prev: %v, new: %v", prevLevel, newLevel) + } + return nil +} + type watchEventType string const ( -- cgit v1.2.3