Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit 6dac9a7

Browse files
memorymxschmitt
authored andcommitted
Add option to disable access logging (#107)
For an internally-facing and/or test/qa deployment, web access logs may be a waste of stackdriver/cloudwatch quota. :)
1 parent 45a1287 commit 6dac9a7

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

build/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RedisHost: localhost:6379 # If using the redis backend, a host:port combination
55
RedisPassword: replace me # if using the redis backend, a conneciton password.
66
DataDir: ./data # Contains: the database and the private key
77
EnableDebugMode: true # Activates more detailed logging
8+
EnableAccessLogs: true # Enable GIN access logs (default is true; set to false to disable access logging)
89
EnableColorLogs: true # Enables/disables ANSI color sequences in log output; default is true
910
ShortedIDLength: 10 # Length of the random generated ID which is used for new shortened URLs
1011
AuthBackend: oauth # Can be 'oauth' or 'proxy'

handlers/handlers.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,15 @@ func (h *Handler) setHandlers() error {
134134
if err := h.addTemplatesFromFS([]string{"token.html", "protected.html"}); err != nil {
135135
return errors.Wrap(err, "could not add templates from FS")
136136
}
137-
if !util.GetConfig().EnableDebugMode {
138-
// if we are not in debug mode, do not log healthchecks
139-
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false, "/ok"))
140-
} else {
141-
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false))
137+
// only do web access logs if enabled
138+
if util.GetConfig().EnableAccessLogs {
139+
if util.GetConfig().EnableDebugMode {
140+
// in debug mode, log everything including healthchecks
141+
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false))
142+
} else {
143+
// if we are not in debug mode, do not log healthchecks
144+
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false, "/ok"))
145+
}
142146
}
143147
protected := h.engine.Group("/api/v1/protected")
144148
if util.GetConfig().AuthBackend == "oauth" {

util/config.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ import (
1414

1515
// Configuration are the available config values
1616
type Configuration struct {
17-
ListenAddr string `yaml:"ListenAddr" env:"LISTEN_ADDR"`
18-
BaseURL string `yaml:"BaseURL" env:"BASE_URL"`
19-
DataDir string `yaml:"DataDir" env:"DATA_DIR"`
20-
Backend string `yaml:"Backend" env:"BACKEND"`
21-
RedisHost string `yaml:"RedisHost" env:"REDIS_HOST"`
22-
RedisPassword string `yaml:"RedisPassword" env:"REDIS_PASSWORD"`
23-
AuthBackend string `yaml:"AuthBackend" env:"AUTH_BACKEND"`
24-
UseSSL bool `yaml:"EnableSSL" env:"USE_SSL"`
25-
EnableDebugMode bool `yaml:"EnableDebugMode" env:"ENABLE_DEBUG_MODE"`
26-
EnableColorLogs bool `yaml:"EnableColorLogs" env:"ENABLE_COLOR_LOGS"`
27-
ShortedIDLength int `yaml:"ShortedIDLength" env:"SHORTED_ID_LENGTH"`
28-
Google oAuthConf `yaml:"Google" env:"GOOGLE"`
29-
GitHub oAuthConf `yaml:"GitHub" env:"GITHUB"`
30-
Microsoft oAuthConf `yaml:"Microsoft" env:"MICROSOFT"`
31-
Proxy proxyAuthConf `yaml:"Proxy" env:"PROXY"`
17+
ListenAddr string `yaml:"ListenAddr" env:"LISTEN_ADDR"`
18+
BaseURL string `yaml:"BaseURL" env:"BASE_URL"`
19+
DataDir string `yaml:"DataDir" env:"DATA_DIR"`
20+
Backend string `yaml:"Backend" env:"BACKEND"`
21+
RedisHost string `yaml:"RedisHost" env:"REDIS_HOST"`
22+
RedisPassword string `yaml:"RedisPassword" env:"REDIS_PASSWORD"`
23+
AuthBackend string `yaml:"AuthBackend" env:"AUTH_BACKEND"`
24+
UseSSL bool `yaml:"EnableSSL" env:"USE_SSL"`
25+
EnableDebugMode bool `yaml:"EnableDebugMode" env:"ENABLE_DEBUG_MODE"`
26+
EnableAccessLogs bool `yaml:"EnableAccessLogs" env:"ENABLE_ACCESS_LOGS"`
27+
EnableColorLogs bool `yaml:"EnableColorLogs" env:"ENABLE_COLOR_LOGS"`
28+
ShortedIDLength int `yaml:"ShortedIDLength" env:"SHORTED_ID_LENGTH"`
29+
Google oAuthConf `yaml:"Google" env:"GOOGLE"`
30+
GitHub oAuthConf `yaml:"GitHub" env:"GITHUB"`
31+
Microsoft oAuthConf `yaml:"Microsoft" env:"MICROSOFT"`
32+
Proxy proxyAuthConf `yaml:"Proxy" env:"PROXY"`
3233
}
3334

3435
type oAuthConf struct {
@@ -44,15 +45,16 @@ type proxyAuthConf struct {
4445

4546
// config contains the default values
4647
var Config = Configuration{
47-
ListenAddr: ":8080",
48-
BaseURL: "http://localhost:3000",
49-
DataDir: "data",
50-
Backend: "boltdb",
51-
EnableDebugMode: false,
52-
EnableColorLogs: true,
53-
UseSSL: false,
54-
ShortedIDLength: 4,
55-
AuthBackend: "oauth",
48+
ListenAddr: ":8080",
49+
BaseURL: "http://localhost:3000",
50+
DataDir: "data",
51+
Backend: "boltdb",
52+
EnableDebugMode: false,
53+
EnableAccessLogs: true,
54+
EnableColorLogs: true,
55+
UseSSL: false,
56+
ShortedIDLength: 4,
57+
AuthBackend: "oauth",
5658
}
5759

5860
// ReadInConfig loads the Configuration and other needed folders for further usage

0 commit comments

Comments
 (0)