diff --git a/client.go b/client.go index 923d5c3..9065741 100644 --- a/client.go +++ b/client.go @@ -12,7 +12,12 @@ import ( ) func send(method string, path string, data string) (string, error) { - logrus.Debugf("sending %s %s with data %s to %s", method, path, data, unixSocketPath) + logrus.WithFields(logrus.Fields{ + "method": method, + "path": path, + "data": data, + "unix": unixSocketPath, + }).Debug("sending request") httpc := http.Client{ Transport: &http.Transport{ @@ -63,7 +68,10 @@ func send(method string, path string, data string) (string, error) { code := resp.StatusCode - logrus.Debugf("got response: %d %s", code, body) + logrus.WithFields(logrus.Fields{ + "code": code, + "body": body, + }).Debug("got response") if code < 200 || code > 299 { return "", fmt.Errorf("got %d: %s", code, body) diff --git a/conf.go b/conf.go index f0f0245..ec65f74 100644 --- a/conf.go +++ b/conf.go @@ -50,7 +50,7 @@ func saveConfig() error { func loadConfig() error { // Check if config file exists if _, err := os.Stat(configPath); errors.Is(err, os.ErrNotExist) { - logrus.Infof("config file %s does not exist, using default config %#v", configPath, defaultConfig) + logrus.WithField("config", defaultConfig).Infof("config file %s does not exist, using default config", configPath) config = defaultConfig err := saveConfig() if err != nil { diff --git a/loop.go b/loop.go index 33e5bc6..a7b9d32 100644 --- a/loop.go +++ b/loop.go @@ -157,12 +157,12 @@ func printStatus( isPluggedIn bool, maintainedChargingInProgress bool, ) { - logrus.Debugf("batteryCharge=%d, lower=%d, upper=%d, chargingEnabled=%t, isPluggedIn=%t, maintainedChargingInProgress=%t", - batteryCharge, - lower, - upper, - isChargingEnabled, - isPluggedIn, - maintainedChargingInProgress, - ) + logrus.WithFields(logrus.Fields{ + "batteryCharge": batteryCharge, + "lower": lower, + "upper": upper, + "chargingEnabled": isChargingEnabled, + "isPluggedIn": isPluggedIn, + "maintainedChargingInProgress": maintainedChargingInProgress, + }).Debug("maintain loop status") } diff --git a/sleepcallback.go b/sleepcallback.go index fada0cb..a5c40fd 100644 --- a/sleepcallback.go +++ b/sleepcallback.go @@ -111,9 +111,11 @@ func systemWillSleepCallback() { logrus.Errorf("DisableCharging failed: %v", err) return } - err = smcConn.SetMagSafeLedState(smc.LEDOff) - if err != nil { - logrus.Errorf("SetMagSafeLedState failed: %v", err) + if config.ControlMagSafeLED { + err = smcConn.SetMagSafeLedState(smc.LEDOff) + if err != nil { + logrus.Errorf("SetMagSafeLedState failed: %v", err) + } } } else { logrus.Debugln("no maintained charging is in progress, allow sleep")