volume/service: change some logs to use structured logs#48675
volume/service: change some logs to use structured logs#48675thaJeztah merged 1 commit intomoby:masterfrom
Conversation
Signed-off-by: Sebastiaan van Stijn <[email protected]>
| driverName := v.DriverName() | ||
| if _, err := s.drivers.ReleaseDriver(driverName); err != nil { | ||
| log.G(ctx).WithError(err).WithField("driver", driverName).Error("Error releasing reference to volume driver") | ||
| log.G(ctx).WithFields(log.Fields{"error": err, "driver": driverName, "volume-name": name}).Error("Error releasing reference to volume driver") |
There was a problem hiding this comment.
What was the problem with WithError?
There was a problem hiding this comment.
Mostly because WithError, WithField, WithFields do a lot under the hood; they have to merge new values with old values, and performing reflection; doing a single WithFields can avoid doing that multiple times;
moby/vendor/github.com/sirupsen/logrus/entry.go
Lines 105 to 151 in 921ac59
There was a problem hiding this comment.
@AkihiroSuda ☝️ does that answer your question? Do the changes LGTY?
| driverName := v.DriverName() | ||
| if _, err := s.drivers.ReleaseDriver(driverName); err != nil { | ||
| log.G(ctx).WithError(err).WithField("driver", driverName).Error("Error releasing reference to volume driver") | ||
| log.G(ctx).WithFields(log.Fields{"error": err, "driver": driverName, "volume-name": name}).Error("Error releasing reference to volume driver") |
There was a problem hiding this comment.
nit:
| log.G(ctx).WithFields(log.Fields{"error": err, "driver": driverName, "volume-name": name}).Error("Error releasing reference to volume driver") | |
| log.G(ctx).WithFields(log.Fields{logrus.ErrorKey: err, "driver": driverName, "volume-name": name}).Error("Error releasing reference to volume driver") |
There was a problem hiding this comment.
Ah, yeah, that's on purpose; trying to avoid direct imports of logrus (we changed all imports to use containerd's logs package, which provides aliases for the essential parts)
- A picture of a cute animal (not mandatory but encouraged)