File tree 3 files changed +20
-8
lines changed
3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ level = info
17
17
output = stdout
18
18
format = json
19
19
request_logging = true
20
+ log_health_checks = true
20
21
21
22
[server]
22
23
base_path = /
@@ -36,10 +37,11 @@ type appConfig struct {
36
37
}
37
38
38
39
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"`
43
45
}
44
46
45
47
type serverConfig struct {
Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ destination = stdout
20
20
# Log all web requests (not just errors)
21
21
request_logging = true
22
22
23
+ # Log requests to the health check endpoint (/api/health). Has no effect unless request_logging is enabled
24
+ log_health_checks = true
25
+
23
26
[server]
24
27
# To serve from a sub path (e.g. in a reverse proxy configuration), specify the sub path here.
25
28
# If accessed without the sub path, chefbrowser will redirect the user to the sub path.
Original file line number Diff line number Diff line change @@ -41,15 +41,24 @@ func New(cfg *config.Config) {
41
41
engine .Debug = true
42
42
}
43
43
44
+ cfg .Server .BasePath = normalizeBasePath (cfg .Server .BasePath )
45
+
44
46
engine .Pre (middleware .RemoveTrailingSlashWithConfig (middleware.TrailingSlashConfig {
45
47
RedirectCode : http .StatusMovedPermanently ,
46
48
}))
47
49
48
50
engine .Use (middleware .Recover ())
49
51
50
52
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 ))
53
62
}
54
63
55
64
if cfg .Server .EnableGzip {
@@ -74,8 +83,6 @@ func New(cfg *config.Config) {
74
83
75
84
chefService := chef .New (cfg , logger )
76
85
77
- cfg .Server .BasePath = normalizeBasePath (cfg .Server .BasePath )
78
-
79
86
app := AppService {
80
87
Log : logger ,
81
88
Chef : chefService ,
You can’t perform that action at this time.
0 commit comments