Log output to disk
This commit is contained in:
parent
7c2ca7d03e
commit
2fa5037859
@ -72,6 +72,7 @@
|
|||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
"limiter": "^1.1.5",
|
"limiter": "^1.1.5",
|
||||||
"pem": "^1.14.2",
|
"pem": "^1.14.2",
|
||||||
|
"rotating-file-stream": "^2.1.1",
|
||||||
"safe-compare": "^1.1.4",
|
"safe-compare": "^1.1.4",
|
||||||
"semver": "^7.1.3",
|
"semver": "^7.1.3",
|
||||||
"tar": "^6.0.1",
|
"tar": "^6.0.1",
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { logger, field } from "@coder/logger"
|
import { field, logger } from "@coder/logger"
|
||||||
import * as cp from "child_process"
|
import * as cp from "child_process"
|
||||||
|
import * as path from "path"
|
||||||
|
import * as rfs from "rotating-file-stream"
|
||||||
import { Emitter } from "../common/emitter"
|
import { Emitter } from "../common/emitter"
|
||||||
|
import { paths } from "./util"
|
||||||
|
|
||||||
interface HandshakeMessage {
|
interface HandshakeMessage {
|
||||||
type: "handshake"
|
type: "handshake"
|
||||||
@ -140,8 +143,17 @@ export interface WrapperOptions {
|
|||||||
export class WrapperProcess {
|
export class WrapperProcess {
|
||||||
private process?: cp.ChildProcess
|
private process?: cp.ChildProcess
|
||||||
private started?: Promise<void>
|
private started?: Promise<void>
|
||||||
|
private readonly logStdoutStream: rfs.RotatingFileStream
|
||||||
|
private readonly logStderrStream: rfs.RotatingFileStream
|
||||||
|
|
||||||
public constructor(private currentVersion: string, private readonly options?: WrapperOptions) {
|
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(() => {
|
ipcMain().onDispose(() => {
|
||||||
if (this.process) {
|
if (this.process) {
|
||||||
this.process.removeAllListeners()
|
this.process.removeAllListeners()
|
||||||
@ -176,6 +188,15 @@ export class WrapperProcess {
|
|||||||
public start(): Promise<void> {
|
public start(): Promise<void> {
|
||||||
if (!this.started) {
|
if (!this.started) {
|
||||||
this.started = this.spawn().then((child) => {
|
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}`)
|
logger.debug(`spawned inner process ${child.pid}`)
|
||||||
ipcMain()
|
ipcMain()
|
||||||
.handshake(child)
|
.handshake(child)
|
||||||
@ -205,7 +226,7 @@ export class WrapperProcess {
|
|||||||
CODE_SERVER_PARENT_PID: process.pid.toString(),
|
CODE_SERVER_PARENT_PID: process.pid.toString(),
|
||||||
NODE_OPTIONS: nodeOptions,
|
NODE_OPTIONS: nodeOptions,
|
||||||
},
|
},
|
||||||
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
stdio: ["ipc"],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6144,6 +6144,11 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
|
|||||||
hash-base "^3.0.0"
|
hash-base "^3.0.0"
|
||||||
inherits "^2.0.1"
|
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:
|
run-async@^2.4.0:
|
||||||
version "2.4.1"
|
version "2.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
|
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
|
||||||
|
Reference in New Issue
Block a user