Skip to content

Commit bb8d249

Browse files
authored
allow users to disable health check logging (#251)
1 parent ca54790 commit bb8d249

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

config/config.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ level = info
1717
output = stdout
1818
format = json
1919
request_logging = true
20+
log_health_checks = true
2021
2122
[server]
2223
base_path = /
@@ -36,10 +37,11 @@ type appConfig struct {
3637
}
3738

3839
type loggingConfig struct {
39-
Level string `mapstructure:"level"`
40-
Output string `mapstructure:"output"`
41-
Format string `mapstructure:"format"`
42-
RequestLogging bool `mapstructure:"request_logging"`
40+
Level string `mapstructure:"level"`
41+
Output string `mapstructure:"output"`
42+
Format string `mapstructure:"format"`
43+
RequestLogging bool `mapstructure:"request_logging"`
44+
LogHealthChecks bool `mapstructure:"log_health_checks"`
4345
}
4446

4547
type serverConfig struct {

defaults.ini

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ destination = stdout
2020
# Log all web requests (not just errors)
2121
request_logging = true
2222

23+
# Log requests to the health check endpoint (/api/health). Has no effect unless request_logging is enabled
24+
log_health_checks = true
25+
2326
[server]
2427
# To serve from a sub path (e.g. in a reverse proxy configuration), specify the sub path here.
2528
# If accessed without the sub path, chefbrowser will redirect the user to the sub path.

internal/app/app.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ func New(cfg *config.Config) {
4141
engine.Debug = true
4242
}
4343

44+
cfg.Server.BasePath = normalizeBasePath(cfg.Server.BasePath)
45+
4446
engine.Pre(middleware.RemoveTrailingSlashWithConfig(middleware.TrailingSlashConfig{
4547
RedirectCode: http.StatusMovedPermanently,
4648
}))
4749

4850
engine.Use(middleware.Recover())
4951

5052
if cfg.Logging.RequestLogging {
51-
// todo: replace with our own logger
52-
engine.Use(middleware.Logger())
53+
logger.Debug("request logging is enabled")
54+
logCfg := middleware.DefaultLoggerConfig
55+
if !cfg.Logging.LogHealthChecks {
56+
logger.Debug("log_health_checks = false; requests to health check endpoint will not be logged")
57+
logCfg.Skipper = func(c echo.Context) bool {
58+
return c.Path() == cfg.Server.BasePath+"/api/health"
59+
}
60+
}
61+
engine.Use(middleware.LoggerWithConfig(logCfg))
5362
}
5463

5564
if cfg.Server.EnableGzip {
@@ -74,8 +83,6 @@ func New(cfg *config.Config) {
7483

7584
chefService := chef.New(cfg, logger)
7685

77-
cfg.Server.BasePath = normalizeBasePath(cfg.Server.BasePath)
78-
7986
app := AppService{
8087
Log: logger,
8188
Chef: chefService,

0 commit comments

Comments
 (0)