Skip to content

Commit 2fa5037

Browse files
committed
Log output to disk
1 parent 7c2ca7d commit 2fa5037

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"js-yaml": "^3.13.1",
7373
"limiter": "^1.1.5",
7474
"pem": "^1.14.2",
75+
"rotating-file-stream": "^2.1.1",
7576
"safe-compare": "^1.1.4",
7677
"semver": "^7.1.3",
7778
"tar": "^6.0.1",

src/node/wrapper.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { logger, field } from "@coder/logger"
1+
import { field, logger } from "@coder/logger"
22
import * as cp from "child_process"
3+
import * as path from "path"
4+
import * as rfs from "rotating-file-stream"
35
import { Emitter } from "../common/emitter"
6+
import { paths } from "./util"
47

58
interface HandshakeMessage {
69
type: "handshake"
@@ -140,8 +143,17 @@ export interface WrapperOptions {
140143
export class WrapperProcess {
141144
private process?: cp.ChildProcess
142145
private started?: Promise<void>
146+
private readonly logStdoutStream: rfs.RotatingFileStream
147+
private readonly logStderrStream: rfs.RotatingFileStream
143148

144149
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+
145157
ipcMain().onDispose(() => {
146158
if (this.process) {
147159
this.process.removeAllListeners()
@@ -176,6 +188,15 @@ export class WrapperProcess {
176188
public start(): Promise<void> {
177189
if (!this.started) {
178190
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+
}
179200
logger.debug(`spawned inner process ${child.pid}`)
180201
ipcMain()
181202
.handshake(child)
@@ -205,7 +226,7 @@ export class WrapperProcess {
205226
CODE_SERVER_PARENT_PID: process.pid.toString(),
206227
NODE_OPTIONS: nodeOptions,
207228
},
208-
stdio: ["inherit", "inherit", "inherit", "ipc"],
229+
stdio: ["ipc"],
209230
})
210231
}
211232
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6144,6 +6144,11 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
61446144
hash-base "^3.0.0"
61456145
inherits "^2.0.1"
61466146

6147+
rotating-file-stream@^2.1.1:
6148+
version "2.1.3"
6149+
resolved "https://registry.yarnpkg.com/rotating-file-stream/-/rotating-file-stream-2.1.3.tgz#4b3cc8f56ae70b3e30ccdb4ee6b14d95e66b02bb"
6150+
integrity sha512-zZ4Tkngxispo7DgiTqX0s4ChLtM3qET6iYsDA9tmgDEqJ3BFgRq/ZotsKEDAYQt9pAn9JwwqT27CSwQt3CTxNg==
6151+
61476152
run-async@^2.4.0:
61486153
version "2.4.1"
61496154
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"

0 commit comments

Comments
 (0)