switch to go-kit/log (#1575)

Signed-off-by: yeya24 <yb532204897@gmail.com>
This commit is contained in:
Ben Ye 2019-12-31 11:19:37 -05:00 committed by Ben Kochie
commit 2477c5c67d
158 changed files with 3434 additions and 4636 deletions

View file

@ -20,9 +20,10 @@ import (
"os"
"path/filepath"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/mdlayher/wifi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)
@ -40,6 +41,8 @@ type wifiCollector struct {
stationTransmitRetriesTotal *prometheus.Desc
stationTransmitFailedTotal *prometheus.Desc
stationBeaconLossTotal *prometheus.Desc
logger log.Logger
}
var (
@ -61,7 +64,7 @@ type wifiStater interface {
}
// NewWifiCollector returns a new Collector exposing Wifi statistics.
func NewWifiCollector() (Collector, error) {
func NewWifiCollector(logger log.Logger) (Collector, error) {
const (
subsystem = "wifi"
)
@ -154,6 +157,7 @@ func NewWifiCollector() (Collector, error) {
labels,
nil,
),
logger: logger,
}, nil
}
@ -162,11 +166,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
// Cannot access wifi metrics, report no error.
if os.IsNotExist(err) {
log.Debug("wifi collector metrics are not available for this system")
level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system")
return nil
}
if os.IsPermission(err) {
log.Debug("wifi collector got permission denied when accessing metrics")
level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics")
return nil
}
@ -185,7 +189,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
continue
}
log.Debugf("probing wifi device %q with type %q", ifi.Name, ifi.Type)
level.Debug(c.logger).Log("msg", "probing wifi device with type", "wifi", ifi.Name, "type", ifi.Type)
ch <- prometheus.MustNewConstMetric(
c.interfaceFrequencyHertz,
@ -203,7 +207,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
case err == nil:
c.updateBSSStats(ch, ifi.Name, bss)
case os.IsNotExist(err):
log.Debugf("BSS information not found for wifi device %q", ifi.Name)
level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name)
default:
return fmt.Errorf("failed to retrieve BSS for device %s: %v",
ifi.Name, err)
@ -216,7 +220,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
c.updateStationStats(ch, ifi.Name, station)
}
case os.IsNotExist(err):
log.Debugf("station information not found for wifi device %q", ifi.Name)
level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name)
default:
return fmt.Errorf("failed to retrieve station info for device %q: %v",
ifi.Name, err)