blob: 42e47716785fe8a36ee5d5c152b6b77cc7d29577 [file] [log] [blame]
Matteo Scandolo2bf742a2019-10-01 11:33:34 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package commands
18
19import (
20 "context"
21 "fmt"
22 "github.com/jessevdk/go-flags"
23 pb "github.com/opencord/bbsim/api/bbsim"
24 "github.com/opencord/bbsim/internal/bbsimctl/config"
25 log "github.com/sirupsen/logrus"
26 "google.golang.org/grpc"
27)
28
29type LoggingOptions struct {
30 Args struct {
31 Level string
32 Caller bool
33 } `positional-args:"yes" required:"yes"`
34}
35
36func RegisterLoggingCommands(parent *flags.Parser) {
37 parent.AddCommand("log", "set bbsim log level", "Commands to set the log level", &LoggingOptions{})
38}
39
40func (options *LoggingOptions) Execute(args []string) error {
41 conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
42
43 if err != nil {
44 log.Fatalf("did not connect: %v", err)
45 return nil
46 }
47 defer conn.Close()
48 c := pb.NewBBSimClient(conn)
49
50 // Contact the server and print out its response.
51
52 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
53 defer cancel()
54
55 req := pb.LogLevel{
56 Level: options.Args.Level,
57 Caller: options.Args.Caller,
58 }
59
60 logLevel, err := c.SetLogLevel(ctx, &req)
61
62 fmt.Println("New log settings:")
63 fmt.Println(fmt.Sprintf("\tLevel: %s", logLevel.Level))
64 fmt.Println(fmt.Sprintf("\tReportCaller: %t", logLevel.Caller))
65
66 return nil
67}