Skip to content

Commit

Permalink
Support formats in logger
Browse files Browse the repository at this point in the history
Accept a third argument when creating a logger that sets the format
that messages in logs will be parsed as. Bumps agent to 8d042e2
  • Loading branch information
thijsc committed Feb 21, 2023
1 parent 918f2db commit 108fa2e
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 25 deletions.
8 changes: 8 additions & 0 deletions .changesets/bump-agent-to-8d042e2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
bump: "patch"
type: "change"
---

Bump agent to 8d042e2.

- Support multiple log formats.
6 changes: 4 additions & 2 deletions ext/appsignal_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,15 @@ Napi::Value Log(const Napi::CallbackInfo &info) {

Napi::String group = info[0].As<Napi::String>();
Napi::Number severity = info[1].As<Napi::Number>();
Napi::String message = info[2].As<Napi::String>();
Napi::Number format = info[2].As<Napi::Number>();
Napi::String message = info[3].As<Napi::String>();
Napi::External<appsignal_data_t> attributes =
info[3].As<Napi::External<appsignal_data_t>>();
info[4].As<Napi::External<appsignal_data_t>>();

appsignal_log(
MakeAppsignalString(group),
severity.Int32Value(),
format.Int32Value(),
MakeAppsignalString(message),
attributes.Data()
);
Expand Down
28 changes: 14 additions & 14 deletions scripts/extension/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// appsignal-agent repository.
// Modifications to this file will be overwritten with the next agent release.

const AGENT_VERSION = "0d593d5"
const AGENT_VERSION = "8d042e2"
const MIRRORS = [
"https://appsignal-agent-releases.global.ssl.fastly.net",
"https://d135dj0rjqvssy.cloudfront.net"
Expand All @@ -12,67 +12,67 @@ const MIRRORS = [
const TRIPLES = {
"x86_64-darwin": {
checksum:
"8e63a3b1ee61165914e6dbb8654c1ad7f096079c77d0559c1733dff15103f4ab",
"e0142859f35e31b52dcc57418636c05bcb21940ad499bbe255f90a1cf7359bf7",
filename: "appsignal-x86_64-darwin-all-static.tar.gz"
},
"universal-darwin": {
checksum:
"8e63a3b1ee61165914e6dbb8654c1ad7f096079c77d0559c1733dff15103f4ab",
"e0142859f35e31b52dcc57418636c05bcb21940ad499bbe255f90a1cf7359bf7",
filename: "appsignal-x86_64-darwin-all-static.tar.gz"
},
"aarch64-darwin": {
checksum:
"cdf323d1b411f45084c13dc4a2c0f980599273d64ab91a28cd07bbc48b3293f6",
"5a1ab02452497b29222d580f3e9d3649eb547b8c90338858462d4f221dd18ff9",
filename: "appsignal-aarch64-darwin-all-static.tar.gz"
},
"arm64-darwin": {
checksum:
"cdf323d1b411f45084c13dc4a2c0f980599273d64ab91a28cd07bbc48b3293f6",
"5a1ab02452497b29222d580f3e9d3649eb547b8c90338858462d4f221dd18ff9",
filename: "appsignal-aarch64-darwin-all-static.tar.gz"
},
"arm-darwin": {
checksum:
"cdf323d1b411f45084c13dc4a2c0f980599273d64ab91a28cd07bbc48b3293f6",
"5a1ab02452497b29222d580f3e9d3649eb547b8c90338858462d4f221dd18ff9",
filename: "appsignal-aarch64-darwin-all-static.tar.gz"
},
"aarch64-linux": {
checksum:
"a6baf7c586722c71c9d5ec885c8ca17da6b9fc9c5d7ab154a7b667f28d082a0f",
"0e85a0a13b9457c4ee1f316e92e8d95de9125bbaff90ceb826bcefaaffa413d9",
filename: "appsignal-aarch64-linux-all-static.tar.gz"
},
"i686-linux": {
checksum:
"c102053fe1f68af84d0b362bd892256981bc4a2dec7e12fec27ea57ba0efbda2",
"0e8a0490ca960bb8e57183156ed4999afbd70cf13c640fe96f9b0e25556075f1",
filename: "appsignal-i686-linux-all-static.tar.gz"
},
"x86-linux": {
checksum:
"c102053fe1f68af84d0b362bd892256981bc4a2dec7e12fec27ea57ba0efbda2",
"0e8a0490ca960bb8e57183156ed4999afbd70cf13c640fe96f9b0e25556075f1",
filename: "appsignal-i686-linux-all-static.tar.gz"
},
"x86_64-linux": {
checksum:
"8f3987d22f0fcbd466377e624aa645c5b9b0f4bbc88855ddb7076b09b9a8d42a",
"4eec193edeae76e0793789846112ac9127870c90a8ae6e47aa2a8490163733aa",
filename: "appsignal-x86_64-linux-all-static.tar.gz"
},
"x86_64-linux-musl": {
checksum:
"e353e165f828cb788c85199adb1b39f15c26406da948117a34b4944f6eabfabc",
"d91d1ed6e775cc00319fca0a4144dff064d31fb6a8a28dbb5027add44e4dab02",
filename: "appsignal-x86_64-linux-musl-all-static.tar.gz"
},
"aarch64-linux-musl": {
checksum:
"b08c5d65fbff05ac6838aa0ed4614b669701f009826652f7d67ab423fede0e44",
"0ff6702bd976871f610f39ff6c2dd73c4535b12c15c81c0d0afab7650e75922d",
filename: "appsignal-aarch64-linux-musl-all-static.tar.gz"
},
"x86_64-freebsd": {
checksum:
"f516b4c84274b9c56cbcb11c252685a4ef97b68b9fec6c189dde96fd37bbf515",
"d973edc7f13cdad2993c415f17a680a4de3288ce57fc5ae0c69ef3a1ccbb2856",
filename: "appsignal-x86_64-freebsd-all-static.tar.gz"
},
"amd64-freebsd": {
checksum:
"f516b4c84274b9c56cbcb11c252685a4ef97b68b9fec6c189dde96fd37bbf515",
"d973edc7f13cdad2993c415f17a680a4de3288ce57fc5ae0c69ef3a1ccbb2856",
filename: "appsignal-x86_64-freebsd-all-static.tar.gz"
}
}
Expand Down
51 changes: 50 additions & 1 deletion src/__tests__/logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from "../client"
import { BaseLogger, LoggerLevel } from "../logger"
import { BaseLogger, LoggerFormat, LoggerLevel } from "../logger"

describe("BaseLogger", () => {
let logger: BaseLogger
Expand Down Expand Up @@ -52,6 +52,36 @@ describe("BaseLogger", () => {
).toEqual(6)
})

it("defaults to a plaintext logger format", () => {
expect(logger.format).toEqual(0)
expect(client.integrationLogger.warn).not.toHaveBeenCalled()
})

it("sets a plaintext format level when the format is unknown and logs a warning", () => {
logger = new BaseLogger(
client,
"groupname",
"trace" as LoggerLevel,
"bacon" as LoggerFormat
)
expect(logger.format).toEqual(0)
expect(client.integrationLogger.warn).toHaveBeenCalledWith(
expect.stringContaining(`"bacon"`)
)
})

it("sets the right format for a known logger format", () => {
expect(
new BaseLogger(client, "groupname", "trace", "plaintext").format
).toEqual(0)
expect(
new BaseLogger(client, "groupname", "trace", "logfmt").format
).toEqual(1)
expect(new BaseLogger(client, "groupname", "trace", "json").format).toEqual(
2
)
})

it("logs to the extension if at or above the logger level", () => {
const attributes = { foo: "bar", number: 42, isAnswer: true }

Expand All @@ -66,26 +96,45 @@ describe("BaseLogger", () => {
expect(client.extension.log).toHaveBeenCalledWith(
"groupname",
3,
0,
"info message",
attributes
)
expect(client.extension.log).toHaveBeenCalledWith(
"groupname",
4,
0,
"log message",
attributes
)
expect(client.extension.log).toHaveBeenCalledWith(
"groupname",
5,
0,
"warn message",
attributes
)
expect(client.extension.log).toHaveBeenCalledWith(
"groupname",
6,
0,
"error message",
attributes
)
})

it("logs to the extension if at or above the logger level with a format", () => {
logger = new BaseLogger(client, "groupname", "info", "logfmt")

logger.info("info message")

expect(client.extension.log).toHaveBeenCalledTimes(1)
expect(client.extension.log).toHaveBeenCalledWith(
"groupname",
3,
1,
"info message",
{}
)
})
})
Loading

0 comments on commit 108fa2e

Please sign in to comment.