Skip to content

Commit 697988e

Browse files
committed
cmd: log less on info level
Currently, virter logs the same 8 (ish) lines every time a VM is started, and another few when it is removed. This is redundant information in almost all cases, so it really belongs in the Debug level.
1 parent a0bf17c commit 697988e

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

cmd/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func initConfig() {
149149
if newPath == "" {
150150
newPath = filepath.Join(configPath(), "virter.toml")
151151
}
152-
log.Print("Config file does not exist, creating default: ", newPath)
152+
log.Info("Config file does not exist, creating default: ", newPath)
153153

154154
err := writeDefaultConfig(newPath)
155155
if err != nil {

internal/virter/dhcp.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (v *Virter) AddDHCPHost(mac string, id uint) error {
3131
return fmt.Errorf("failed to compute IP for network: %w", err)
3232
}
3333

34-
log.Printf("Add DHCP entry from %v to %v", mac, ip)
34+
log.WithField("from", mac).WithField("to", ip).Debug("Add DHCP entry")
3535
err = v.patchedNetworkUpdate(
3636
v.provisionNetwork,
3737
libvirt.NetworkUpdateCommandAddLast,
@@ -213,7 +213,7 @@ func (v *Virter) removeDomainDHCP(domain libvirt.Domain, removeDHCPEntries bool)
213213

214214
func (v *Virter) removeDHCPEntries(network libvirt.Network, mac string, ips []string) error {
215215
for _, ip := range ips {
216-
log.Printf("Remove DHCP entry from %v to %v", mac, ip)
216+
log.WithField("from", mac).WithField("to", ip).Debug("Remove DHCP entry")
217217
err := v.patchedNetworkUpdate(
218218
network,
219219
libvirt.NetworkUpdateCommandDelete,

internal/virter/vm.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (v *Virter) VMRun(vmConfig VMConfig) error {
130130
}
131131
// end checks
132132

133-
log.Print("Create host key")
133+
log.Debug("Create host key")
134134
hostkey, err := sshkeys.NewRSAHostKey()
135135
if err != nil {
136136
return fmt.Errorf("could not create new host key: %w", err)
@@ -148,26 +148,26 @@ func (v *Virter) VMRun(vmConfig VMConfig) error {
148148

149149
log.Debugf("Using domain XML: %s", vmXML)
150150

151-
log.Print("Define VM")
151+
log.Debug("Define VM")
152152
d, err := v.libvirt.DomainDefineXML(vmXML)
153153
if err != nil {
154154
return fmt.Errorf("could not define domain: %w", err)
155155
}
156156

157-
log.Print("Create boot volume")
157+
log.Debug("Create boot volume")
158158
_, err = v.ImageSpawn(vmConfig.Name, v.provisionStoragePool, vmConfig.Image, vmConfig.BootCapacityKiB)
159159
if err != nil {
160160
return err
161161
}
162162

163-
log.Print("Create cloud-init volume")
163+
log.Debug("Create cloud-init volume")
164164
_, err = v.createCIData(vmConfig, hostkey)
165165
if err != nil {
166166
return err
167167
}
168168

169169
for _, d := range vmConfig.Disks {
170-
log.Printf("Create volume '%s'", d.GetName())
170+
log.WithField("name", d.GetName()).Debug("Create volume")
171171
pool, err := v.lookupPool(d.GetPool())
172172
if err != nil {
173173
return fmt.Errorf("failed to lookup libvirt pool %s: %w", d.GetPool(), err)
@@ -188,7 +188,7 @@ func (v *Virter) VMRun(vmConfig VMConfig) error {
188188
}
189189
}
190190

191-
log.Print("Start VM")
191+
log.Debug("Start VM")
192192
err = v.libvirt.DomainCreate(d)
193193
if err != nil {
194194
return fmt.Errorf("could not create (start) domain: %w", err)
@@ -245,7 +245,7 @@ func (v *Virter) WaitVmReady(ctx context.Context, shellClientBuilder ShellClient
245245
return nil
246246
}
247247

248-
log.Print("Wait for VM to get ready")
248+
log.Debug("Wait for VM to get ready")
249249

250250
// Using ActualTime breaks the expectation of the unit tests
251251
// that this code does not sleep, but we work around that by
@@ -254,7 +254,7 @@ func (v *Virter) WaitVmReady(ctx context.Context, shellClientBuilder ShellClient
254254
return fmt.Errorf("VM not ready: %w", err)
255255
}
256256

257-
log.Print("Successfully connected to ready VM")
257+
log.Debug("Successfully connected to ready VM")
258258
return nil
259259
}
260260

@@ -283,7 +283,7 @@ func (v *Virter) VMRm(vmName string, removeDHCPEntries bool, removeBoot bool) er
283283
// it is active (running). And only if it is persistent, otherwise the
284284
// domain is gone and we cannot query what resources it depended on.
285285
if active > 0 && persistent > 0 {
286-
log.Print("Stop VM")
286+
log.Debug("Stop VM")
287287
err = v.libvirt.DomainDestroy(domain)
288288
if err != nil {
289289
return fmt.Errorf("could not destroy domain: %w", err)
@@ -318,14 +318,14 @@ func (v *Virter) VMRm(vmName string, removeDHCPEntries bool, removeBoot bool) er
318318
}
319319

320320
if persistent > 0 {
321-
log.Print("Undefine VM")
321+
log.Debug("Undefine VM")
322322
err = v.libvirt.DomainUndefineFlags(domain, libvirt.DomainUndefineNvram)
323323
if err != nil {
324324
return fmt.Errorf("could not undefine domain: %w", err)
325325
}
326326
} else if active > 0 {
327327
// Stop the VM if we did not stop it previously.
328-
log.Print("Stop VM")
328+
log.Debug("Stop VM")
329329
err = v.libvirt.DomainDestroy(domain)
330330
if err != nil {
331331
return fmt.Errorf("could not destroy domain: %w", err)
@@ -370,7 +370,7 @@ func (v *Virter) rmSnapshots(domain libvirt.Domain) error {
370370
}
371371

372372
for _, snapshot := range snapshots {
373-
log.Printf("Delete snapshot %v", snapshot.Name)
373+
log.WithField("name", snapshot.Name).Debug("Delete snapshot")
374374
err = v.libvirt.DomainSnapshotDelete(snapshot, 0)
375375
if err != nil {
376376
return fmt.Errorf("could not delete snapshot: %w", err)
@@ -443,14 +443,14 @@ func (v *Virter) vmShutdown(ctx context.Context, afterNotifier AfterNotifier, sh
443443
}
444444

445445
if active != 0 {
446-
log.Printf("Shut down VM")
446+
log.Debug("Shut down VM")
447447

448448
err = v.libvirt.DomainShutdown(domain)
449449
if err != nil {
450450
return fmt.Errorf("could not shut down domain: %w", err)
451451
}
452452

453-
log.Printf("Wait for VM to stop")
453+
log.Debug("Wait for VM to stop")
454454
}
455455

456456
timeout := afterNotifier.After(shutdownTimeout)
@@ -703,7 +703,7 @@ func (v *Virter) VMExecRsync(ctx context.Context, copier netcopy.NetworkCopier,
703703
g, ctx := errgroup.WithContext(ctx)
704704
for _, vmName := range vmNames {
705705
vmName := vmName
706-
log.Printf(`Copying files via rsync: %s to %s on %s`, rsyncStep.Source, rsyncStep.Dest, vmName)
706+
log.Debugf(`Copying files via rsync: %s to %s on %s`, rsyncStep.Source, rsyncStep.Dest, vmName)
707707
g.Go(func() error {
708708
dest := fmt.Sprintf("%s:%s", vmName, rsyncStep.Dest)
709709
return v.VMExecCopy(ctx, copier, files, dest)

0 commit comments

Comments
 (0)