From 8c94d5e60ceea5539a1a77e2c85eaef195161753 Mon Sep 17 00:00:00 2001 From: Archit Bansal Date: Thu, 27 Aug 2020 17:07:56 -0700 Subject: [PATCH] Add logging levels to custom plugin logs. --- pkg/custompluginmonitor/custom_plugin_monitor.go | 2 +- pkg/custompluginmonitor/plugin/plugin.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/custompluginmonitor/custom_plugin_monitor.go b/pkg/custompluginmonitor/custom_plugin_monitor.go index 42353830..e47c1c05 100644 --- a/pkg/custompluginmonitor/custom_plugin_monitor.go +++ b/pkg/custompluginmonitor/custom_plugin_monitor.go @@ -271,7 +271,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat } // Log only if condition has changed if len(activeProblemEvents) != 0 || len(inactiveProblemEvents) != 0 { - glog.Infof("New status generated: %+v", status) + glog.V(0).Infof("New status generated: %+v", status) } return status } diff --git a/pkg/custompluginmonitor/plugin/plugin.go b/pkg/custompluginmonitor/plugin/plugin.go index 6738c2e8..24f4a18c 100644 --- a/pkg/custompluginmonitor/plugin/plugin.go +++ b/pkg/custompluginmonitor/plugin/plugin.go @@ -115,7 +115,6 @@ func (p *Plugin) runRules() { // Let the result be logged at a higher verbosity level. If there is a change in status it is logged later. glog.V(3).Infof("Add check result %+v for rule %+v", result, rule) - glog.Infof("Ran rule %+v", rule) }(rule) } @@ -219,12 +218,13 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp exitCode := cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() switch exitCode { case 0: + logPluginStderr(rule, string(stderr), 3) return cpmtypes.OK, output case 1: - logPluginStderr(rule.Path, string(stderr)) + logPluginStderr(rule, string(stderr), 0) return cpmtypes.NonOK, output default: - logPluginStderr(rule.Path, string(stderr)) + logPluginStderr(rule, string(stderr), 0) return cpmtypes.Unknown, output } } @@ -234,9 +234,9 @@ func (p *Plugin) Stop() { glog.Info("Stop plugin execution") } -func logPluginStderr(path, logs string) { +func logPluginStderr(rule cpmtypes.CustomRule, logs string, logLevel glog.Level) { if len(logs) != 0 { - glog.Infof("Start logs from plugin %q \n %s", path, string(logs)) - glog.Infof("End logs from plugin %q", path) + glog.V(logLevel).Infof("Start logs from plugin %+v \n %s", rule, logs) + glog.V(logLevel).Infof("End logs from plugin %+v", rule) } }