9
9
"fmt"
10
10
"io"
11
11
"io/fs"
12
+ "log/slog"
12
13
"os"
13
14
"os/exec"
14
15
"path/filepath"
@@ -25,7 +26,6 @@ import (
25
26
"go.jetpack.io/devbox/internal/cloud/mutagenbox"
26
27
"go.jetpack.io/devbox/internal/cloud/openssh"
27
28
"go.jetpack.io/devbox/internal/cloud/openssh/sshshim"
28
- "go.jetpack.io/devbox/internal/debug"
29
29
"go.jetpack.io/devbox/internal/envir"
30
30
"go.jetpack.io/devbox/internal/services"
31
31
"go.jetpack.io/devbox/internal/telemetry"
@@ -61,7 +61,7 @@ func ensureVMForUser(vmHostname string, w io.Writer, username string, sshCmd *op
61
61
// Inspect the ssh ControlPath to check for existing connections
62
62
vmHostname = vmHostnameFromSSHControlPath ()
63
63
if vmHostname != "" {
64
- debug . Log ("Using vmHostname from ssh socket: %v " , vmHostname )
64
+ slog . Debug ("Using vmHostname from ssh socket" , "host " , vmHostname )
65
65
color .New (color .FgGreen ).Fprintln (w , "Detected existing virtual machine" )
66
66
} else {
67
67
var region , vmUser string
@@ -80,7 +80,7 @@ func ensureVMForUser(vmHostname string, w io.Writer, username string, sshCmd *op
80
80
// match their claimed username from GitHub.
81
81
err = openssh .SaveGithubUsernameToLocalFile (username )
82
82
if err != nil {
83
- debug . Log ( "Failed to save username: %v " , err )
83
+ slog . Error ( "failed to save username" , "err " , err )
84
84
}
85
85
}
86
86
}
@@ -142,7 +142,7 @@ func InitVM(
142
142
return "" , "" , nilTime , err
143
143
}
144
144
}
145
- debug . Log ( "username: %s " , username )
145
+ slog . Debug ( "initializing vm" , "user " , username )
146
146
147
147
// Record the start time for telemetry, now that we are done with prompting
148
148
// for GitHub username.
@@ -158,7 +158,7 @@ func InitVM(
158
158
if err != nil {
159
159
return "" , "" , nilTime , err
160
160
}
161
- debug . Log ( "vm_hostname: %s " , vmHostname )
161
+ slog . Debug ( "initializing vm" , "host " , vmHostname )
162
162
163
163
return username , vmHostname , telemetryShellStartTime , nil
164
164
}
@@ -222,23 +222,23 @@ func AutoPortForward(ctx context.Context, w io.Writer, projectDir, hostID string
222
222
func getGithubUsername () (string , error ) {
223
223
username , err := openssh .GithubUsernameFromLocalFile ()
224
224
if err == nil && username != "" {
225
- debug . Log ( "Username from locally-cached file: %s " , username )
225
+ slog . Debug ( "got username from locally-cached file" , "user " , username )
226
226
return username , nil
227
227
}
228
228
229
229
if err != nil {
230
- debug . Log ("failed to get auth.Username. Error: %v " , err )
230
+ slog . Debug ("failed to get auth.Username" , "err " , err )
231
231
}
232
232
username , err = queryGithubUsername ()
233
233
if err == nil && username != "" {
234
- debug . Log ( "Username from ssh -T [email protected] : %s ",
username )
234
+ slog . Debug ( "got username from ssh -T [email protected] " , "user ",
username )
235
235
return username , nil
236
236
}
237
237
238
238
// The query for GitHub username is best effort, and if it fails to resolve
239
239
// we fallback to prompting the user, and suggesting the local computer username.
240
240
if err != nil {
241
- debug . Log ("failed to query auth.Username. Error: %v " , err )
241
+ slog . Debug ("failed to query auth.Username" , "err " , err )
242
242
}
243
243
return promptUsername ()
244
244
}
@@ -253,7 +253,7 @@ func promptUsername() (string, error) {
253
253
if err != nil {
254
254
return "" , errors .WithStack (err )
255
255
}
256
- debug . Log ( "Username from prompting user: %s " , username )
256
+ slog . Debug ( "got username from prompt" , " user" , username )
257
257
return username , nil
258
258
}
259
259
@@ -283,7 +283,7 @@ func getVirtualMachine(sshCmd *openssh.Cmd) (vmUser, vmHost, region string, err
283
283
return "" , "" , "" , errors .Wrapf (err , "error unmarshalling gateway response %q" , sshOut )
284
284
}
285
285
if redacted , err := json .MarshalIndent (resp .redact (), "\t " , " " ); err == nil {
286
- debug . Log ("got gateway response: \n \t %s " , redacted )
286
+ slog . Debug ("got gateway response" , "resp " , redacted )
287
287
}
288
288
if resp .VMPrivateKey != "" {
289
289
err = openssh .AddVMKey (resp .VMHost , resp .VMPrivateKey )
@@ -300,7 +300,7 @@ func syncFiles(username, hostname, projectDir string) error {
300
300
return err
301
301
}
302
302
absPathInVM := absoluteProjectPathInVM (username , relProjectPathInVM )
303
- debug . Log ( "absPathInVM: %s " , absPathInVM )
303
+ slog . Debug ( "syncFiles absoluteProjectPathInVM" , "path " , absPathInVM )
304
304
305
305
err = copyConfigFileToVM (hostname , username , projectDir , absPathInVM )
306
306
if err != nil {
@@ -364,26 +364,26 @@ func updateSyncStatus(mutagenSessionName, username, hostname, relProjectPathInVM
364
364
mkdirCmd := openssh .Command (username , hostname )
365
365
_ , err := mkdirCmd .ExecRemote (fmt .Sprintf (`mkdir -p "%s"` , destDir ))
366
366
if err != nil {
367
- debug . Log ("error setting initial starship mutagen status: %v " , err )
367
+ slog . Error ("error setting initial starship mutagen status" , "err " , err )
368
368
}
369
369
370
370
// Set an initial status
371
371
displayableStatus := "initial sync"
372
372
statusCmd := openssh .Command (username , hostname )
373
373
_ , err = statusCmd .ExecRemote (fmt .Sprintf (`echo "%s" > "%s/mutagen_status.txt"` , displayableStatus , destDir ))
374
374
if err != nil {
375
- debug . Log ("error setting initial starship mutagen status: %v " , err )
375
+ slog . Error ("error setting initial starship mutagen status" , "err " , err )
376
376
}
377
377
time .Sleep (5 * time .Second )
378
378
379
- debug . Log ("Starting check for file sync status" )
379
+ slog . Debug ("Starting check for file sync status" )
380
380
for status != "watching" {
381
381
status , err = getSyncStatus (mutagenSessionName )
382
382
if err != nil {
383
- debug . Log ( "ERROR: getSyncStatus error is %s " , err )
383
+ slog . Error ( " getSyncStatus error" , "err " , err )
384
384
return
385
385
}
386
- debug . Log ("checking file sync status: %s " , status )
386
+ slog . Debug ("checking file sync status" , "status " , status )
387
387
388
388
if status == "watching" {
389
389
displayableStatus = "\" watching for changes\" "
@@ -392,7 +392,7 @@ func updateSyncStatus(mutagenSessionName, username, hostname, relProjectPathInVM
392
392
statusCmd := openssh .Command (username , hostname )
393
393
_ , err = statusCmd .ExecRemote (fmt .Sprintf (`echo "%s" > "%s/mutagen_status.txt"` , displayableStatus , destDir ))
394
394
if err != nil {
395
- debug . Log ("error setting initial starship mutagen status: %v " , err )
395
+ slog . Error ("error setting initial starship mutagen status" , "err " , err )
396
396
}
397
397
time .Sleep (5 * time .Second )
398
398
}
@@ -422,7 +422,7 @@ func copyConfigFileToVM(hostname, username, projectDir, pathInVM string) error {
422
422
// We retry a few times to avoid failing the command.
423
423
_ , err := mkdirCmd .ExecRemoteWithRetry (fmt .Sprintf (`mkdir -p "%s"` , pathInVM ), 5 , 4 )
424
424
if err != nil {
425
- debug . Log ("error copying config file to VM: %v " , err )
425
+ slog . Error ("error copying config file to VM" , "err " , err )
426
426
return errors .WithStack (err )
427
427
}
428
428
@@ -432,7 +432,7 @@ func copyConfigFileToVM(hostname, username, projectDir, pathInVM string) error {
432
432
destPath := fmt .Sprintf ("%s:%s" , destServer , pathInVM )
433
433
cmd := exec .Command ("scp" , configFilePath , destPath )
434
434
err = cmd .Run ()
435
- debug . Log ("scp devbox.json command: %s with error: %s" , cmd , err )
435
+ slog . Error ("scp devbox.json error" , "cmd" , cmd , "err" , err )
436
436
return errors .WithStack (err )
437
437
}
438
438
0 commit comments