mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 01:57:02 +00:00
Make log level configurable
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/robfig/goconfig/config"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SmtpConfig houses the SMTP server configuration - not using pointers
|
||||
@@ -52,6 +53,7 @@ func LoadConfig(filename string) error {
|
||||
messages := list.New()
|
||||
|
||||
// Validate sections
|
||||
requireSection(messages, "logging")
|
||||
requireSection(messages, "smtp")
|
||||
requireSection(messages, "web")
|
||||
requireSection(messages, "datastore")
|
||||
@@ -64,6 +66,7 @@ func LoadConfig(filename string) error {
|
||||
}
|
||||
|
||||
// Validate options
|
||||
requireOption(messages, "logging", "level")
|
||||
requireOption(messages, "smtp", "ip4.address")
|
||||
requireOption(messages, "smtp", "ip4.port")
|
||||
requireOption(messages, "smtp", "domain")
|
||||
@@ -91,6 +94,21 @@ func LoadConfig(filename string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// parseLoggingConfig trying to catch config errors early
|
||||
func parseLoggingConfig() error {
|
||||
option := "[logging]level"
|
||||
str, err := Config.String("logging", "level")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to parse %v: %v", option, err)
|
||||
}
|
||||
switch strings.ToUpper(str) {
|
||||
case "TRACE", "INFO", "WARN", "ERROR":
|
||||
default:
|
||||
return fmt.Errorf("Invalid value provided for %v: %v", option, str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseSmtpConfig trying to catch config errors early
|
||||
func parseSmtpConfig() error {
|
||||
smtpConfig = new(SmtpConfig)
|
||||
|
||||
Reference in New Issue
Block a user