Skip to content

Commit 6e41c33

Browse files
committed
Simplify options to use stdlog interface
1 parent c1559c4 commit 6e41c33

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

stackdriver_exporter.go

+2-26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package main
1515

1616
import (
1717
"fmt"
18+
stdlog "log"
1819
"net/http"
1920
"os"
2021
"strings"
@@ -125,10 +126,6 @@ var (
125126
monitoringDescriptorCacheOnlyGoogle = kingpin.Flag(
126127
"monitoring.descriptor-cache-only-google", "Only cache descriptors for *.googleapis.com metrics",
127128
).Default("true").Bool()
128-
129-
monitoringEnablePromHttpCustomLogger = kingpin.Flag(
130-
"monitoring.enable-promhttp-custom-logger", "Enable custom logger for promhttp",
131-
).Default("false").Bool()
132129
)
133130

134131
func init() {
@@ -238,15 +235,8 @@ func (h *handler) innerHandler(filters map[string]bool) http.Handler {
238235
registry,
239236
}
240237
}
241-
238+
opts := promhttp.HandlerOpts{ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0)}
242239
// Delegate http serving to Prometheus client library, which will call collector.Collect.
243-
opts := promhttp.HandlerOpts{}
244-
if *monitoringEnablePromHttpCustomLogger {
245-
level.Info(h.logger).Log("msg", "Enabling custom logger for promhttp")
246-
opts = promhttp.HandlerOpts{
247-
ErrorLog: NewPromHttpCustomLogger(h.logger),
248-
}
249-
}
250240
return promhttp.HandlerFor(gatherers, opts)
251241
}
252242

@@ -376,17 +366,3 @@ func parseMetricExtraFilters() []collectors.MetricFilter {
376366
}
377367
return extraFilters
378368
}
379-
380-
type customPromErrorLogger struct {
381-
logger log.Logger
382-
}
383-
384-
func (l *customPromErrorLogger) Println(v ...interface{}) {
385-
level.Error(l.logger).Log("msg", fmt.Sprint(v...))
386-
}
387-
388-
func NewPromHttpCustomLogger(logger log.Logger) *customPromErrorLogger {
389-
return &customPromErrorLogger{
390-
logger: logger,
391-
}
392-
}

0 commit comments

Comments
 (0)