feat(server): include daemon version in logs (#2155)
Attach the running release to every entry so log history can show when daemon upgrades took effect.
This commit is contained in:
@@ -5,6 +5,7 @@ import path from "node:path";
|
|||||||
import { spawn } from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { resolveDaemonVersion } from "./daemon-version.js";
|
||||||
import { resolveLogConfig } from "./logger.js";
|
import { resolveLogConfig } from "./logger.js";
|
||||||
import { loadConfig } from "./config.js";
|
import { loadConfig } from "./config.js";
|
||||||
import type { PersistedConfig } from "./persisted-config.js";
|
import type { PersistedConfig } from "./persisted-config.js";
|
||||||
@@ -153,6 +154,24 @@ describe("loadConfig logger config", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("createRootLogger", () => {
|
describe("createRootLogger", () => {
|
||||||
|
it("includes the daemon version in child logger entries", async () => {
|
||||||
|
const paseoHome = await mkdtemp(path.join(tmpdir(), "paseo-logger-version-"));
|
||||||
|
|
||||||
|
const { stdout } = await runLoggerFixture(`
|
||||||
|
const logger = createRootLogger(undefined, { paseoHome: ${JSON.stringify(paseoHome)} });
|
||||||
|
logger.child({ name: "fixture" }).info("versioned child logger");
|
||||||
|
logger.flush();
|
||||||
|
`);
|
||||||
|
|
||||||
|
expect(JSON.parse(stdout)).toMatchObject({
|
||||||
|
pid: expect.any(Number),
|
||||||
|
hostname: expect.any(String),
|
||||||
|
daemonVersion: resolveDaemonVersion(),
|
||||||
|
name: "fixture",
|
||||||
|
msg: "versioned child logger",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("writes JSON to stdout by default and does not initialize file logging", async () => {
|
it("writes JSON to stdout by default and does not initialize file logging", async () => {
|
||||||
const paseoHome = await mkdtemp(path.join(tmpdir(), "paseo-logger-default-"));
|
const paseoHome = await mkdtemp(path.join(tmpdir(), "paseo-logger-default-"));
|
||||||
const missingLogDir = path.join(paseoHome, "logs");
|
const missingLogDir = path.join(paseoHome, "logs");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { mkdirSync } from "node:fs";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import pino from "pino";
|
import pino from "pino";
|
||||||
import pretty from "pino-pretty";
|
import pretty from "pino-pretty";
|
||||||
|
import { resolveDaemonVersion } from "./daemon-version.js";
|
||||||
import type { PersistedConfig } from "./persisted-config.js";
|
import type { PersistedConfig } from "./persisted-config.js";
|
||||||
import { resolvePaseoHome } from "./paseo-home.js";
|
import { resolvePaseoHome } from "./paseo-home.js";
|
||||||
|
|
||||||
@@ -180,13 +181,15 @@ export function createRootLogger(
|
|||||||
})
|
})
|
||||||
: pino.destination({ dest: config.file?.path ?? 1, sync: false });
|
: pino.destination({ dest: config.file?.path ?? 1, sync: false });
|
||||||
|
|
||||||
return pino(
|
const logger = pino(
|
||||||
{
|
{
|
||||||
level: config.file?.level ?? config.console.level,
|
level: config.file?.level ?? config.console.level,
|
||||||
redact: { paths: REDACT_PATHS, remove: true },
|
redact: { paths: REDACT_PATHS, remove: true },
|
||||||
},
|
},
|
||||||
stream,
|
stream,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return logger.child({ daemonVersion: resolveDaemonVersion() });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createChildLogger(parent: pino.Logger, name: string): pino.Logger {
|
export function createChildLogger(parent: pino.Logger, name: string): pino.Logger {
|
||||||
|
|||||||
Reference in New Issue
Block a user