Skip to content

Commit

Permalink
Support Winston child logger groups
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luismiramirez committed Feb 14, 2023
1 parent 6d81330 commit 266c53e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/__tests__/winston_transport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
12 changes: 11 additions & 1 deletion src/winston_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 266c53e

Please sign in to comment.