~xenrox/twitch-bot

702ad7fafe104c9bb9e8a31680f47b2745737803 — Thorben Günther 8 months ago 863ac53
Add option for setting the logging format
2 files changed, 10 insertions(+), 1 deletions(-)

M config.go
M main.go
M config.go => config.go +9 -0
@@ 13,6 13,7 @@ type config struct {
	DBConnectionString string
	FaceitAPIKey       string
	LogLevel           string
	LogFormat          string
}

type channel struct {


@@ 60,6 61,7 @@ func readConfig(path string) (*config, error) {
	}

	config.LogLevel = "info"
	config.LogFormat = "text"
	d = cfg.Get("log-level")
	if d != nil {
		if err := d.ParseParams(&config.LogLevel); err != nil {


@@ 67,6 69,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
		}
	}

	channels := make(map[string]channel)
	for _, channelDir := range cfg.GetAll("channel") {
		var name string

M main.go => main.go +1 -1
@@ 29,7 29,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()))