Log output to disk

This commit is contained in:
Asher 2020-07-23 12:51:08 -05:00
parent 7c2ca7d03e
commit 2fa5037859
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
3 changed files with 29 additions and 2 deletions

View File

@ -72,6 +72,7 @@
"js-yaml": "^3.13.1",
"limiter": "^1.1.5",
"pem": "^1.14.2",
"rotating-file-stream": "^2.1.1",
"safe-compare": "^1.1.4",
"semver": "^7.1.3",
"tar": "^6.0.1",

View File

@ -1,6 +1,9 @@
import { logger, field } from "@coder/logger"
import { field, logger } from "@coder/logger"
import * as cp from "child_process"
import * as path from "path"
import * as rfs from "rotating-file-stream"
import { Emitter } from "../common/emitter"
import { paths } from "./util"
interface HandshakeMessage {
type: "handshake"
@ -140,8 +143,17 @@ export interface WrapperOptions {
export class WrapperProcess {
private process?: cp.ChildProcess
private started?: Promise<void>
private readonly logStdoutStream: rfs.RotatingFileStream
private readonly logStderrStream: rfs.RotatingFileStream
public constructor(private currentVersion: string, private readonly options?: WrapperOptions) {
const opts = {
size: "10M",
maxFiles: 10,
}
this.logStdoutStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stdout.log"), opts)
this.logStderrStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stderr.log"), opts)
ipcMain().onDispose(() => {
if (this.process) {
this.process.removeAllListeners()
@ -176,6 +188,15 @@ export class WrapperProcess {
public start(): Promise<void> {
if (!this.started) {
this.started = this.spawn().then((child) => {
// Log both to stdout and to the log directory.
if (child.stdout) {
child.stdout.pipe(this.logStdoutStream)
child.stdout.pipe(process.stdout)
}
if (child.stderr) {
child.stderr.pipe(this.logStderrStream)
child.stderr.pipe(process.stderr)
}
logger.debug(`spawned inner process ${child.pid}`)
ipcMain()
.handshake(child)
@ -205,7 +226,7 @@ export class WrapperProcess {
CODE_SERVER_PARENT_PID: process.pid.toString(),
NODE_OPTIONS: nodeOptions,
},
stdio: ["inherit", "inherit", "inherit", "ipc"],
stdio: ["ipc"],
})
}
}

View File

@ -6144,6 +6144,11 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^3.0.0"
inherits "^2.0.1"
rotating-file-stream@^2.1.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/rotating-file-stream/-/rotating-file-stream-2.1.3.tgz#4b3cc8f56ae70b3e30ccdb4ee6b14d95e66b02bb"
integrity sha512-zZ4Tkngxispo7DgiTqX0s4ChLtM3qET6iYsDA9tmgDEqJ3BFgRq/ZotsKEDAYQt9pAn9JwwqT27CSwQt3CTxNg==
run-async@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"