Skip to content

Commit 8270bd8

Browse files
committed
feat: optionally log /healthcheck, fixes #55
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 2c11ae0 commit 8270bd8

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

config.yaml.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ logging:
88
# This can also be set via the LOGGING_LEVEL environment variable
99
level: info
1010

11+
# Health checks
12+
#
13+
# This can also be set via the LOGGING_HEALTHCHECKS environment variable
14+
healthchecks: false
15+
1116
api:
1217
# Listen address for the API
1318
#

internal/api/api.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,21 @@ func Start(cfg *config.Config) error {
4343
router := gin.New()
4444
// Catch panics and return a 500
4545
router.Use(gin.Recovery())
46+
// Standard logging
47+
logger := logging.GetLogger()
4648
// Access logging
4749
accessLogger := logging.GetAccessLogger()
50+
skipPaths := []string{}
51+
if cfg.Logging.Healthchecks {
52+
skipPaths = append(skipPaths, "/healthcheck")
53+
logger.Infof("disabling access logs for /healthcheck")
54+
}
4855
router.Use(ginzap.GinzapWithConfig(accessLogger, &ginzap.Config{
4956
TimeFormat: time.RFC3339,
5057
UTC: true,
51-
SkipPaths: []string{"/healthcheck"},
58+
SkipPaths: skipPaths,
5259
}))
5360
router.Use(ginzap.RecoveryWithZap(accessLogger, true))
54-
// Standard logging
55-
logger := logging.GetLogger()
5661

5762
// Create a healthcheck (before metrics so it's not instrumented)
5863
router.GET("/healthcheck", handleHealthcheck)

internal/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type Config struct {
1818
}
1919

2020
type LoggingConfig struct {
21-
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
21+
Healthchecks bool `yaml:"healthchecks" envconfig:"LOGGING_HEALTHCHECKS"`
22+
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
2223
}
2324

2425
type ApiConfig struct {
@@ -47,7 +48,8 @@ type NodeConfig struct {
4748
// Singleton config instance with default values
4849
var globalConfig = &Config{
4950
Logging: LoggingConfig{
50-
Level: "info",
51+
Level: "info",
52+
Healthchecks: false,
5153
},
5254
Api: ApiConfig{
5355
ListenAddress: "",

0 commit comments

Comments
 (0)