Skip to content

Commit

Permalink
Change Info log messages (#169)
Browse files Browse the repository at this point in the history
### What does this PR do

Changes messages that are logged as `.Info` to either `.Debug` or
`.Error` as appropriate. We should not be logging under `.Info` in a
library.
  • Loading branch information
mmlb authored Jul 9, 2024
2 parents ececddd + ffce05c commit b856053
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions actions/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ func (a *InventoryCollectorAction) CollectFirmwareChecksums(ctx context.Context)
}()

if a.collectors.FirmwareChecksumCollector == nil {
a.log.Info("nil firmware checksum collector")
a.log.Debug("nil firmware checksum collector")
return nil
}

Expand All @@ -698,7 +698,7 @@ func (a *InventoryCollectorAction) CollectFirmwareChecksums(ctx context.Context)
if slices.Contains(a.disabledCollectorUtilities, collectorKind) ||
slices.Contains(a.disabledCollectorUtilities, firmware.FirmwareDumpUtility) ||
slices.Contains(a.disabledCollectorUtilities, firmware.UEFIParserUtility) {
a.log.Info("firmware checksum disabled")
a.log.Debug("firmware checksum disabled")
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions examples/diskwipe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func main() {
// If the user supplied a non-default timeout then we'll honor it, otherwise we just go with a huge timeout.
// If this were *real* code and not an example some work could be done to guesstimate a timeout based on disk size.
if timeout == defaultTimeout {
l.WithField("timeout", timeout.String()).Info("increasing timeout")
l.WithField("timeout", timeout.String()).Debug("increasing timeout")
timeout = 24 * time.Hour
ctx, cancel = context.WithTimeout(context.WithoutCancel(ctx), timeout)
defer cancel()
Expand All @@ -107,7 +107,9 @@ func main() {
l.Fatal("failed find appropriate wiper drive")
}

err = wiper.WipeDrive(ctx, logger, drive)
ll := logger
ll.SetLevel(logrus.DebugLevel)
err = wiper.WipeDrive(ctx, ll, drive)
if err != nil {
l.Fatal("failed to wipe drive")
}
Expand Down
2 changes: 1 addition & 1 deletion examples/nvme-ns-wipe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

logger.Info("resetting namespaces")
logger.Debug("resetting namespaces")
err = nvme.ResetNS(ctx, *logicalName)
if err != nil {
logger.WithError(err).Fatal("exiting")
Expand Down
2 changes: 1 addition & 1 deletion providers/asrockrack/asrockrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func New(dmidecode *utils.Dmidecode, l *logrus.Logger) (actions.DeviceManager, e
// Returns hardware inventory for the device
func (a *asrockrack) GetInventory(ctx context.Context, options ...actions.Option) (*common.Device, error) {
// Collect device inventory
a.logger.Info("Collecting inventory")
a.logger.Debug("Collecting inventory")

deviceObj := common.NewDevice()
a.hw.Device = &deviceObj
Expand Down
10 changes: 5 additions & 5 deletions providers/dell/dell.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (d *dell) UpdatesApplied() bool {
// GetInventory collects hardware inventory along with the firmware installed and returns a Device object
func (d *dell) GetInventory(ctx context.Context, options ...actions.Option) (*common.Device, error) {
// Collect device inventory
d.logger.Info("Collecting hardware inventory")
d.logger.Debug("Collecting hardware inventory")

collector := actions.NewInventoryCollectorAction(d.logger, options...)
if err := collector.Collect(ctx, d.hw.Device); err != nil {
Expand Down Expand Up @@ -142,7 +142,7 @@ func (d *dell) GetInventoryOEM(ctx context.Context, _ *common.Device, options *m
// ListAvailableUpdates runs the vendor tooling (dsu) to identify updates available
func (d *dell) ListAvailableUpdates(ctx context.Context, options *model.UpdateOptions) (*common.Device, error) {
// collect firmware updates available for components
d.logger.Info("Identifying component firmware updates...")
d.logger.Debug("Identifying component firmware updates...")

d.setUpdateOptions(options)

Expand All @@ -153,11 +153,11 @@ func (d *dell) ListAvailableUpdates(ctx context.Context, options *model.UpdateOp

count := len(oemUpdates)
if count == 0 {
d.logger.Info("no available dell Oem updates")
d.logger.Debug("no available dell Oem updates")
return nil, nil
}

d.logger.WithField("count", count).Info("component updates identified..")
d.logger.WithField("count", count).Debug("component updates identified..")

d.hw.OEMComponents = append(d.hw.OEMComponents, oemUpdates...)

Expand Down Expand Up @@ -225,7 +225,7 @@ func (d *dell) setUpdateOptions(options *model.UpdateOptions) {
"dsu repo": d.dsuReleaseVersion,
"base url": d.updateBaseURL,
},
).Info("update parameters")
).Debug("update parameters")
}

// ApplyUpdate is here to satisfy the actions.Updater interface
Expand Down
6 changes: 3 additions & 3 deletions providers/dell/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *dell) installUpdate(ctx context.Context, updateFile string, downgrade b

d.logger.WithFields(
logrus.Fields{"file": updateFile},
).Info("Installing dell Update Bin file")
).Debug("Installing dell Update Bin file")

result, err := e.Exec(ctx)
if err != nil {
Expand All @@ -88,7 +88,7 @@ func (d *dell) installUpdate(ctx context.Context, updateFile string, downgrade b

d.logger.WithFields(
logrus.Fields{"file": updateFile},
).Info("Installed")
).Debug("Installed")

d.hw.PendingReboot = true

Expand Down Expand Up @@ -140,7 +140,7 @@ func (d *dell) pre(ctx context.Context) (err error) {
}
}

d.logger.Info("Dell DSU prerequisites setup complete")
d.logger.Debug("Dell DSU prerequisites setup complete")
d.DsuPrequisitesInstalled = true

return nil
Expand Down
2 changes: 1 addition & 1 deletion providers/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func New(dmidecode *utils.Dmidecode, l *logrus.Logger) (actions.DeviceManager, e
// Returns hardware inventory for the device
func (a *Generic) GetInventory(ctx context.Context, options ...actions.Option) (*common.Device, error) {
// Collect device inventory
a.logger.Info("Collecting inventory")
a.logger.Debug("Collecting inventory")

collector := actions.NewInventoryCollectorAction(a.logger, options...)
if err := collector.Collect(ctx, a.hw.Device); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion providers/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *supermicro) UpdatesApplied() bool {
// GetInventory collects hardware inventory along with the firmware installed and returns a Device object
func (s *supermicro) GetInventory(ctx context.Context, options ...actions.Option) (*common.Device, error) {
// Collect device inventory
s.logger.Info("Collecting hardware inventory")
s.logger.Debug("Collecting hardware inventory")

// define collectors for supermicro hardware
collectors := &actions.Collectors{
Expand Down
2 changes: 1 addition & 1 deletion utils/blkdiscard.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (b *Blkdiscard) Discard(ctx context.Context, drive *common.Drive) error {

// WipeDrive implements DriveWipe by calling Discard
func (b *Blkdiscard) WipeDrive(ctx context.Context, logger *logrus.Logger, drive *common.Drive) error {
logger.WithField("drive", drive.LogicalName).WithField("method", "blkdiscard").Info("wiping")
logger.WithField("drive", drive.LogicalName).WithField("method", "blkdiscard").Debug("wiping")
return b.Discard(ctx, drive)
}

Expand Down
8 changes: 4 additions & 4 deletions utils/fill_zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewFillZeroCmd(trace bool) *FillZero {

func (z *FillZero) WipeDrive(ctx context.Context, logger *logrus.Logger, drive *common.Drive) error {
log := logger.WithField("drive", drive.LogicalName).WithField("method", "zero-fill")
log.Info("wiping")
log.Debug("wiping")

verify, err := ApplyWatermarks(drive)
if err != nil {
Expand All @@ -46,7 +46,7 @@ func (z *FillZero) WipeDrive(ctx context.Context, logger *logrus.Logger, drive *
return err
}

log.WithField("size", fmt.Sprintf("%dB", partitionSize)).Info("disk info detected")
log.WithField("size", fmt.Sprintf("%dB", partitionSize)).Debug("disk info detected")
_, err = file.Seek(0, io.SeekStart)
if err != nil {
return err
Expand All @@ -60,7 +60,7 @@ func (z *FillZero) WipeDrive(ctx context.Context, logger *logrus.Logger, drive *
// Check if the context has been canceled
select {
case <-ctx.Done():
log.Info("stopping")
log.Debug("stopping")
return ctx.Err()
default:
l := min(int64(len(buffer)), bytesRemaining)
Expand Down Expand Up @@ -100,7 +100,7 @@ func printProgress(log *logrus.Entry, totalBytesWritten, partitionSize int64, st
"progress": fmt.Sprintf("%.2f%%", progress),
"speed": fmt.Sprintf("%.2f MB/s", mbPerSecond),
"remaining": fmt.Sprintf("%.2f hour(s)", remainingHours),
}).Info("")
}).Debug("")
}

// SetQuiet lowers the verbosity
Expand Down
12 changes: 6 additions & 6 deletions utils/hdparm.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,32 +240,32 @@ func (h *Hdparm) WipeDrive(ctx context.Context, logger *logrus.Logger, drive *co
if sanitize && cse {
// nolint:govet
l := l.WithField("method", "sanitize").WithField("action", "sanitize-crypto-scramble")
l.Info("wiping")
l.Debug("wiping")
err := h.Sanitize(ctx, drive, CryptoErase)
if err == nil {
return nil
}
l.WithError(err).Info("failed")
l.WithError(err).Error("failed")
}
if sanitize && bee {
// nolint:govet
l := l.WithField("method", "sanitize").WithField("action", "sanitize-block-erase")
l.Info("wiping")
l.Debug("wiping")
err := h.Sanitize(ctx, drive, BlockErase)
if err == nil {
return nil
}
l.WithError(err).Info("failed")
l.WithError(err).Error("failed")
}
if esee && eseu {
// nolint:govet
l := l.WithField("method", "security-erase-enhanced")
l.Info("wiping")
l.Debug("wiping")
err := h.Erase(ctx, drive, CryptographicErase)
if err == nil {
return nil
}
l.WithError(err).Info("failed")
l.WithError(err).Error("failed")
}
return ErrIneffectiveWipe
}
Expand Down
16 changes: 8 additions & 8 deletions utils/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,41 +310,41 @@ func (n *Nvme) WipeDrive(ctx context.Context, logger *logrus.Logger, drive *comm
if cer {
// nolint:govet
l := l.WithField("method", "sanitize").WithField("action", CryptoErase)
l.Info("wiping")
l.Debug("wiping")
err := n.Sanitize(ctx, drive, CryptoErase)
if err == nil {
return nil
}
l.WithError(err).Info("failed")
l.WithError(err).Error("failed")
}
if ber {
// nolint:govet
l := l.WithField("method", "sanitize").WithField("action", BlockErase)
l.Info("wiping")
l.Debug("wiping")
err := n.Sanitize(ctx, drive, BlockErase)
if err == nil {
return nil
}
l.WithError(err).Info("failed")
l.WithError(err).Error("failed")
}
if cese {
// nolint:govet
l := l.WithField("method", "format").WithField("setting", CryptographicErase)
l.Info("wiping")
l.Debug("wiping")
err := n.Format(ctx, drive, CryptographicErase)
if err == nil {
return nil
}
l.WithError(err).Info("failed")
l.WithError(err).Error("failed")
}

l = l.WithField("method", "format").WithField("setting", UserDataErase)
l.Info("wiping")
l.Debug("wiping")
err := n.Format(ctx, drive, UserDataErase)
if err == nil {
return nil
}
l.WithError(err).Info("failed")
l.WithError(err).Error("failed")
return ErrIneffectiveWipe
}

Expand Down

0 comments on commit b856053

Please sign in to comment.