log.go 456 B

123456789101112131415161718192021
  1. package hcs
  2. import "github.com/sirupsen/logrus"
  3. func logOperationBegin(ctx logrus.Fields, msg string) {
  4. logrus.WithFields(ctx).Debug(msg)
  5. }
  6. func logOperationEnd(ctx logrus.Fields, msg string, err error) {
  7. // Copy the log and fields first.
  8. log := logrus.WithFields(ctx)
  9. if err == nil {
  10. log.Debug(msg)
  11. } else {
  12. // Edit only the copied field data to avoid race conditions on the
  13. // write.
  14. log.Data[logrus.ErrorKey] = err
  15. log.Error(msg)
  16. }
  17. }