Skip to content

Commit

Permalink
Merge pull request #159 from numtide/feat/debug-logging
Browse files Browse the repository at this point in the history
feat: add some info and debug logging
  • Loading branch information
brianmcgee authored Dec 3, 2024
2 parents 3cff563 + e1b1adb commit f956507
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/facter/facter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package facter
import (
"errors"
"fmt"
"log/slog"

"github.com/numtide/nixos-facter/pkg/build"
"github.com/numtide/nixos-facter/pkg/ephem"
Expand Down Expand Up @@ -63,28 +64,37 @@ func (s *Scanner) Scan() (*Report, error) {

report.System = build.System

slog.Info("building report", "system", report.System, "version", report.Version)

var (
smbios []hwinfo.Smbios
devices []hwinfo.HardwareDevice
)

slog.Info("scanning hardware", "features", s.Features)

smbios, devices, err = hwinfo.Scan(s.Features)
if err != nil {
return nil, fmt.Errorf("failed to scan hardware: %w", err)
}

slog.Info("reading IOMMU groups")

// read iommu groups
iommuGroups, err := hwinfo.IOMMUGroups()
if err != nil {
return nil, fmt.Errorf("failed to read iommu groups: %w", err)
}

slog.Info("processing devices", "count", len(devices))

for idx := range devices {
// lookup iommu group before adding to the report
device := devices[idx]

groupID, ok := iommuGroups[device.SysfsID]
if ok {
slog.Debug("IOMMU group found", "device", device.SysfsID, "groupID", groupID)
device.SysfsIOMMUGroupID = &groupID
}

Expand All @@ -93,21 +103,29 @@ func (s *Scanner) Scan() (*Report, error) {
}
}

slog.Info("processing smbios entries", "count", len(smbios))

for idx := range smbios {
if err = report.Smbios.add(smbios[idx]); err != nil {
return nil, fmt.Errorf("failed to add to smbios report: %w", err)
}
}

slog.Info("detecting virtualisation")

if report.Virtualisation, err = virt.Detect(); err != nil {
return nil, fmt.Errorf("failed to detect virtualisation: %w", err)
}

if s.Ephemeral || s.Swap {
slog.Info("processing swap devices")

if report.Swap, err = ephem.SwapEntries(); err != nil {
return nil, fmt.Errorf("failed to detect swap devices: %w", err)
}
}

slog.Info("report complete")

return &report, nil
}
11 changes: 11 additions & 0 deletions pkg/facter/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package facter
import (
"errors"
"fmt"
"log/slog"
"slices"

"github.com/numtide/nixos-facter/pkg/hwinfo"
Expand Down Expand Up @@ -186,6 +187,16 @@ func compareDevice(a hwinfo.HardwareDevice, b hwinfo.HardwareDevice) int {
}

func (h *Hardware) add(device hwinfo.HardwareDevice) error {
slog.Debug(
"hardware.add",
"index", device.Index,
"attached_to", device.AttachedTo,
"class", device.Class,
"class_list", device.ClassList,
"bus", device.BusType,
"sysfs_id", device.SysfsID,
)

// start with the overall device class
class := device.Class

Expand Down
3 changes: 3 additions & 0 deletions pkg/facter/smbios.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package facter
import (
"errors"
"fmt"
"log/slog"

"github.com/numtide/nixos-facter/pkg/hwinfo"
)
Expand Down Expand Up @@ -75,6 +76,8 @@ type Smbios struct {
}

func (s *Smbios) add(item hwinfo.Smbios) error {
slog.Debug("smbios.add", "type", item.SmbiosType())

switch item.SmbiosType() {
case hwinfo.SmbiosTypeBios:
if s.Bios != nil {
Expand Down

0 comments on commit f956507

Please sign in to comment.