Skip to content

Commit

Permalink
logging: Ensure errors are logged correctly
Browse files Browse the repository at this point in the history
Ensure all errors are logged using the `logrus.WithError()` API.
The current `logrus.Error(err)` calls will result in log messages
containing the following fields:

```
level=error msg="..."
```

Whereas using `logrus.WithError()` will result in the expected:

```
level=error error="..."
```

Fixes kata-containers#26.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Mar 22, 2018
1 parent 5f28890 commit 712d846
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ksm.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (k *ksm) throttle() {
defer k.Unlock()

if !k.initialized {
throttlerLog.Error(errors.New("KSM is unavailable"))
throttlerLog.WithError(errors.New("KSM is unavailable")).Error()
return
}

Expand All @@ -287,7 +287,7 @@ func (k *ksm) throttle() {
// We will enter the aggressive setting until we throttle down.
_ = throttleTimer.Stop()
if err := k.tune(ksmSettings[ksmAggressive]); err != nil {
throttlerLog.Error(err)
throttlerLog.WithError(err).Error("kick failed to tune")
continue
}

Expand All @@ -306,7 +306,7 @@ func (k *ksm) throttle() {
if throttle.nextKnob == ksmInitial {
k.Lock()
if err := k.restoreSysFS(); err != nil {
throttlerLog.Error(err)
throttlerLog.WithError(err).Error("failed to restore sysfs")
}
k.Unlock()
}
Expand All @@ -316,7 +316,7 @@ func (k *ksm) throttle() {
nextKnob := ksmThrottleIntervals[k.currentKnob].nextKnob
interval := ksmThrottleIntervals[k.currentKnob].interval
if err := k.tune(ksmSettings[nextKnob]); err != nil {
throttlerLog.Error(err)
throttlerLog.WithError(err).Error("timer failed to tune")
continue
}

Expand Down Expand Up @@ -371,7 +371,7 @@ func (k *ksm) kick() {
k.Lock()

if !k.initialized {
throttlerLog.Error(errors.New("KSM is unavailable"))
throttlerLog.WithError(errors.New("KSM is unavailable")).Error()
k.Unlock()
return
}
Expand Down

0 comments on commit 712d846

Please sign in to comment.