diff --git a/core/unifi/parsers.go b/core/unifi/devices.go similarity index 75% rename from core/unifi/parsers.go rename to core/unifi/devices.go index a2b97ce5..20a6a580 100644 --- a/core/unifi/parsers.go +++ b/core/unifi/devices.go @@ -13,7 +13,7 @@ func (u *Unifi) parseDevices(data []json.RawMessage, siteName string) *Devices { } else if t, ok := o["type"].(string); ok { assetType = t } - u.dLogf("Unmarshalling Device Type: %v, site %s ", assetType, siteName) + u.DebugLog("Unmarshalling Device Type: %v, site %s ", assetType, siteName) // Choose which type to unmarshal into based on the "type" json key. switch assetType { // Unmarshal again into the correct type.. case "uap": @@ -32,7 +32,7 @@ func (u *Unifi) parseDevices(data []json.RawMessage, siteName string) *Devices { devices.USWs = append(devices.USWs, usw) } default: - u.eLogf("unknown asset type - %v - skipping", assetType) + u.ErrorLog("unknown asset type - %v - skipping", assetType) } } return devices @@ -41,12 +41,12 @@ func (u *Unifi) parseDevices(data []json.RawMessage, siteName string) *Devices { // unmarshalDevice handles logging for the unmarshal operations in parseDevices(). func (u *Unifi) unmarshalDevice(dev string, data json.RawMessage, v interface{}) (err error) { if err = json.Unmarshal(data, v); err != nil { - u.eLogf("json.Unmarshal(%v): %v", dev, err) - u.eLogf("Enable Debug Logging to output the failed payload.") + u.ErrorLog("json.Unmarshal(%v): %v", dev, err) + u.ErrorLog("Enable Debug Logging to output the failed payload.") json, err := data.MarshalJSON() - u.dLogf("Failed Payload: %s (marshal err: %v)", json, err) - u.dLogf("The above payload can prove useful during torubleshooting when you open an Issue:") - u.dLogf("==- https://github.com/golift/unifi/issues/new -==") + u.DebugLog("Failed Payload: %s (marshal err: %v)", json, err) + u.DebugLog("The above payload can prove useful during torubleshooting when you open an Issue:") + u.DebugLog("==- https://github.com/golift/unifi/issues/new -==") } return err } diff --git a/core/unifi/types.go b/core/unifi/types.go index 77be80e7..a1782e83 100644 --- a/core/unifi/types.go +++ b/core/unifi/types.go @@ -32,18 +32,9 @@ const ( // that matches this interface to capture debug and error logs. type Logger func(msg string, fmt ...interface{}) -// dLogf logs a debug message. -func (u *Unifi) dLogf(msg string, v ...interface{}) { - if u.DebugLog != nil { - u.DebugLog("[DEBUG] "+msg, v...) - } -} - -// eLogf logs an error message. -func (u *Unifi) eLogf(msg string, v ...interface{}) { - if u.ErrorLog != nil { - u.ErrorLog("[ERROR] "+msg, v...) - } +// DiscardLogs is the default logger. +func DiscardLogs(msg string, v ...interface{}) { + // do nothing. } // Devices contains a list of all the unifi devices from a controller. diff --git a/core/unifi/unifi.go b/core/unifi/unifi.go index 3b408db7..cac82978 100644 --- a/core/unifi/unifi.go +++ b/core/unifi/unifi.go @@ -32,6 +32,8 @@ func NewUnifi(user, pass, url string, verifySSL bool) (*Unifi, error) { Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: !verifySSL}}, Jar: jar, }, + ErrorLog: DiscardLogs, + DebugLog: DiscardLogs, } return u, u.getController(user, pass) } @@ -74,7 +76,7 @@ func (u *Unifi) GetClients(sites []Site) (Clients, error) { var response struct { Data []Client `json:"data"` } - u.dLogf("Polling Controller, retreiving Unifi Clients, site %s (%s) ", site.Name, site.Desc) + u.DebugLog("Polling Controller, retreiving Unifi Clients, site %s (%s) ", site.Name, site.Desc) clientPath := fmt.Sprintf(ClientPath, site.Name) if err := u.GetData(clientPath, &response); err != nil { return nil, err @@ -135,7 +137,7 @@ func (u *Unifi) GetSites() (Sites, error) { response.Data[i].SiteName = response.Data[i].Desc + " (" + response.Data[i].Name + ")" sites = append(sites, response.Data[i].Name) } - u.dLogf("Found %d site(s): %s", len(sites), strings.Join(sites, ",")) + u.DebugLog("Found %d site(s): %s", len(sites), strings.Join(sites, ",")) return response.Data, nil }