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. 10
      handlers/handlers.go
  3. 2
      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'

10
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 util.GetConfig().EnableAccessLogs {
if util.GetConfig().EnableDebugMode {
// in debug mode, log everything including healthchecks
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false))
} else {
// if we are not in debug mode, do not log healthchecks // if we are not in debug mode, do not log healthchecks
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false, "/ok")) h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false, "/ok"))
} else { }
h.engine.Use(Ginrus(logrus.StandardLogger(), time.RFC3339, false))
} }
protected := h.engine.Group("/api/v1/protected") protected := h.engine.Group("/api/v1/protected")
if util.GetConfig().AuthBackend == "oauth" { if util.GetConfig().AuthBackend == "oauth" {

2
util/config.go

@ -23,6 +23,7 @@ type Configuration struct {
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"`
EnableAccessLogs bool `yaml:"EnableAccessLogs" env:"ENABLE_ACCESS_LOGS"`
EnableColorLogs bool `yaml:"EnableColorLogs" env:"ENABLE_COLOR_LOGS"` EnableColorLogs bool `yaml:"EnableColorLogs" env:"ENABLE_COLOR_LOGS"`
ShortedIDLength int `yaml:"ShortedIDLength" env:"SHORTED_ID_LENGTH"` ShortedIDLength int `yaml:"ShortedIDLength" env:"SHORTED_ID_LENGTH"`
Google oAuthConf `yaml:"Google" env:"GOOGLE"` Google oAuthConf `yaml:"Google" env:"GOOGLE"`
@ -49,6 +50,7 @@ var Config = Configuration{
DataDir: "data", DataDir: "data",
Backend: "boltdb", Backend: "boltdb",
EnableDebugMode: false, EnableDebugMode: false,
EnableAccessLogs: true,
EnableColorLogs: true, EnableColorLogs: true,
UseSSL: false, UseSSL: false,
ShortedIDLength: 4, ShortedIDLength: 4,

Loading…
Cancel
Save