feat(logging): add structured server diagnostics
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Writable } from "node:stream";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createLogger } from "../src/index";
|
||||
|
||||
function captureLog() {
|
||||
let output = "";
|
||||
const destination = new Writable({
|
||||
write(chunk, _encoding, callback) {
|
||||
output += chunk.toString();
|
||||
callback();
|
||||
},
|
||||
});
|
||||
return { destination, read: () => JSON.parse(output.trim()) as Record<string, unknown> };
|
||||
}
|
||||
|
||||
describe("structured application logging", () => {
|
||||
it("emits service metadata and redacts credential fields", () => {
|
||||
const capture = captureLog();
|
||||
const logger = createLogger("account-manager-test", { destination: capture.destination });
|
||||
|
||||
logger.info({ token: "secret-token", apiKey: "secret-key", operation: "test" }, "Test event");
|
||||
|
||||
expect(capture.read()).toMatchObject({
|
||||
service: "account-manager-test",
|
||||
token: "[Redacted]",
|
||||
apiKey: "[Redacted]",
|
||||
operation: "test",
|
||||
msg: "Test event",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user