Skip to content

Commit 377c7f6

Browse files
Merge pull request #72 from zhuje/OU-525-excess-logs
OU-525: Reduce excess logs
2 parents 4b0e220 + 7097a03 commit 377c7f6

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,7 @@ overwriting default console styles, breaking the layout of existing pages. The
195195
best practice is to prefix your CSS classnames with your plugin name to avoid
196196
conflicts. Please don't disable these rules without understanding how they can
197197
break console styles!
198+
199+
### Local Development Troubleshooting
200+
1. Disable cache. Select 'disable cache' in your browser's DevTools > Network > 'disable cache'. Or use private/incognito mode in your browser.
201+
2. Enable higher log verbosity by setting `-log-level=trace` when starting the plugin backend. For more options to set log level see [logrus documentation](https://github.com/sirupsen/logrus?tab=readme-ov-file#level-logging).

cmd/plugin-backend.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
staticPathArg = flag.String("static-path", "", "static files path to serve frontend (default: './web/dist')")
1919
configPathArg = flag.String("config-path", "", "config files path (default: './config')")
2020
pluginConfigArg = flag.String("plugin-config-path", "", "plugin yaml configuration")
21+
logLevelArg = flag.String("log-level", "error", "verbosity of logs\noptions: ['panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace']\n'trace' level will log all incoming requests\n(default 'error')")
2122
log = logrus.WithField("module", "main")
2223
)
2324

@@ -31,7 +32,7 @@ func main() {
3132
staticPath := mergeEnvValue("TROUBLESHOOTING_PANEL_CONSOLE_PLUGIN_STATIC_PATH", *staticPathArg, "opt/app-root/web/dist")
3233
configPath := mergeEnvValue("TROUBLESHOOTING_PANEL_CONSOLE_PLUGIN_MANIFEST_CONFIG_PATH", *configPathArg, "opt/app-root/web/dist")
3334
pluginConfigPath := mergeEnvValue("TROUBLESHOOTING_PANEL_CONSOLE_PLUGIN_CONFIG_PATH", *pluginConfigArg, "/etc/plugin/config.yaml")
34-
35+
logLevel := mergeEnvValue("TROUBLESHOOTING_PANEL_CONSOLE_PLUGIN_LOG_LEVEL", *logLevelArg, "error")
3536
featuresList := strings.Fields(strings.Join(strings.Split(strings.ToLower(features), ","), " "))
3637

3738
featuresSet := make(map[string]bool)
@@ -49,6 +50,7 @@ func main() {
4950
StaticPath: staticPath,
5051
ConfigPath: configPath,
5152
PluginConfigPath: pluginConfigPath,
53+
LogLevel: logLevel,
5254
})
5355
}
5456

pkg/server.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Config struct {
2525
StaticPath string
2626
ConfigPath string
2727
PluginConfigPath string
28+
LogLevel string
2829
}
2930

3031
type PluginConfig struct {
@@ -46,8 +47,6 @@ func Start(cfg *Config) {
4647
router, pluginConfig := setupRoutes(cfg)
4748
router.Use(corsHeaderMiddleware())
4849

49-
loggedRouter := handlers.LoggingHandler(log.Logger.Out, router)
50-
5150
tlsConfig := &tls.Config{
5251
MinVersion: tls.VersionTLS12,
5352
}
@@ -57,19 +56,32 @@ func Start(cfg *Config) {
5756
timeout = pluginConfig.Timeout
5857
}
5958

59+
logrusLevel, err := logrus.ParseLevel(cfg.LogLevel)
60+
if err != nil {
61+
logrus.WithError(err).Fatal("unable to set the log level")
62+
logrusLevel = logrus.ErrorLevel
63+
}
64+
6065
httpServer := &http.Server{
61-
Handler: loggedRouter,
66+
Handler: router,
6267
Addr: fmt.Sprintf(":%d", cfg.Port),
6368
TLSConfig: tlsConfig,
6469
ReadTimeout: timeout,
6570
WriteTimeout: timeout,
6671
}
6772

73+
if logrusLevel == logrus.TraceLevel {
74+
loggedRouter := handlers.LoggingHandler(log.Logger.Out, router)
75+
httpServer.Handler = loggedRouter
76+
}
77+
6878
if cfg.CertFile != "" && cfg.PrivateKeyFile != "" {
6979
log.Infof("listening on https://:%d", cfg.Port)
80+
logrus.SetLevel(logrusLevel)
7081
panic(httpServer.ListenAndServeTLS(cfg.CertFile, cfg.PrivateKeyFile))
7182
} else {
7283
log.Infof("listening on http://:%d", cfg.Port)
84+
logrus.SetLevel(logrusLevel)
7385
panic(httpServer.ListenAndServe())
7486
}
7587
}

0 commit comments

Comments
 (0)