Get rid of intermediate logger.
This commit is contained in:
parent
3a8fcda20a
commit
a423a8aebe
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue