@@ -34,6 +34,7 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
34
34
var (
35
35
sessionTokenFile string
36
36
urlFile string
37
+ logDir string
37
38
networkInfoDir string
38
39
networkInfoInterval time.Duration
39
40
)
@@ -129,13 +130,25 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
129
130
}
130
131
}
131
132
133
+ // The VS Code extension obtains the PID of the SSH process to
134
+ // read files to display logs and network info.
135
+ //
136
+ // We get the parent PID because it's assumed `ssh` is calling this
137
+ // command via the ProxyCommand SSH option.
138
+ pid := os .Getppid ()
139
+
132
140
var logger slog.Logger
133
- if r .verbose {
134
- logger = slog .Make (sloghuman .Sink (inv .Stdout )).Leveled (slog .LevelDebug )
141
+ if logDir != "" {
142
+ logFilePath := filepath .Join (logDir , fmt .Sprintf ("%d.log" , pid ))
143
+ logFile , err := fs .OpenFile (logFilePath , os .O_CREATE | os .O_WRONLY , 0o600 )
144
+ if err != nil {
145
+ return xerrors .Errorf ("open log file %q: %w" , logFilePath , err )
146
+ }
147
+ defer logFile .Close ()
148
+ logger = slog .Make (sloghuman .Sink (logFile )).Leveled (slog .LevelDebug )
135
149
}
136
-
137
150
if r .disableDirect {
138
- _ , _ = fmt . Fprintln ( inv . Stderr , "Direct connections disabled. " )
151
+ logger . Info ( ctx , "direct connections disabled" )
139
152
}
140
153
agentConn , err := client .DialWorkspaceAgent (ctx , agent .ID , & codersdk.DialWorkspaceAgentOptions {
141
154
Logger : logger ,
@@ -166,7 +179,7 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
166
179
//
167
180
// We get the parent PID because it's assumed `ssh` is calling this
168
181
// command via the ProxyCommand SSH option.
169
- networkInfoFilePath := filepath .Join (networkInfoDir , fmt .Sprintf ("%d.json" , os . Getppid () ))
182
+ networkInfoFilePath := filepath .Join (networkInfoDir , fmt .Sprintf ("%d.json" , pid ))
170
183
171
184
statsErrChan := make (chan error , 1 )
172
185
cb := func (start , end time.Time , virtual , _ map [netlogtype.Connection ]netlogtype.Counts ) {
@@ -213,6 +226,11 @@ func (r *RootCmd) vscodeSSH() *clibase.Cmd {
213
226
Description : "Specifies a directory to write network information periodically." ,
214
227
Value : clibase .StringOf (& networkInfoDir ),
215
228
},
229
+ {
230
+ Flag : "log-dir" ,
231
+ Description : "Specifies a directory to write logs to." ,
232
+ Value : clibase .StringOf (& logDir ),
233
+ },
216
234
{
217
235
Flag : "session-token-file" ,
218
236
Description : "Specifies a file that contains a session token." ,
0 commit comments