fix(app): log every VM line under the VM's key

Some lines used the bare VM name as their source, so the log lines reported
with a failed command-line start left them out. Disk tasks also kept the
VM name in their step text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
千川白浪andClaude Opus 5.5 committed 2026-12-03 21:27:52 -07:00
1 parent 165f26351d
commit 0ed522656d
10 files changed
+44 -35

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
{
"group": "fixes",
"order": 0,
"authors": ["Nwflower"],
"zh": "从命令行启动虚拟机失败时,一并显示 Guest Tools 和网络相关的日志。",
"en": "Include Guest Tools and network log lines when a VM fails to start from the command line."
}
+1 -1
View File
@@ -218,7 +218,7 @@ func (a *App) createVMFlow(opts reims.CreateOpts) (err error) {
if _, networkErr := a.applyVMNetwork(ctx, opts.Name, "bridge", opts.UplinkGUID); networkErr != nil {
err = networkmsg.Error("create_bridge_pending", networkErr, "name", opts.Name)
finishTask(err)
a.emitLog(opts.Name, networkmsg.Text(a.locale(), "log.create_bridge_failed")+" "+networkmsg.Localize(networkErr, a.locale()).Error())
a.emitVMLog(opts.Name, networkmsg.Text(a.locale(), "log.create_bridge_failed")+" "+networkmsg.Localize(networkErr, a.locale()).Error())
a.emitStateChanged()
return err
}
+11 -11
View File
@@ -301,12 +301,12 @@ func (a *App) registerSavedGuestToolsConfig(srv *guesttools.Server, port int, na
return
}
if err := requireGuestToolsVM(vmDir); err != nil {
a.emitLog(name, "Warning: could not register Guest Tools config: "+err.Error())
a.emitVMLog(name, "Warning: could not register Guest Tools config: "+err.Error())
return
}
cfg, ok, err := guesttools.ReadVMConfigStrict(vmDir)
if err != nil {
a.emitLog(name, "Warning: could not load Guest Tools config: "+err.Error())
a.emitVMLog(name, "Warning: could not load Guest Tools config: "+err.Error())
return
}
if !ok {
@@ -318,7 +318,7 @@ func (a *App) registerSavedGuestToolsConfig(srv *guesttools.Server, port int, na
cfg.VMDir = vmDir
cfg.QEMUPath = a.activeQemuPath()
if _, err := srv.EnsureManagementNetwork(cfg); err != nil {
a.emitLog(name, networkmsg.Text(a.locale(), "log.management_restore_failed")+" "+networkmsg.Localize(err, a.locale()).Error())
a.emitVMLog(name, networkmsg.Text(a.locale(), "log.management_restore_failed")+" "+networkmsg.Localize(err, a.locale()).Error())
return
}
} else if len(networkMode) > 0 {
@@ -332,12 +332,12 @@ func (a *App) registerSavedGuestToolsConfig(srv *guesttools.Server, port int, na
if sharedDirChanged || cfg.Port != port {
cfg.Port = port
if err := guesttools.SaveVMConfig(vmDir, cfg); err != nil {
a.emitLog(name, "Warning: could not save Guest Tools config: "+err.Error())
a.emitVMLog(name, "Warning: could not save Guest Tools config: "+err.Error())
return
}
}
if err := a.registerGuestToolsConfig(srv, vmDir, cfg); err != nil {
a.emitLog(name, "Warning: could not register Guest Tools config: "+err.Error())
a.emitVMLog(name, "Warning: could not register Guest Tools config: "+err.Error())
}
}
@@ -359,7 +359,7 @@ func (a *App) populateGuestToolsDetail(d *reims.VMDetail, epoch uint64) {
}
cfg, ok, err := guesttools.ReadVMConfigStrict(d.Directory)
if err != nil {
a.emitLog(d.Name, "Warning: could not load Guest Tools config: "+err.Error())
a.emitVMLog(d.Name, "Warning: could not load Guest Tools config: "+err.Error())
return
}
if ok {
@@ -369,12 +369,12 @@ func (a *App) populateGuestToolsDetail(d *reims.VMDetail, epoch uint64) {
if sharedDir != "" && cfg.SharedDir != sharedDir {
cfg.SharedDir = sharedDir
if err := guesttools.SaveVMConfig(d.Directory, cfg); err != nil {
a.emitLog(d.Name, "Warning: could not save Guest Tools config: "+err.Error())
a.emitVMLog(d.Name, "Warning: could not save Guest Tools config: "+err.Error())
}
}
if srv, _, err := a.ensureGuestToolsBridge(); err == nil {
if err := a.registerGuestToolsConfig(srv, d.Directory, cfg); err != nil {
a.emitLog(d.Name, "Warning: could not register Guest Tools config: "+err.Error())
a.emitVMLog(d.Name, "Warning: could not register Guest Tools config: "+err.Error())
return
}
st := srv.Status(d.Name, 15*time.Second)
@@ -397,7 +397,7 @@ func (a *App) syncGuestTools(c *reims.Client, name string, cur *reims.VMDetail,
_, configured, err := guesttools.ReadVMConfigStrict(cur.Directory)
unlock()
if err != nil {
a.emitLog(name, "Warning: could not load Guest Tools config: "+err.Error())
a.emitVMLog(name, "Warning: could not load Guest Tools config: "+err.Error())
return
}
if !attached && !configured {
@@ -417,7 +417,7 @@ func (a *App) syncGuestTools(c *reims.Client, name string, cur *reims.VMDetail,
if cur.NetworkMode == "bridge" && a.npcapPluginEnabled() {
tokens, argsErr := reims.GuestToolsNetworkUnixArgs(cur.Directory, cfg.ManagementOutSock, cfg.ManagementInSock)
if argsErr != nil {
a.emitLog(name, networkmsg.Localize(argsErr, a.locale()).Error())
a.emitVMLog(name, networkmsg.Localize(argsErr, a.locale()).Error())
return
}
merged = strings.TrimSpace(merged + " " + strings.Join(tokens, " "))
@@ -427,7 +427,7 @@ func (a *App) syncGuestTools(c *reims.Client, name string, cur *reims.VMDetail,
if attached {
imgPath := a.guestToolsImagePath(name)
if err := guesttools.BuildToolsDiskImage(imgPath, cfg); err != nil {
a.emitLog(name, "Warning: could not refresh REIMSTOOLS disk: "+err.Error())
a.emitVMLog(name, "Warning: could not refresh REIMSTOOLS disk: "+err.Error())
return
}
merged = reims.MergeGuestToolsArgs(merged, imgPath)
+4 -4
View File
@@ -482,7 +482,7 @@ func (a *App) applyVMNetwork(parent context.Context, name, mode, uplink string)
a.emitStateChanged()
settings, err := a.GetVMNetworkSettings(name)
if err != nil {
a.emitLog(name, networkmsg.Text(a.locale(), "log.refresh_failed"))
a.emitVMLog(name, networkmsg.Text(a.locale(), "log.refresh_failed"))
return VMNetworkSettings{Mode: mode, UplinkGUID: selected.GUID, UplinkName: selected.Name, Ready: true}, nil
}
return settings, nil
@@ -706,7 +706,7 @@ func (a *App) registerExistingPacketBridges(ctx context.Context) {
err = a.preparePacketNetwork(ctx, c, d, record, true)
}
if err != nil {
a.emitLog(vm.Name, networkmsg.Text(a.locale(), "log.packet_restore_failed")+" "+networkmsg.Localize(err, a.locale()).Error())
a.emitVMLog(vm.Name, networkmsg.Text(a.locale(), "log.packet_restore_failed")+" "+networkmsg.Localize(err, a.locale()).Error())
}
}
}
@@ -807,7 +807,7 @@ func (a *App) switchPacketUplink(ctx context.Context, c networkControlClient, d
}
return err
}
a.emitLog(d.Name, networkmsg.Text(a.locale(), "log.uplink_switched"))
a.emitVMLog(d.Name, networkmsg.Text(a.locale(), "log.uplink_switched"))
return nil
}
@@ -903,6 +903,6 @@ func (a *App) applyPacketNetwork(ctx context.Context, c networkControlClient, d
srv.StopManagementNetwork(d.Name)
}
}
a.emitLog(d.Name, networkmsg.Text(a.locale(), "log.mode_applied", "mode", networkmsg.Text(a.locale(), "mode."+strings.ToLower(mode))))
a.emitVMLog(d.Name, networkmsg.Text(a.locale(), "log.mode_applied", "mode", networkmsg.Text(a.locale(), "mode."+strings.ToLower(mode))))
return nil
}
+1 -1
View File
@@ -903,7 +903,7 @@ func (a *App) CreateVMWithDriver(req driver.CreateRequest) error {
if issues := drv.ValidateCreate(ctx, req); len(issues) > 0 {
return errors.New(issues[0].Message)
}
w := vmstart.LineWriter(func(line string) { a.emitLog(req.Name, line) })
w := vmstart.LineWriter(func(line string) { a.emitVMLogForDriver(req.DriverID, req.Name, line) })
if err := drv.Create(ctx, req, w, w); err != nil {
return err
}
+4 -4
View File
@@ -157,14 +157,14 @@ func (a *App) registerResumeGuestTools(vm driver.VMInfo, epoch uint64, unicodeIn
}
cfg, configured, err := guesttools.ReadVMConfigStrict(vm.Directory)
if err != nil {
a.emitLog(ref.Name, "Warning: could not load Guest Tools config: "+err.Error())
a.emitVMLog(ref.Name, "Warning: could not load Guest Tools config: "+err.Error())
return nil, nil, 0
}
if !configured {
return nil, nil, 0
}
if err := requireGuestToolsVM(vm.Directory); err != nil {
a.emitLog(ref.Name, "Warning: could not register Guest Tools config: "+err.Error())
a.emitVMLog(ref.Name, "Warning: could not register Guest Tools config: "+err.Error())
return nil, nil, 0
}
srv, port, err := a.ensureGuestToolsBridge()
@@ -182,12 +182,12 @@ func (a *App) registerResumeGuestTools(vm driver.VMInfo, epoch uint64, unicodeIn
if cfg.Port != port || (windowBridge && (oldName != cfg.VMName || oldDir != cfg.SharedDir)) {
cfg.Port = port
if err := guesttools.SaveVMConfig(vm.Directory, cfg); err != nil {
a.emitLog(ref.Name, "Warning: could not save Guest Tools config: "+err.Error())
a.emitVMLog(ref.Name, "Warning: could not save Guest Tools config: "+err.Error())
return nil, nil, 0
}
}
if err := a.registerGuestToolsConfig(srv, vm.Directory, cfg); err != nil {
a.emitLog(ref.Name, "Warning: could not register Guest Tools config: "+err.Error())
a.emitVMLog(ref.Name, "Warning: could not register Guest Tools config: "+err.Error())
return nil, nil, 0
}
+11 -5
View File
@@ -390,7 +390,13 @@ func (a *App) ctlTaskWriter(kind, vm string, cancel context.CancelFunc) (id stri
id = tasks.start(kind, vm, vm, cancel)
lastStep := ""
lastLogAt := time.Now()
trim := func(s string) string { return strings.TrimPrefix(s, vm+": ") }
// vm is a VM name or a VM key.
name := vmNameFromKey(vm)
source := vm
if name == vm {
source = vmKey(vm)
}
trim := func(s string) string { return strings.TrimPrefix(s, name+": ") }
w = vmstart.LineWriter(func(line string) {
u, ok := host.ParseCtlLine(line)
if !ok {
@@ -401,19 +407,19 @@ func (a *App) ctlTaskWriter(kind, vm string, cancel context.CancelFunc) (id stri
if u.Step != lastStep {
lastStep = u.Step
lastLogAt = time.Now()
a.emitLog(vm, u.Step)
a.emitLog(source, u.Step)
} else if time.Since(lastLogAt) >= 30*time.Second {
lastLogAt = time.Now()
if u.Total > 0 {
a.emitLog(vm, fmt.Sprintf("%s: %.0f%% (%.1f / %.1f MB)", u.Step, u.Percent, float64(u.Done)/1e6, float64(u.Total)/1e6))
a.emitLog(source, fmt.Sprintf("%s: %.0f%% (%.1f / %.1f MB)", u.Step, u.Percent, float64(u.Done)/1e6, float64(u.Total)/1e6))
} else if u.Done > 0 {
a.emitLog(vm, fmt.Sprintf("%s: %.1f MB", u.Step, float64(u.Done)/1e6))
a.emitLog(source, fmt.Sprintf("%s: %.1f MB", u.Step, float64(u.Done)/1e6))
}
}
tasks.update(id, u)
return
}
a.emitLog(vm, line)
a.emitLog(source, line)
step := trim(u.Message)
lastStep = step
lastLogAt = time.Now()
+1 -1
View File
@@ -25,7 +25,7 @@ func (a *App) confirmVMWindowClose(name string) {
owner = host.ProcessDisplayWindow(uint32(pid))
}
if owner == 0 {
a.emitLog(name, "Could not locate the VM display window for close confirmation")
a.emitVMLog(name, "Could not locate the VM display window for close confirmation")
return
}
a.mu.Lock()
+1 -5
View File
@@ -300,11 +300,7 @@ func (p *vmPoller) pinStarted(vms []driver.VMListItem, loc i18n.Locale, autoPin
details[vmKeyForDriver(vm.DriverID, vm.Name)] = det
ref := driver.NewVMRef(vm.DriverID, vm.Name)
if line, _ := p.a.applyVMAffinity(loc, p.host, ref, vmDir, autoPin, pid, det.CPUs, false); line != "" {
if ref.DriverID == driver.BuiltinReimsMacOSDriverID {
p.a.emitLog(vm.Name, line)
} else {
p.a.emitVMLogForDriver(vm.DriverID, vm.Name, line)
}
p.a.emitVMLogForDriver(vm.DriverID, vm.Name, line)
}
}
return details
+3 -3
View File
@@ -57,9 +57,9 @@ func (a *App) handleWindowArgs(w cli.WindowArgs, secondLaunch bool) {
}
result := a.startResultPath(w.StartResult)
if w.StartResult != "" && result == "" {
a.emitVMLog(name, "Ignored a start result path outside the Reims-Go temp folder: "+w.StartResult)
a.emitVMLogForDriver(w.StartDriver, name, "Ignored a start result path outside the Reims-Go temp folder: "+w.StartResult)
}
a.emitVMLog(name, "Start requested from the command line")
a.emitVMLogForDriver(w.StartDriver, name, "Start requested from the command line")
go func() {
key := vmKeyForDriver(w.StartDriver, name)
capture := a.captureLogs(key)
@@ -77,7 +77,7 @@ func (a *App) handleWindowArgs(w cli.WindowArgs, secondLaunch bool) {
}
if result != "" {
if werr := cli.WriteStartResult(result, err); werr != nil {
a.emitVMLog(name, "Could not report the start result to the command line: "+werr.Error())
a.emitVMLogForDriver(w.StartDriver, name, "Could not report the start result to the command line: "+werr.Error())
}
}
}()