Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Ciena Corporation |
| 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 | package commands |
| 17 | |
| 18 | import ( |
| 19 | "context" |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 20 | "errors" |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 21 | "fmt" |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 22 | flags "github.com/jessevdk/go-flags" |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 23 | "github.com/opencord/voltctl/pkg/format" |
| 24 | "github.com/opencord/voltctl/pkg/model" |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 25 | "github.com/opencord/voltha-lib-go/v3/pkg/config" |
| 26 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
| 27 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 28 | "strings" |
| 29 | ) |
| 30 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 31 | const ( |
| 32 | defaultComponentName = "global" |
| 33 | defaultPackageName = "default" |
| 34 | ) |
| 35 | |
| 36 | // LogLevelOutput represents the output structure for the loglevel |
| 37 | type LogLevelOutput struct { |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 38 | ComponentName string |
| 39 | Status string |
| 40 | Error string |
| 41 | } |
| 42 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 43 | // SetLogLevelOpts represents the supported CLI arguments for the loglevel set command |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 44 | type SetLogLevelOpts struct { |
| 45 | OutputOptions |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 46 | Args struct { |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 47 | Level string |
| 48 | Component []string |
| 49 | } `positional-args:"yes" required:"yes"` |
| 50 | } |
| 51 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 52 | // ListLogLevelOpts represents the supported CLI arguments for the loglevel list command |
| 53 | type ListLogLevelsOpts struct { |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 54 | ListOutputOptions |
| 55 | Args struct { |
| 56 | Component []string |
| 57 | } `positional-args:"yes" required:"yes"` |
| 58 | } |
| 59 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 60 | // ClearLogLevelOpts represents the supported CLI arguments for the loglevel clear command |
| 61 | type ClearLogLevelsOpts struct { |
| 62 | OutputOptions |
| 63 | Args struct { |
| 64 | Component []string |
| 65 | } `positional-args:"yes" required:"yes"` |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 66 | } |
| 67 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 68 | // LogLevelOpts represents the loglevel commands |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 69 | type LogLevelOpts struct { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 70 | SetLogLevel SetLogLevelOpts `command:"set"` |
| 71 | ListLogLevels ListLogLevelsOpts `command:"list"` |
| 72 | ClearLogLevels ClearLogLevelsOpts `command:"clear"` |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | var logLevelOpts = LogLevelOpts{} |
| 76 | |
| 77 | const ( |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 78 | DEFAULT_LOGLEVELS_FORMAT = "table{{ .ComponentName }}\t{{.PackageName}}\t{{.Level}}" |
| 79 | DEFAULT_LOGLEVEL_RESULT_FORMAT = "table{{ .ComponentName }}\t{{.Status}}\t{{.Error}}" |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 80 | ) |
| 81 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 82 | // RegisterLogLevelCommands is used to register set,list and clear loglevel of components |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 83 | func RegisterLogLevelCommands(parent *flags.Parser) { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 84 | _, err := parent.AddCommand("loglevel", "loglevel commands", "list, set, clear log levels of components", &logLevelOpts) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 85 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 86 | Error.Fatalf("Unable to register log level commands with voltctl command parser: %s", err.Error()) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 90 | // processComponentListArgs stores the component name and package names given in command arguments to LogLevel |
| 91 | // It checks the given argument has # key or not, if # is present then split the argument for # then stores first part as component name |
| 92 | // and second part as package name |
| 93 | func processComponentListArgs(Components []string) ([]model.LogLevel, error) { |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 94 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 95 | var logLevelConfig []model.LogLevel |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 96 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 97 | if len(Components) == 0 { |
| 98 | Components = append(Components, defaultComponentName) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 99 | } |
| 100 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 101 | for _, component := range Components { |
| 102 | logConfig := model.LogLevel{} |
| 103 | val := strings.SplitN(component, "#", 2) |
divyadesai | 6e28d30 | 2020-03-16 08:39:16 +0000 | [diff] [blame] | 104 | |
| 105 | if strings.Contains(val[0], "/") { |
| 106 | return nil, errors.New("the component name '" + val[0] + "' contains an invalid character '/'") |
| 107 | } |
| 108 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 109 | if len(val) > 1 { |
| 110 | if val[0] == defaultComponentName { |
| 111 | return nil, errors.New("global level doesn't support packageName") |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 112 | } |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 113 | logConfig.ComponentName = val[0] |
| 114 | logConfig.PackageName = strings.ReplaceAll(val[1], "/", "#") |
| 115 | } else { |
| 116 | logConfig.ComponentName = component |
| 117 | logConfig.PackageName = defaultPackageName |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 118 | } |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 119 | logLevelConfig = append(logLevelConfig, logConfig) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 120 | } |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 121 | return logLevelConfig, nil |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 122 | } |
| 123 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 124 | // This method set loglevel for components. |
| 125 | // For example, using below command loglevel can be set for specific component with default packageName |
| 126 | // voltctl loglevel set level <componentName> |
| 127 | // For example, using below command loglevel can be set for specific component with specific packageName |
| 128 | // voltctl loglevel set level <componentName#packageName> |
| 129 | // For example, using below command loglevel can be set for more than one component for default package and other component for specific packageName |
| 130 | // voltctl loglevel set level <componentName1#packageName> <componentName2> |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 131 | func (options *SetLogLevelOpts) Execute(args []string) error { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 132 | var ( |
| 133 | logLevelConfig []model.LogLevel |
| 134 | err error |
| 135 | ) |
| 136 | ProcessGlobalOptions() |
| 137 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 138 | log.SetAllLogLevel(log.FatalLevel) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 139 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 140 | if options.Args.Level != "" { |
| 141 | if _, err := log.StringToLogLevel(options.Args.Level); err != nil { |
divyadesai | 6e28d30 | 2020-03-16 08:39:16 +0000 | [diff] [blame] | 142 | return fmt.Errorf("Unknown log level '%s'. Allowed values are DEBUG, INFO, WARN, ERROR, FATAL", options.Args.Level) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 146 | logLevelConfig, err = processComponentListArgs(options.Args.Component) |
| 147 | if err != nil { |
| 148 | return fmt.Errorf(err.Error()) |
| 149 | } |
| 150 | |
Rohan Agrawal | c558b1d | 2020-04-15 16:54:20 +0000 | [diff] [blame^] | 151 | client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()), log.FatalLevel) |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 152 | if err != nil { |
| 153 | return fmt.Errorf("Unable to create kvstore client %s", err) |
| 154 | } |
| 155 | defer client.Close() |
| 156 | |
| 157 | // Already error checked during option processing |
| 158 | host, port, _ := splitEndpoint(GlobalConfig.KvStore, defaultKvHost, defaultKvPort) |
| 159 | cm := config.NewConfigManager(client, supportedKvStoreType, host, port, int(GlobalConfig.KvStoreConfig.Timeout.Seconds())) |
| 160 | |
| 161 | var output []LogLevelOutput |
| 162 | |
| 163 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.KvStoreConfig.Timeout) |
| 164 | defer cancel() |
| 165 | |
| 166 | for _, lConfig := range logLevelConfig { |
| 167 | |
| 168 | logConfig := cm.InitComponentConfig(lConfig.ComponentName, config.ConfigTypeLogLevel) |
| 169 | err := logConfig.Save(ctx, lConfig.PackageName, strings.ToUpper(options.Args.Level)) |
| 170 | if err != nil { |
| 171 | output = append(output, LogLevelOutput{ComponentName: lConfig.ComponentName, Status: "Failure", Error: err.Error()}) |
| 172 | } else { |
| 173 | output = append(output, LogLevelOutput{ComponentName: lConfig.ComponentName, Status: "Success"}) |
| 174 | } |
| 175 | |
| 176 | } |
| 177 | |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 178 | outputFormat := CharReplacer.Replace(options.Format) |
| 179 | if outputFormat == "" { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 180 | outputFormat = GetCommandOptionWithDefault("loglevel-set", "format", DEFAULT_LOGLEVEL_RESULT_FORMAT) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 181 | } |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 182 | result := CommandResult{ |
| 183 | Format: format.Format(outputFormat), |
| 184 | OutputAs: toOutputType(options.OutputAs), |
| 185 | NameLimit: options.NameLimit, |
| 186 | Data: output, |
| 187 | } |
| 188 | |
| 189 | GenerateOutput(&result) |
| 190 | return nil |
| 191 | } |
| 192 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 193 | // This method list loglevel for components. |
| 194 | // For example, using below command loglevel can be list for specific component |
| 195 | // voltctl loglevel list <componentName> |
| 196 | // For example, using below command loglevel can be list for all the components with all the packageName |
| 197 | // voltctl loglevel list |
| 198 | func (options *ListLogLevelsOpts) Execute(args []string) error { |
| 199 | |
| 200 | var ( |
David K. Bainbridge | 4bbad14 | 2020-03-11 11:55:39 -0700 | [diff] [blame] | 201 | // Initialize to empty as opposed to nil so that -o json will |
| 202 | // display empty list and not null VOL-2742 |
| 203 | data []model.LogLevel = []model.LogLevel{} |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 204 | componentList []string |
| 205 | logLevelConfig map[string]string |
| 206 | err error |
| 207 | ) |
| 208 | ProcessGlobalOptions() |
| 209 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 210 | log.SetAllLogLevel(log.FatalLevel) |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 211 | |
Rohan Agrawal | c558b1d | 2020-04-15 16:54:20 +0000 | [diff] [blame^] | 212 | client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()), log.FatalLevel) |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 213 | if err != nil { |
| 214 | return fmt.Errorf("Unable to create kvstore client %s", err) |
| 215 | } |
| 216 | defer client.Close() |
| 217 | |
| 218 | // Already error checked during option processing |
| 219 | host, port, _ := splitEndpoint(GlobalConfig.KvStore, defaultKvHost, defaultKvPort) |
| 220 | cm := config.NewConfigManager(client, supportedKvStoreType, host, port, int(GlobalConfig.KvStoreConfig.Timeout.Seconds())) |
| 221 | |
| 222 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.KvStoreConfig.Timeout) |
| 223 | defer cancel() |
| 224 | |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 225 | if len(options.Args.Component) == 0 { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 226 | componentList, err = cm.RetrieveComponentList(ctx, config.ConfigTypeLogLevel) |
| 227 | if err != nil { |
| 228 | return fmt.Errorf("Unable to retrieve list of voltha components : %s ", err) |
| 229 | } |
| 230 | } else { |
| 231 | componentList = options.Args.Component |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 232 | } |
| 233 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 234 | for _, componentName := range componentList { |
| 235 | logConfig := cm.InitComponentConfig(componentName, config.ConfigTypeLogLevel) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 236 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 237 | logLevelConfig, err = logConfig.RetrieveAll(ctx) |
| 238 | if err != nil { |
| 239 | return fmt.Errorf("Unable to retrieve loglevel configuration for component %s : %s", componentName, err) |
| 240 | } |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 241 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 242 | for packageName, level := range logLevelConfig { |
| 243 | logLevel := model.LogLevel{} |
| 244 | if packageName == "" { |
| 245 | continue |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 246 | } |
| 247 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 248 | pName := strings.ReplaceAll(packageName, "#", "/") |
| 249 | logLevel.PopulateFrom(componentName, pName, level) |
| 250 | data = append(data, logLevel) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | outputFormat := CharReplacer.Replace(options.Format) |
| 255 | if outputFormat == "" { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 256 | outputFormat = GetCommandOptionWithDefault("loglevel-list", "format", DEFAULT_LOGLEVELS_FORMAT) |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 257 | } |
| 258 | orderBy := options.OrderBy |
| 259 | if orderBy == "" { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 260 | orderBy = GetCommandOptionWithDefault("loglevel-list", "order", "") |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | result := CommandResult{ |
| 264 | Format: format.Format(outputFormat), |
| 265 | Filter: options.Filter, |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 266 | OrderBy: orderBy, |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 267 | OutputAs: toOutputType(options.OutputAs), |
| 268 | NameLimit: options.NameLimit, |
| 269 | Data: data, |
| 270 | } |
| 271 | GenerateOutput(&result) |
| 272 | return nil |
| 273 | } |
| 274 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 275 | // This method clear loglevel for components. |
| 276 | // For example, using below command loglevel can be clear for specific component with default packageName |
| 277 | // voltctl loglevel clear <componentName> |
| 278 | // For example, using below command loglevel can be clear for specific component with specific packageName |
| 279 | // voltctl loglevel clear <componentName#packageName> |
| 280 | func (options *ClearLogLevelsOpts) Execute(args []string) error { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 281 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 282 | var ( |
| 283 | logLevelConfig []model.LogLevel |
| 284 | err error |
| 285 | ) |
| 286 | ProcessGlobalOptions() |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 287 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 288 | log.SetAllLogLevel(log.FatalLevel) |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 289 | |
| 290 | logLevelConfig, err = processComponentListArgs(options.Args.Component) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 291 | if err != nil { |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 292 | return fmt.Errorf("%s", err) |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Rohan Agrawal | c558b1d | 2020-04-15 16:54:20 +0000 | [diff] [blame^] | 295 | client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()), log.FatalLevel) |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 296 | if err != nil { |
| 297 | return fmt.Errorf("Unable to create kvstore client %s", err) |
| 298 | } |
| 299 | defer client.Close() |
| 300 | |
| 301 | // Already error checked during option processing |
| 302 | host, port, _ := splitEndpoint(GlobalConfig.KvStore, defaultKvHost, defaultKvPort) |
| 303 | cm := config.NewConfigManager(client, supportedKvStoreType, host, port, int(GlobalConfig.KvStoreConfig.Timeout.Seconds())) |
| 304 | |
| 305 | var output []LogLevelOutput |
| 306 | |
| 307 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.KvStoreConfig.Timeout) |
| 308 | defer cancel() |
| 309 | |
| 310 | for _, lConfig := range logLevelConfig { |
| 311 | |
divyadesai | 6e28d30 | 2020-03-16 08:39:16 +0000 | [diff] [blame] | 312 | if lConfig.ComponentName == defaultComponentName { |
| 313 | return fmt.Errorf("The global default loglevel cannot be cleared.") |
| 314 | } |
| 315 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 316 | logConfig := cm.InitComponentConfig(lConfig.ComponentName, config.ConfigTypeLogLevel) |
| 317 | |
| 318 | err := logConfig.Delete(ctx, lConfig.PackageName) |
| 319 | if err != nil { |
| 320 | output = append(output, LogLevelOutput{ComponentName: lConfig.ComponentName, Status: "Failure", Error: err.Error()}) |
| 321 | } else { |
| 322 | output = append(output, LogLevelOutput{ComponentName: lConfig.ComponentName, Status: "Success"}) |
| 323 | } |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 324 | } |
| 325 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 326 | outputFormat := CharReplacer.Replace(options.Format) |
| 327 | if outputFormat == "" { |
| 328 | outputFormat = GetCommandOptionWithDefault("loglevel-clear", "format", DEFAULT_LOGLEVEL_RESULT_FORMAT) |
| 329 | } |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 330 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 331 | result := CommandResult{ |
| 332 | Format: format.Format(outputFormat), |
| 333 | OutputAs: toOutputType(options.OutputAs), |
| 334 | NameLimit: options.NameLimit, |
| 335 | Data: output, |
| 336 | } |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 337 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 338 | GenerateOutput(&result) |
| 339 | return nil |
Scott Baker | d69e422 | 2019-08-21 16:46:05 -0700 | [diff] [blame] | 340 | } |