From d62f4ceeb629abe7dc2664094f0de3f9a4a27762 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Thu, 6 May 2021 12:12:18 +0300 Subject: [PATCH] Added log level to config --- src/config/config.go.example | 1 + src/config/types.go | 2 ++ src/logging/logging.go | 2 ++ src/website/landing.go | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/config/config.go.example b/src/config/config.go.example index 7808b059..a0047446 100644 --- a/src/config/config.go.example +++ b/src/config/config.go.example @@ -4,6 +4,7 @@ var Config = HMNConfig{ Env: Dev, Addr: ":9001", BaseUrl: "http://handmade.local:9001", + LogLevel: zerolog.TraceLevel, Postgres: PostgresConfig{ User: "hmn", Password: "password", diff --git a/src/config/types.go b/src/config/types.go index f6443f9e..6e9563c6 100644 --- a/src/config/types.go +++ b/src/config/types.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/jackc/pgx/v4" + "github.com/rs/zerolog" ) type Environment string @@ -18,6 +19,7 @@ type HMNConfig struct { Env Environment Addr string BaseUrl string + LogLevel zerolog.Level Postgres PostgresConfig Auth AuthConfig } diff --git a/src/logging/logging.go b/src/logging/logging.go index 719db4a5..3561b43b 100644 --- a/src/logging/logging.go +++ b/src/logging/logging.go @@ -8,6 +8,7 @@ import ( "strings" color "git.handmade.network/hmn/hmn/src/ansicolor" + "git.handmade.network/hmn/hmn/src/config" "git.handmade.network/hmn/hmn/src/oops" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -16,6 +17,7 @@ import ( func init() { zerolog.ErrorStackMarshaler = oops.ZerologStackMarshaler log.Logger = log.Output(NewPrettyZerologWriter()) + zerolog.SetGlobalLevel(config.Config.LogLevel) } func GlobalLogger() *zerolog.Logger { diff --git a/src/website/landing.go b/src/website/landing.go index 3cc59235..98e508af 100644 --- a/src/website/landing.go +++ b/src/website/landing.go @@ -62,7 +62,7 @@ func Index(c *RequestContext) ResponseData { allProjects := iterProjects.ToSlice() c.Perf.EndBlock() - c.Logger.Info().Interface("allProjects", allProjects).Msg("all the projects") + c.Logger.Debug().Interface("allProjects", allProjects).Msg("all the projects") categoryUrls := GetAllCategoryUrls(c.Context(), c.Conn)