Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
feat: add log configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphg6 committed Jun 7, 2024
1 parent fe996a2 commit d15f9cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Config struct {
ResourceLoaderHeaders http.Header
ResourceLoaderHeadersStr string `mapstructure:"FEATWS_RULLER_RESOURCE_LOADER_HEADERS"`

LogLevel string `mapstructure:"FEATWS_RULLER_LOG_LEVEL"`

Port string `mapstructure:"PORT"`
DefaultRules string `mapstructure:"FEATWS_RULLER_DEFAULT_RULES"`
DisableSSLVerify bool `mapstructure:"FEATWS_DISABLE_SSL_VERIFY"`
Expand All @@ -58,8 +60,8 @@ func LoadConfig() (err error) {

viper.AutomaticEnv()

viper.SetDefault("FEATWS_RULLER_LOG_LEVEL", "INFO")
viper.SetDefault("FEATWS_RULLER_RESOURCE_LOADER_TYPE", "http")
viper.SetDefault("FEATWS_RULLER_RESOURCE_LOADER_URL", "")
viper.SetDefault("FEATWS_RULLER_RESOURCE_LOADER_HEADERS", "")
viper.SetDefault("FEATWS_RULLER_RESOLVER_BRIDGE_URL", "")
viper.SetDefault("FEATWS_RULLER_RESOLVER_BRIDGE_HEADERS", "")
Expand Down
22 changes: 12 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"os"

"github.com/bancodobrasil/featws-ruller/config"
_ "github.com/bancodobrasil/featws-ruller/docs"
Expand All @@ -17,13 +16,16 @@ import (
ginlogrus "github.com/toorop/gin-logrus"
)

func setupLog() {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
// log.SetFormatter(&log.JSONFormatter{})

log.SetOutput(os.Stdout)

log.SetLevel(log.DebugLevel)
func setupLog(config *config.Config) {
level := log.InfoLevel
if len(config.LogLevel) > 0 {
log.Infof("Configuring log level: %s", config.LogLevel)
parsedLevel, err := log.ParseLevel(config.LogLevel)
if err == nil {
level = parsedLevel
}
}
log.SetLevel(level)
}

// @title FeatWS Ruler
Expand Down Expand Up @@ -70,15 +72,15 @@ func setupLog() {
// configuration.
func main() {

setupLog()

err := config.LoadConfig()
if err != nil {
log.Fatalf("Não foi possível carregar as configurações: %s\n", err)
}

cfg := config.GetConfig()

setupLog(cfg)

if cfg.DefaultRules != "" {
defaultGRL := cfg.DefaultRules
log.Debugf("Carregando '%s' como folha de regras default!", defaultGRL)
Expand Down

0 comments on commit d15f9cb

Please sign in to comment.