Skip to content

Commit

Permalink
Print info message and error for log set
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
  • Loading branch information
ondrej-fabry committed Sep 3, 2019
1 parent 1e759e5 commit 4a26f1d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cmd/agentctl/commands/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package commands

import (
"encoding/json"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -133,11 +134,27 @@ A CLI tool to connect to vppagent and set vppagent logger type.
}

func RunLogSet(cli *AgentCli, opts LogSetOptions) error {
resp, err := cli.PUT("/log/"+opts.Logger+"/"+opts.Level, nil)
data, err := cli.PUT("/log/"+opts.Logger+"/"+opts.Level, nil)
if err != nil {
return fmt.Errorf("HTTP PUT request failed: %v", err)
}

logging.Debugf("response: %s\n", resp)
type response struct {
Logger string `json:"logger,omitempty"`
Level string `json:"level,omitempty"`
Error string `json:"Error,omitempty"`
}
var resp response
if err := json.Unmarshal(data, &resp); err != nil {
return err
}
logging.Debugf("response: %+v\n", resp)

if resp.Error != "" {
return fmt.Errorf("SERVER: %s", resp.Error)
}

fmt.Fprintf(os.Stdout, "logger %s has been set to level %s\n", resp.Logger, resp.Level)

return nil
}

0 comments on commit 4a26f1d

Please sign in to comment.