From 266c53eb0b5e7f1c3c7836771bb74b07c9f8abaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luismi=20Ram=C3=ADrez?= Date: Tue, 14 Feb 2023 11:08:25 +0100 Subject: [PATCH] Support Winston child logger groups When using the Winston transport for our logging feature, the child loggers with an assigned group will send such group to AppSignal when logging messages. --- ...logger-groups-when-using-the-winston-transport.md | 9 +++++++++ package-lock.json | 4 ++-- src/__tests__/winston_transport.test.ts | 4 ++-- src/winston_transport.ts | 12 +++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 .changesets/support-winston-child-logger-groups-when-using-the-winston-transport.md diff --git a/.changesets/support-winston-child-logger-groups-when-using-the-winston-transport.md b/.changesets/support-winston-child-logger-groups-when-using-the-winston-transport.md new file mode 100644 index 00000000..c8bb4252 --- /dev/null +++ b/.changesets/support-winston-child-logger-groups-when-using-the-winston-transport.md @@ -0,0 +1,9 @@ +--- +bump: "patch" +type: "add" +--- + +Support Winston child logger groups when using the Winston transport + +When using the Winston transport for our logging feature, the child loggers with an assigned group +will send the group to AppSignal when logging messages. diff --git a/package-lock.json b/package-lock.json index 97a584e2..f40e8d0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@appsignal/nodejs", - "version": "3.0.7", + "version": "3.0.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@appsignal/nodejs", - "version": "3.0.7", + "version": "3.0.9", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/src/__tests__/winston_transport.test.ts b/src/__tests__/winston_transport.test.ts index 52b08b24..7ba37199 100644 --- a/src/__tests__/winston_transport.test.ts +++ b/src/__tests__/winston_transport.test.ts @@ -41,10 +41,10 @@ describe("BaseLogger", () => { }) it("carries arguments passed to child loggers", () => { - const childLogger = logger.child({ child: "foo" }) + const childLogger = logger.child({ child: "foo", group: "childgroup" }) childLogger.info("child logger message", { argument: 123 }) expect(client.extension.log).toHaveBeenCalledWith( - "groupname", + "childgroup", 3, "child logger message", { child: "foo", argument: 123 } diff --git a/src/winston_transport.ts b/src/winston_transport.ts index 4561bade..bef73ca4 100644 --- a/src/winston_transport.ts +++ b/src/winston_transport.ts @@ -67,8 +67,18 @@ export class WinstonTransport extends Transport { const levelSeverity = severity(info[Symbol.for("level")]) const [message, attributes] = this.parseInfo(info) + let group = undefined + if (typeof attributes["group"] == "string") { + group = attributes["group"] + delete attributes["group"] + } - client.extension.log(this.#group, levelSeverity, message, attributes) + client.extension.log( + group || this.#group, + levelSeverity, + message, + attributes + ) callback() }