|
1 |
| -import { logger, field } from "@coder/logger" |
| 1 | +import { field, logger } from "@coder/logger" |
2 | 2 | import * as cp from "child_process"
|
| 3 | +import * as path from "path" |
| 4 | +import * as rfs from "rotating-file-stream" |
3 | 5 | import { Emitter } from "../common/emitter"
|
| 6 | +import { paths } from "./util" |
4 | 7 |
|
5 | 8 | interface HandshakeMessage {
|
6 | 9 | type: "handshake"
|
@@ -140,8 +143,17 @@ export interface WrapperOptions {
|
140 | 143 | export class WrapperProcess {
|
141 | 144 | private process?: cp.ChildProcess
|
142 | 145 | private started?: Promise<void>
|
| 146 | + private readonly logStdoutStream: rfs.RotatingFileStream |
| 147 | + private readonly logStderrStream: rfs.RotatingFileStream |
143 | 148 |
|
144 | 149 | public constructor(private currentVersion: string, private readonly options?: WrapperOptions) {
|
| 150 | + const opts = { |
| 151 | + size: "10M", |
| 152 | + maxFiles: 10, |
| 153 | + } |
| 154 | + this.logStdoutStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stdout.log"), opts) |
| 155 | + this.logStderrStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stderr.log"), opts) |
| 156 | + |
145 | 157 | ipcMain().onDispose(() => {
|
146 | 158 | if (this.process) {
|
147 | 159 | this.process.removeAllListeners()
|
@@ -176,6 +188,15 @@ export class WrapperProcess {
|
176 | 188 | public start(): Promise<void> {
|
177 | 189 | if (!this.started) {
|
178 | 190 | this.started = this.spawn().then((child) => {
|
| 191 | + // Log both to stdout and to the log directory. |
| 192 | + if (child.stdout) { |
| 193 | + child.stdout.pipe(this.logStdoutStream) |
| 194 | + child.stdout.pipe(process.stdout) |
| 195 | + } |
| 196 | + if (child.stderr) { |
| 197 | + child.stderr.pipe(this.logStderrStream) |
| 198 | + child.stderr.pipe(process.stderr) |
| 199 | + } |
179 | 200 | logger.debug(`spawned inner process ${child.pid}`)
|
180 | 201 | ipcMain()
|
181 | 202 | .handshake(child)
|
@@ -205,7 +226,7 @@ export class WrapperProcess {
|
205 | 226 | CODE_SERVER_PARENT_PID: process.pid.toString(),
|
206 | 227 | NODE_OPTIONS: nodeOptions,
|
207 | 228 | },
|
208 |
| - stdio: ["inherit", "inherit", "inherit", "ipc"], |
| 229 | + stdio: ["ipc"], |
209 | 230 | })
|
210 | 231 | }
|
211 | 232 | }
|
|
0 commit comments