Skip to content

Commit 7bfeeda

Browse files
committed
use new features of logr library
1 parent a92e7ad commit 7bfeeda

File tree

4 files changed

+6
-30
lines changed

4 files changed

+6
-30
lines changed

config/config.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/TwiN/gatus/v5/storage"
2525
"github.com/TwiN/logr"
2626
"gopkg.in/yaml.v3"
27-
"hermannm.dev/enumnames"
2827
)
2928

3029
const (
@@ -49,13 +48,6 @@ var (
4948

5049
// errEarlyReturn is returned to break out of a loop from a callback early
5150
errEarlyReturn = errors.New("early escape")
52-
53-
LogLevels = enumnames.NewMap(map[logr.Level]string{
54-
logr.LevelDebug: "DEBUG",
55-
logr.LevelInfo: "INFO",
56-
logr.LevelWarn: "WARN",
57-
logr.LevelError: "ERROR",
58-
})
5951
)
6052

6153
// Config is the main configuration structure
@@ -64,7 +56,7 @@ type Config struct {
6456
Debug bool `yaml:"debug,omitempty"`
6557

6658
// Log level: DEBUG, INFO, WARN, ERROR. Default: INFO
67-
LogLevel string `yaml:"log-level,omitempty"`
59+
LogLevel logr.Level `yaml:"log-level,omitempty"`
6860

6961
// Metrics Whether to expose metrics at /metrics
7062
Metrics bool `yaml:"metrics,omitempty"`
@@ -216,11 +208,6 @@ func LoadConfiguration(configPath string) (*Config, error) {
216208
}
217209
config.configPath = usedConfigPath
218210
config.UpdateLastFileModTime()
219-
220-
if config.LogLevel == "" {
221-
config.LogLevel = "INFO"
222-
}
223-
224211
return config, err
225212
}
226213

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/TwiN/g8/v2 v2.0.0
1111
github.com/TwiN/gocache/v2 v2.2.2
1212
github.com/TwiN/health v1.6.0
13-
github.com/TwiN/logr v0.0.2
13+
github.com/TwiN/logr v0.2.1
1414
github.com/TwiN/whois v1.1.9
1515
github.com/aws/aws-sdk-go v1.54.10
1616
github.com/coreos/go-oidc/v3 v3.10.0
@@ -31,7 +31,6 @@ require (
3131
gopkg.in/mail.v2 v2.3.1
3232
gopkg.in/yaml.v3 v3.0.1
3333
modernc.org/sqlite v1.33.1
34-
hermannm.dev/enumnames v0.2.1
3534
)
3635

3736
require (

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/TwiN/gocache/v2 v2.2.2 h1:4HToPfDV8FSbaYO5kkbhLpEllUYse5rAf+hVU/mSsuI
1616
github.com/TwiN/gocache/v2 v2.2.2/go.mod h1:WfIuwd7GR82/7EfQqEtmLFC3a2vqaKbs4Pe6neB7Gyc=
1717
github.com/TwiN/health v1.6.0 h1:L2ks575JhRgQqWWOfKjw9B0ec172hx7GdToqkYUycQM=
1818
github.com/TwiN/health v1.6.0/go.mod h1:Z6TszwQPMvtSiVx1QMidVRgvVr4KZGfiwqcD7/Z+3iw=
19-
github.com/TwiN/logr v0.0.2 h1:BGlNtfx8ni6zvylSsdB8xMv0PSTVBQf9LKtcfK24P2U=
20-
github.com/TwiN/logr v0.0.2/go.mod h1:oldDOkRjFXjZqiMP0+ca5NAQHXTiJ02zHirsuBJJH6k=
19+
github.com/TwiN/logr v0.2.1 h1:kMhUmBBVlFxzqTvyHuNoYQ/uwqg8BW4y0AyZxI5JB3Q=
20+
github.com/TwiN/logr v0.2.1/go.mod h1:oldDOkRjFXjZqiMP0+ca5NAQHXTiJ02zHirsuBJJH6k=
2121
github.com/TwiN/whois v1.1.9 h1:m20+m1CXnrstie+tW2ZmAJkfcT9zgwpVRUFsKeMw+ng=
2222
github.com/TwiN/whois v1.1.9/go.mod h1:TjipCMpJRAJYKmtz/rXQBU6UGxMh6bk8SHazu7OMnQE=
2323
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
@@ -327,8 +327,6 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
327327
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
328328
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
329329
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
330-
hermannm.dev/enumnames v0.2.1 h1:e9Qw5DlF5QVoxglnSPU2gjpHtmWUByqXrig97wZ14sU=
331-
hermannm.dev/enumnames v0.2.1/go.mod h1:Zlyt21mTyqMUcec/vMhxxSNUKkL7TVwskge2zaxOaEE=
332330
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
333331
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
334332
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ=

main.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,8 @@ func save() {
6262
}
6363

6464
func configureLogging(cfg *config.Config) {
65-
66-
if config.LogLevels.ContainsName(cfg.LogLevel) {
67-
log.Printf("[main.configureLogging] Log Level is %s", cfg.LogLevel)
68-
key, ok := config.LogLevels.GetKey(cfg.LogLevel)
69-
if ok {
70-
logr.SetThreshold(key)
71-
}
72-
} else {
73-
log.Printf("[main.configureLogging] Unrecognised log level '%s', defaulting to INFO. Allowed values are [DEBUG, INFO, WARN, ERROR]", cfg.LogLevel)
74-
}
65+
logr.SetThreshold(cfg.LogLevel)
66+
logr.Infof("[main.configureLogging] Log Level is %s", logr.GetThreshold())
7567
}
7668

7769
func loadConfiguration() (*config.Config, error) {

0 commit comments

Comments
 (0)