mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 08:50:46 +00:00
Added setting for LogLevel
This commit is contained in:
@@ -26,7 +26,8 @@ func ParseFlags() ServerConfig {
|
||||
disableAuthentication := flag.Bool("DisableAuth", false, "Disable authentication")
|
||||
disableTls := flag.Bool("DisableTls", false, "Disable TLS, serve over HTTP")
|
||||
persistDataPath := flag.String("Persist", "", "Saves data to given path on application exit")
|
||||
debug := flag.Bool("Debug", false, "Runs application in debug mode, this provides additional logging")
|
||||
logLevel := NewEnumValue("info", []string{"debug", "info", "error", "silent"})
|
||||
flag.Var(logLevel, "LogLevel", fmt.Sprintf("Sets the logging level %s", logLevel.AllowedValuesList()))
|
||||
|
||||
flag.Parse()
|
||||
setFlagsFromEnvironment()
|
||||
@@ -41,8 +42,8 @@ func ParseFlags() ServerConfig {
|
||||
config.PersistDataFilePath = *persistDataPath
|
||||
config.DisableAuth = *disableAuthentication
|
||||
config.DisableTls = *disableTls
|
||||
config.Debug = *debug
|
||||
config.AccountKey = *accountKey
|
||||
config.LogLevel = logLevel.value
|
||||
|
||||
config.PopulateCalculatedFields()
|
||||
|
||||
@@ -54,7 +55,19 @@ func (c *ServerConfig) PopulateCalculatedFields() {
|
||||
c.DatabaseDomain = c.Host
|
||||
c.DatabaseEndpoint = fmt.Sprintf("https://%s:%d/", c.Host, c.Port)
|
||||
c.ExplorerBaseUrlLocation = ExplorerBaseUrlLocation
|
||||
logger.EnableDebugOutput = c.Debug
|
||||
|
||||
switch c.LogLevel {
|
||||
case "debug":
|
||||
logger.LogLevel = logger.LogLevelDebug
|
||||
case "info":
|
||||
logger.LogLevel = logger.LogLevelInfo
|
||||
case "error":
|
||||
logger.LogLevel = logger.LogLevelError
|
||||
case "silent":
|
||||
logger.LogLevel = logger.LogLevelSilent
|
||||
default:
|
||||
logger.LogLevel = logger.LogLevelInfo
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ServerConfig) ApplyDefaultsToEmptyFields() {
|
||||
|
||||
36
api/config/enumFlag.go
Normal file
36
api/config/enumFlag.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type EnumValue struct {
|
||||
allowedValues []string
|
||||
value string
|
||||
}
|
||||
|
||||
func (e *EnumValue) String() string {
|
||||
return e.value
|
||||
}
|
||||
|
||||
func (e *EnumValue) Set(v string) error {
|
||||
for _, allowed := range e.allowedValues {
|
||||
if v == allowed {
|
||||
e.value = v
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("invalid value %q, must be one of: %s", v, strings.Join(e.allowedValues, ", "))
|
||||
}
|
||||
|
||||
func NewEnumValue(defaultValue string, allowedValues []string) *EnumValue {
|
||||
return &EnumValue{
|
||||
allowedValues: allowedValues,
|
||||
value: defaultValue,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EnumValue) AllowedValuesList() string {
|
||||
return fmt.Sprintf("(one of: %s)", strings.Join(e.allowedValues, ", "))
|
||||
}
|
||||
@@ -15,6 +15,6 @@ type ServerConfig struct {
|
||||
PersistDataFilePath string `json:"persistDataFilePath"`
|
||||
DisableAuth bool `json:"disableAuth"`
|
||||
DisableTls bool `json:"disableTls"`
|
||||
Debug bool `json:"debug"`
|
||||
LogLevel string `json:"logLevel"`
|
||||
ExplorerBaseUrlLocation string `json:"explorerBaseUrlLocation"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user