Browse Source

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. :)
dependabot/npm_and_yarn/web/prismjs-1.21.0
memory 8 years ago
committed by Max Schmitt
parent
commit
6dac9a7fcb
  1. 1
      build/config.yaml
  2. 14
      handlers/handlers.go
  3. 50
      util/config.go

1
build/config.yaml

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

14
handlers/handlers.go

@ -134,11 +134,15 @@ func (h *Handler) setHandlers() error {
if err := h.addTemplatesFromFS([]string{"token.html", "protected.html"}); err != nil { if err := h.addTemplatesFromFS([]string{"token.html", "protected.html"}); err != nil {
return errors.Wrap(err, "could not add templates from FS") return errors.Wrap(err, "could not add templates from FS")
} }
if !util.GetConfig().EnableDebugMode { // only do web access logs if enabled
// if we are not in debug mode, do not log healthchecks if util.GetConfig().EnableAccessLogs {
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false, "/ok")) if util.GetConfig().EnableDebugMode {
} else { // in debug mode, log everything including healthchecks
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false)) h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false))
} else {
// if we are not in debug mode, do not log healthchecks
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false, "/ok"))
}
} }
protected := h.engine.Group("/api/v1/protected") protected := h.engine.Group("/api/v1/protected")
if util.GetConfig().AuthBackend == "oauth" { if util.GetConfig().AuthBackend == "oauth" {

50
util/config.go

@ -14,21 +14,22 @@ import (
// Configuration are the available config values // Configuration are the available config values
type Configuration struct { type Configuration struct {
ListenAddr string `yaml:"ListenAddr" env:"LISTEN_ADDR"` ListenAddr string `yaml:"ListenAddr" env:"LISTEN_ADDR"`
BaseURL string `yaml:"BaseURL" env:"BASE_URL"` BaseURL string `yaml:"BaseURL" env:"BASE_URL"`
DataDir string `yaml:"DataDir" env:"DATA_DIR"` DataDir string `yaml:"DataDir" env:"DATA_DIR"`
Backend string `yaml:"Backend" env:"BACKEND"` Backend string `yaml:"Backend" env:"BACKEND"`
RedisHost string `yaml:"RedisHost" env:"REDIS_HOST"` RedisHost string `yaml:"RedisHost" env:"REDIS_HOST"`
RedisPassword string `yaml:"RedisPassword" env:"REDIS_PASSWORD"` RedisPassword string `yaml:"RedisPassword" env:"REDIS_PASSWORD"`
AuthBackend string `yaml:"AuthBackend" env:"AUTH_BACKEND"` AuthBackend string `yaml:"AuthBackend" env:"AUTH_BACKEND"`
UseSSL bool `yaml:"EnableSSL" env:"USE_SSL"` UseSSL bool `yaml:"EnableSSL" env:"USE_SSL"`
EnableDebugMode bool `yaml:"EnableDebugMode" env:"ENABLE_DEBUG_MODE"` EnableDebugMode bool `yaml:"EnableDebugMode" env:"ENABLE_DEBUG_MODE"`
EnableColorLogs bool `yaml:"EnableColorLogs" env:"ENABLE_COLOR_LOGS"` EnableAccessLogs bool `yaml:"EnableAccessLogs" env:"ENABLE_ACCESS_LOGS"`
ShortedIDLength int `yaml:"ShortedIDLength" env:"SHORTED_ID_LENGTH"` EnableColorLogs bool `yaml:"EnableColorLogs" env:"ENABLE_COLOR_LOGS"`
Google oAuthConf `yaml:"Google" env:"GOOGLE"` ShortedIDLength int `yaml:"ShortedIDLength" env:"SHORTED_ID_LENGTH"`
GitHub oAuthConf `yaml:"GitHub" env:"GITHUB"` Google oAuthConf `yaml:"Google" env:"GOOGLE"`
Microsoft oAuthConf `yaml:"Microsoft" env:"MICROSOFT"` GitHub oAuthConf `yaml:"GitHub" env:"GITHUB"`
Proxy proxyAuthConf `yaml:"Proxy" env:"PROXY"` Microsoft oAuthConf `yaml:"Microsoft" env:"MICROSOFT"`
Proxy proxyAuthConf `yaml:"Proxy" env:"PROXY"`
} }
type oAuthConf struct { type oAuthConf struct {
@ -44,15 +45,16 @@ type proxyAuthConf struct {
// config contains the default values // config contains the default values
var Config = Configuration{ var Config = Configuration{
ListenAddr: ":8080", ListenAddr: ":8080",
BaseURL: "http://localhost:3000", BaseURL: "http://localhost:3000",
DataDir: "data", DataDir: "data",
Backend: "boltdb", Backend: "boltdb",
EnableDebugMode: false, EnableDebugMode: false,
EnableColorLogs: true, EnableAccessLogs: true,
UseSSL: false, EnableColorLogs: true,
ShortedIDLength: 4, UseSSL: false,
AuthBackend: "oauth", ShortedIDLength: 4,
AuthBackend: "oauth",
} }
// ReadInConfig loads the Configuration and other needed folders for further usage // ReadInConfig loads the Configuration and other needed folders for further usage

Loading…
Cancel
Save