Skip to content

Commit f57d3e9

Browse files
committed
Migrate logging to promlog
Signed-off-by: rustyclock <rustyclock@protonmail.com>
1 parent 0b34d68 commit f57d3e9

File tree

7 files changed

+64
-80
lines changed

7 files changed

+64
-80
lines changed

cmd/main.go

+26-27
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ import (
1818
"encoding/json"
1919
"fmt"
2020
"net/http"
21+
"os"
2122
"time"
2223

24+
"github.com/go-kit/kit/log"
25+
"github.com/go-kit/kit/log/level"
2326
"github.com/prometheus-community/json_exporter/config"
2427
"github.com/prometheus-community/json_exporter/internal"
2528
"github.com/prometheus/client_golang/prometheus"
2629
"github.com/prometheus/client_golang/prometheus/promhttp"
27-
log "github.com/sirupsen/logrus"
30+
"github.com/prometheus/common/promlog"
31+
"github.com/prometheus/common/version"
2832
"github.com/urfave/cli"
2933
)
3034

@@ -47,7 +51,6 @@ func MakeApp() *cli.App {
4751

4852
app := cli.NewApp()
4953
app.Name = "json_exporter"
50-
app.Version = internal.Version
5154
app.Usage = "A prometheus exporter for scraping metrics from JSON REST API endpoints"
5255
app.UsageText = "[OPTIONS] CONFIG_PATH"
5356
app.Action = main
@@ -57,30 +60,36 @@ func MakeApp() *cli.App {
5760
}
5861

5962
func main(c *cli.Context) {
60-
setupLogging(c.String("log-level"))
6163

62-
internal.Init(c)
64+
promlogConfig := &promlog.Config{}
65+
logger := promlog.New(promlogConfig)
66+
67+
level.Info(logger).Log("msg", "Starting json_exporter", "version", version.Info())
68+
level.Info(logger).Log("msg", "Build context", "build", version.BuildContext())
69+
70+
internal.Init(logger, c)
6371

6472
config, err := config.LoadConfig(c.Args()[0])
6573
if err != nil {
66-
log.Fatal(err)
74+
level.Error(logger).Log("msg", "Error loading config", "err", err)
75+
os.Exit(1)
6776
}
68-
configJson, err := json.MarshalIndent(config, "", "\t")
77+
configJson, err := json.Marshal(config)
6978
if err != nil {
70-
log.Errorf("Failed to marshal loaded config to JSON. ERROR: '%s'", err)
79+
level.Error(logger).Log("msg", "Failed to marshal config to JOSN", "err", err)
7180
}
72-
log.Infof("Config:\n%s", string(configJson))
81+
level.Info(logger).Log("msg", "Loaded config file", "config", configJson)
7382

7483
http.Handle("/metrics", promhttp.Handler())
7584
http.HandleFunc("/probe", func(w http.ResponseWriter, req *http.Request) {
76-
probeHandler(w, req, config)
85+
probeHandler(w, req, logger, config)
7786
})
7887
if err := http.ListenAndServe(fmt.Sprintf(":%d", c.Int("port")), nil); err != nil {
79-
log.Fatal(err)
88+
level.Error(logger).Log("msg", "failed to start the server", "err", err)
8089
}
8190
}
8291

83-
func probeHandler(w http.ResponseWriter, r *http.Request, config config.Config) {
92+
func probeHandler(w http.ResponseWriter, r *http.Request, logger log.Logger, config config.Config) {
8493

8594
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(config.Global.TimeoutSeconds*float64(time.Second)))
8695
defer cancel()
@@ -90,7 +99,7 @@ func probeHandler(w http.ResponseWriter, r *http.Request, config config.Config)
9099

91100
metrics, err := internal.CreateMetricsList(registry, config)
92101
if err != nil {
93-
log.Fatalf("Failed to create metrics from config. Error: %s", err)
102+
level.Error(logger).Log("msg", "Failed to create metrics list from config", "err", err)
94103
}
95104

96105
probeSuccessGauge := prometheus.NewGauge(prometheus.GaugeOpts{
@@ -112,31 +121,21 @@ func probeHandler(w http.ResponseWriter, r *http.Request, config config.Config)
112121
registry.MustRegister(probeSuccessGauge)
113122
registry.MustRegister(probeDurationGauge)
114123

115-
data, err := internal.FetchJson(ctx, target, config.Headers)
124+
data, err := internal.FetchJson(ctx, logger, target, config.Headers)
116125
if err != nil {
117-
log.Error(err)
126+
level.Error(logger).Log("msg", "Failed to fetch JSON response", "err", err)
118127
duration := time.Since(start).Seconds()
119-
log.Errorf("Probe failed. duration_seconds: %f", duration)
128+
level.Error(logger).Log("msg", "Probe failed", "duration_seconds", duration)
120129
} else {
121-
internal.Scrape(metrics, data)
130+
internal.Scrape(logger, metrics, data)
122131

123132
duration := time.Since(start).Seconds()
124133
probeDurationGauge.Set(duration)
125134
probeSuccessGauge.Set(1)
135+
//level.Info(logger).Log("msg", "Probe succeeded", "duration_seconds", duration) // Too noisy
126136
}
127137

128138
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
129139
h.ServeHTTP(w, r)
130140

131141
}
132-
133-
func setupLogging(level string) {
134-
log.SetFormatter(&log.TextFormatter{
135-
FullTimestamp: true,
136-
})
137-
logLevel, err := log.ParseLevel(level)
138-
if err != nil {
139-
log.Fatalf("could not set log level to '%s';err:<%s>", level, err)
140-
}
141-
log.SetLevel(logLevel)
142-
}

config/config.go

-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ package config
1616
import (
1717
"io/ioutil"
1818

19-
log "github.com/sirupsen/logrus"
20-
2119
"gopkg.in/yaml.v2"
2220
)
2321

@@ -61,12 +59,10 @@ func LoadConfig(configPath string) (Config, error) {
6159
var config Config
6260
data, err := ioutil.ReadFile(configPath)
6361
if err != nil {
64-
log.Errorf("Failed to load config: %s, Error: %s", configPath, err)
6562
return config, err
6663
}
6764

6865
if err := yaml.Unmarshal(data, &config); err != nil {
69-
log.Errorf("Failed to parse YAML: %s", err)
7066
return config, err
7167
}
7268

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ go 1.14
44

55
require (
66
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
7+
github.com/go-kit/kit v0.9.0
78
github.com/kawamuray/jsonpath v0.0.0-20160208140654-5c448ebf9735
89
github.com/prometheus/client_golang v1.7.1
910
github.com/prometheus/common v0.10.0
10-
github.com/sirupsen/logrus v1.6.0
1111
github.com/urfave/cli v1.22.4
1212
gopkg.in/yaml.v2 v2.3.0
1313
)

go.sum

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
22
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
34
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
45
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
6+
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
57
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
68
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
79
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
@@ -16,9 +18,12 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
1618
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1719
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1820
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
21+
github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk=
1922
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
2023
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
24+
github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA=
2125
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
26+
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
2227
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
2328
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
2429
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -42,8 +47,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
4247
github.com/kawamuray/jsonpath v0.0.0-20160208140654-5c448ebf9735 h1:AozUZseulD50o1Vxj5KYleqpyN4/9hlrCBEYqOC9SZc=
4348
github.com/kawamuray/jsonpath v0.0.0-20160208140654-5c448ebf9735/go.mod h1:dz00yqWNWlKa9ff7RJzpnHPAPUazsid3yhVzXcsok94=
4449
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
45-
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
46-
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
50+
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
4751
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
4852
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
4953
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -58,6 +62,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
5862
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
5963
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
6064
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
65+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
6166
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
6267
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6368
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -82,8 +87,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I
8287
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
8388
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
8489
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
85-
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
86-
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
8790
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8891
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8992
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@@ -116,6 +119,7 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
116119
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
117120
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
118121
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
122+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
119123
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
120124
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
121125
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=

internal/collector.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import (
2020
"net/http"
2121
"strconv"
2222

23+
"github.com/go-kit/kit/log"
24+
"github.com/go-kit/kit/log/level"
2325
"github.com/kawamuray/jsonpath" // Originally: "github.com/NickSardo/jsonpath"
2426
"github.com/prometheus/client_golang/prometheus"
25-
log "github.com/sirupsen/logrus"
2627
)
2728

2829
type JsonGaugeCollector struct {
@@ -32,42 +33,42 @@ type JsonGaugeCollector struct {
3233
LabelsJsonPath map[string]string
3334
}
3435

35-
func Scrape(collectors []JsonGaugeCollector, json []byte) {
36+
func Scrape(logger log.Logger, collectors []JsonGaugeCollector, json []byte) {
3637

3738
for _, collector := range collectors {
3839
if collector.ValueJsonPath == "" { // ScrapeType is 'value'
3940

4041
// Since this is a 'value' type metric, there should be exactly one element in results
4142
// If there are more, just return the first one
4243
// TODO: Better handling/logging for this scenario
43-
floatValue, err := extractValue(json, collector.KeyJsonPath)
44+
floatValue, err := extractValue(logger, json, collector.KeyJsonPath)
4445
if err != nil {
45-
log.Error(err)
46+
level.Error(logger).Log("msg", "Failed to extract float value for metric", "path", collector.KeyJsonPath, "err", err)
4647
continue
4748
}
4849

49-
collector.With(extractLabels(json, collector.LabelsJsonPath)).Set(floatValue)
50+
collector.With(extractLabels(logger, json, collector.LabelsJsonPath)).Set(floatValue)
5051
} else { // ScrapeType is 'object'
5152
path, err := compilePath(collector.KeyJsonPath)
5253
if err != nil {
53-
log.Errorf("Failed to compile path: '%s', ERROR: '%s'", collector.KeyJsonPath, err)
54+
level.Error(logger).Log("msg", "Failed to compile path", "path", collector.KeyJsonPath, "err", err)
5455
continue
5556
}
5657

5758
eval, err := jsonpath.EvalPathsInBytes(json, []*jsonpath.Path{path})
5859
if err != nil {
59-
log.Errorf("Failed to create evaluator for JSON Path: %s, ERROR: '%s'", collector.KeyJsonPath, err)
60+
level.Error(logger).Log("msg", "Failed to create evaluator for json path", "path", collector.KeyJsonPath, "err", err)
6061
continue
6162
}
6263
for {
6364
if result, ok := eval.Next(); ok {
64-
floatValue, err := extractValue(result.Value, collector.ValueJsonPath)
65+
floatValue, err := extractValue(logger, result.Value, collector.ValueJsonPath)
6566
if err != nil {
66-
log.Error(err)
67+
level.Error(logger).Log("msg", "Failed to extract value", "path", collector.ValueJsonPath, "err", err)
6768
continue
6869
}
6970

70-
collector.With(extractLabels(result.Value, collector.LabelsJsonPath)).Set(floatValue)
71+
collector.With(extractLabels(logger, result.Value, collector.LabelsJsonPath)).Set(floatValue)
7172
} else {
7273
break
7374
}
@@ -91,7 +92,7 @@ func compilePath(path string) (*jsonpath.Path, error) {
9192
}
9293

9394
// Returns the first matching float value at the given json path
94-
func extractValue(json []byte, path string) (float64, error) {
95+
func extractValue(logger log.Logger, json []byte, path string) (float64, error) {
9596
var floatValue = -1.0
9697
var result *jsonpath.Result
9798
var err error
@@ -117,15 +118,15 @@ func extractValue(json []byte, path string) (float64, error) {
117118
if eval.Error != nil {
118119
return floatValue, fmt.Errorf("Failed to evaluate json. ERROR: '%s', PATH: '%s', JSON: '%s'", eval.Error, path, string(json))
119120
} else {
120-
log.Debugf("Could not find path. PATH: '%s', JSON: '%s'", path, string(json))
121+
level.Debug(logger).Log("msg", "Path not found", "path", path, "json", string(json))
121122
return floatValue, fmt.Errorf("Could not find path. PATH: '%s'", path)
122123
}
123124
}
124125

125126
return SanitizeValue(result)
126127
}
127128

128-
func extractLabels(json []byte, l map[string]string) map[string]string {
129+
func extractLabels(logger log.Logger, json []byte, l map[string]string) map[string]string {
129130
labels := make(map[string]string)
130131
for label, path := range l {
131132

@@ -138,25 +139,25 @@ func extractLabels(json []byte, l map[string]string) map[string]string {
138139
// Dynamic value
139140
p, err := compilePath(path)
140141
if err != nil {
141-
log.Errorf("Failed to compile path for label: '%s', PATH: '%s', ERROR: '%s'", label, path, err)
142+
level.Error(logger).Log("msg", "Failed to compile path for label", "path", path, "label", label, "err", err)
142143
labels[label] = ""
143144
continue
144145
}
145146

146147
eval, err := jsonpath.EvalPathsInBytes(json, []*jsonpath.Path{p})
147148
if err != nil {
148-
log.Errorf("Failed to create evaluator for JSON Path: %s, ERROR: '%s'", path, err)
149+
level.Error(logger).Log("msg", "Failed to create evaluator for json", "path", path, "err", err)
149150
labels[label] = ""
150151
continue
151152
}
152153

153154
result, ok := eval.Next()
154155
if result == nil || !ok {
155156
if eval.Error != nil {
156-
log.Errorf("Failed to evaluate json for label: '%s', ERROR: '%s', PATH: '%s', JSON: '%s'", label, eval.Error, path, string(json))
157+
level.Error(logger).Log("msg", "Failed to evaluate", "label", label, "json", string(json), "err", eval.Error)
157158
} else {
158-
log.Debugf("Could not find path in json for label: '%s', PATH: '%s', JSON: '%s'", label, path, string(json))
159-
log.Warnf("Could not find path in json for label: '%s', PATH: '%s'", label, path)
159+
level.Warn(logger).Log("msg", "Label path not found in json", "path", path, "label", label)
160+
level.Debug(logger).Log("msg", "Label path not found in json", "path", path, "label", label, "json", string(json))
160161
}
161162
continue
162163
}
@@ -171,12 +172,12 @@ func extractLabels(json []byte, l map[string]string) map[string]string {
171172
return labels
172173
}
173174

174-
func FetchJson(ctx context.Context, endpoint string, headers map[string]string) ([]byte, error) {
175+
func FetchJson(ctx context.Context, logger log.Logger, endpoint string, headers map[string]string) ([]byte, error) {
175176
client := &http.Client{}
176177
req, err := http.NewRequest("GET", endpoint, nil)
177178
req = req.WithContext(ctx)
178179
if err != nil {
179-
log.Errorf("Error creating request. ERROR: '%s'", err)
180+
level.Error(logger).Log("msg", "Failed to create request", "err", err)
180181
return nil, err
181182
}
182183

internal/init.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
package internal
1515

1616
import (
17-
"log"
17+
"os"
1818

19+
"github.com/go-kit/kit/log"
20+
"github.com/go-kit/kit/log/level"
1921
"github.com/prometheus-community/json_exporter/config"
2022
"github.com/urfave/cli"
2123
)
2224

23-
func Init(c *cli.Context) {
25+
func Init(logger log.Logger, c *cli.Context) {
2426
args := c.Args()
2527

2628
if len(args) < 1 {
2729
cli.ShowAppHelp(c) //nolint:errcheck
28-
log.Fatalf("Not enought arguments")
30+
level.Error(logger).Log("msg", "Not enough arguments")
31+
os.Exit(1)
2932
}
3033

3134
var (
@@ -35,6 +38,7 @@ func Init(c *cli.Context) {
3538
_, err := config.LoadConfig(configPath)
3639

3740
if err != nil {
38-
log.Fatal("Failed to load config")
41+
level.Error(logger).Log("msg", "Failed to load config")
42+
os.Exit(1)
3943
}
4044
}

0 commit comments

Comments
 (0)