[SEBA-835] Dynamically configuring log levels
Change-Id: Id7bb2e870a9e83cdabd6116b05bcf284d83c37a3
diff --git a/internal/bbsimctl/commands/logging.go b/internal/bbsimctl/commands/logging.go
new file mode 100644
index 0000000..42e4771
--- /dev/null
+++ b/internal/bbsimctl/commands/logging.go
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package commands
+
+import (
+ "context"
+ "fmt"
+ "github.com/jessevdk/go-flags"
+ pb "github.com/opencord/bbsim/api/bbsim"
+ "github.com/opencord/bbsim/internal/bbsimctl/config"
+ log "github.com/sirupsen/logrus"
+ "google.golang.org/grpc"
+)
+
+type LoggingOptions struct {
+ Args struct {
+ Level string
+ Caller bool
+ } `positional-args:"yes" required:"yes"`
+}
+
+func RegisterLoggingCommands(parent *flags.Parser) {
+ parent.AddCommand("log", "set bbsim log level", "Commands to set the log level", &LoggingOptions{})
+}
+
+func (options *LoggingOptions) Execute(args []string) error {
+ conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
+
+ if err != nil {
+ log.Fatalf("did not connect: %v", err)
+ return nil
+ }
+ defer conn.Close()
+ c := pb.NewBBSimClient(conn)
+
+ // Contact the server and print out its response.
+
+ ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
+ defer cancel()
+
+ req := pb.LogLevel{
+ Level: options.Args.Level,
+ Caller: options.Args.Caller,
+ }
+
+ logLevel, err := c.SetLogLevel(ctx, &req)
+
+ fmt.Println("New log settings:")
+ fmt.Println(fmt.Sprintf("\tLevel: %s", logLevel.Level))
+ fmt.Println(fmt.Sprintf("\tReportCaller: %t", logLevel.Caller))
+
+ return nil
+}
diff --git a/internal/bbsimctl/commands/olt.go b/internal/bbsimctl/commands/olt.go
index 7f698f1..3a434b2 100644
--- a/internal/bbsimctl/commands/olt.go
+++ b/internal/bbsimctl/commands/olt.go
@@ -54,7 +54,7 @@
func getOLT() *pb.Olt {
conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
if err != nil {
- log.Fatal("did not connect: %v", err)
+ log.Fatalf("did not connect: %v", err)
return nil
}
defer conn.Close()
@@ -66,7 +66,7 @@
defer cancel()
olt, err := c.GetOlt(ctx, &pb.Empty{})
if err != nil {
- log.Fatal("could not get OLT: %v", err)
+ log.Fatalf("could not get OLT: %v", err)
return nil
}
return olt
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
index 6422f0a..2e8f887 100644
--- a/internal/bbsimctl/commands/onu.go
+++ b/internal/bbsimctl/commands/onu.go
@@ -42,7 +42,7 @@
conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
if err != nil {
- log.Fatal("did not connect: %v", err)
+ log.Fatalf("did not connect: %v", err)
return nil
}
defer conn.Close()
@@ -54,7 +54,7 @@
defer cancel()
onus, err := c.GetONUs(ctx, &pb.Empty{})
if err != nil {
- log.Fatal("could not get OLT: %v", err)
+ log.Fatalf("could not get OLT: %v", err)
return nil
}
return onus