M config/config.go => config/config.go +9 -0
@@ 11,6 11,7 @@ type Config struct {
HTTPAddress string
DBConnectionString string
LogLevel string
+ LogFormat string
EnablePlayground bool
Admins []string
Maps []string
@@ 26,6 27,7 @@ func ReadConfig(path string) (*Config, error) {
// Set default values
config.HTTPAddress = "127.0.0.1:8080"
config.LogLevel = "info"
+ config.LogFormat = "text"
config.EnablePlayground = false
d := cfg.Get("http-address")
@@ 50,6 52,13 @@ func ReadConfig(path string) (*Config, error) {
}
}
+ d = cfg.Get("log-format")
+ if d != nil {
+ if err := d.ParseParams(&config.LogFormat); err != nil {
+ return nil, err
+ }
+ }
+
d = cfg.Get("enable-playground")
if d != nil {
var enablePlayground string
M server.go => server.go +1 -1
@@ 33,7 33,7 @@ func main() {
os.Exit(1)
}
- logger, err := logging.New(cfg.LogLevel, "text", os.Stderr)
+ logger, err := logging.New(cfg.LogLevel, cfg.LogFormat, os.Stderr)
if err != nil {
slog.Error("Failed to create logger",
slog.String("error", err.Error()))