From 8c66a24513ccac47122d8d5765bcd6b9aca7eea5 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sun, 1 Apr 2018 20:50:18 -0700 Subject: [PATCH] config: lowercase log levels for #90 --- Dockerfile | 2 +- cmd/inbucket/main.go | 13 ++++++------- doc/config.md | 10 +++++----- etc/dev-start.sh | 4 ++-- etc/linux/inbucket.service | 2 +- pkg/config/config.go | 4 +++- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index b716802..739a2c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ FROM golang:1.10-alpine # Configuration ENV INBUCKET_SRC $GOPATH/src/github.com/jhillyerd/inbucket ENV INBUCKET_HOME /opt/inbucket -ENV INBUCKET_SMTP_DOMAINNOSTORE bitbucket.local +ENV INBUCKET_SMTP_DISCARDDOMAINS bitbucket.local ENV INBUCKET_SMTP_TIMEOUT 30s ENV INBUCKET_POP3_TIMEOUT 30s ENV INBUCKET_WEB_UIDIR $INBUCKET_HOME/ui diff --git a/cmd/inbucket/main.go b/cmd/inbucket/main.go index 87c03cd..ba5f236 100644 --- a/cmd/inbucket/main.go +++ b/cmd/inbucket/main.go @@ -11,7 +11,6 @@ import ( "os" "os/signal" "runtime" - "strings" "syscall" "time" @@ -168,17 +167,17 @@ signalLoop: // openLog configures zerolog output, returns func to close logfile. func openLog(level string, logfile string, json bool) (close func(), err error) { - switch strings.ToUpper(level) { - case "DEBUG": + switch level { + case "debug": zerolog.SetGlobalLevel(zerolog.DebugLevel) - case "INFO": + case "info": zerolog.SetGlobalLevel(zerolog.InfoLevel) - case "WARN": + case "warn": zerolog.SetGlobalLevel(zerolog.WarnLevel) - case "ERROR": + case "error": zerolog.SetGlobalLevel(zerolog.ErrorLevel) default: - return nil, fmt.Errorf("Log level %q not one of: DEBUG, INFO, WARN, ERROR", level) + return nil, fmt.Errorf("Log level %q not one of: debug, info, warn, error", level) } close = func() {} var w io.Writer diff --git a/doc/config.md b/doc/config.md index cab55fc..d0a64fb 100644 --- a/doc/config.md +++ b/doc/config.md @@ -8,7 +8,7 @@ Running `inbucket -help` will yield a condensed summary of the environment variables it supports: KEY DEFAULT DESCRIPTION - INBUCKET_LOGLEVEL INFO DEBUG, INFO, WARN, or ERROR + INBUCKET_LOGLEVEL info debug, info, warn, or error INBUCKET_SMTP_ADDR 0.0.0.0:2500 SMTP server IP4 host:port INBUCKET_SMTP_DOMAIN inbucket HELO domain INBUCKET_SMTP_MAXRECIPIENTS 200 Maximum RCPT TO per message @@ -47,11 +47,11 @@ The following documentation will describe each of these in more detail. `INBUCKET_LOGLEVEL` This setting controls the verbosity of log output. A small desktop installation -should probably select INFO, but a busy shared installation would be better off -with WARN or ERROR. +should probably select `info`, but a busy shared installation would be better +off with `warn` or `error`. -- Default: `INFO` -- Values: one of `DEBUG`, `INFO`, `WARN`, or `ERROR` +- Default: `info` +- Values: one of `debug`, `info`, `warn`, or `error` ## SMTP diff --git a/etc/dev-start.sh b/etc/dev-start.sh index 82b5cc9..a35db19 100755 --- a/etc/dev-start.sh +++ b/etc/dev-start.sh @@ -2,8 +2,8 @@ # dev-start.sh # description: Developer friendly Inbucket configuration -export INBUCKET_LOGLEVEL="DEBUG" -export INBUCKET_SMTP_DOMAINNOSTORE="bitbucket.local" +export INBUCKET_LOGLEVEL="debug" +export INBUCKET_SMTP_DISCARDDOMAINS="bitbucket.local" export INBUCKET_WEB_TEMPLATECACHE="false" export INBUCKET_WEB_COOKIEAUTHKEY="not-secret" export INBUCKET_STORAGE_TYPE="file" diff --git a/etc/linux/inbucket.service b/etc/linux/inbucket.service index 00ed9dc..a919eb9 100644 --- a/etc/linux/inbucket.service +++ b/etc/linux/inbucket.service @@ -8,7 +8,7 @@ User=daemon Group=daemon PermissionsStartOnly=true -Environment=INBUCKET_LOGLEVEL=WARN +Environment=INBUCKET_LOGLEVEL=warn Environment=INBUCKET_SMTP_ADDR=0.0.0.0:2500 Environment=INBUCKET_POP3_ADDR=0.0.0.0:1100 Environment=INBUCKET_WEB_ADDR=0.0.0.0:9000 diff --git a/pkg/config/config.go b/pkg/config/config.go index 1bb6057..e1c77e9 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -3,6 +3,7 @@ package config import ( "log" "os" + "strings" "text/tabwriter" "time" @@ -30,7 +31,7 @@ var ( // Root wraps all other configurations. type Root struct { - LogLevel string `required:"true" default:"INFO" desc:"DEBUG, INFO, WARN, or ERROR"` + LogLevel string `required:"true" default:"info" desc:"debug, info, warn, or error"` SMTP SMTP POP3 POP3 Web Web @@ -86,6 +87,7 @@ type Storage struct { func Process() (*Root, error) { c := &Root{} err := envconfig.Process(prefix, c) + c.LogLevel = strings.ToLower(c.LogLevel) stringutil.SliceToLower(c.SMTP.AcceptDomains) stringutil.SliceToLower(c.SMTP.RejectDomains) stringutil.SliceToLower(c.SMTP.StoreDomains)