@ogcio/fastify-logging-wrapper 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 4.0.1 (2024-10-01)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **fastify-logging-wrapper:** installed shared errors ([#5](https://github.com/ogcio/shared-node-utils/issues/5)) ([e76c452](https://github.com/ogcio/shared-node-utils/commit/e76c4522d3b5a64cb68bd3cf3e1c1ccd9d049b08))
12
+
13
+
14
+ ### Features
15
+
16
+ * **root:** startup repo ([7422a6c](https://github.com/ogcio/shared-node-utils/commit/7422a6c8a7d51722299e6cd61eebacefe2b80d6d))
@@ -1,5 +1,5 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
1
+ import { httpErrors } from "@fastify/sensible";
2
+ import { assert, afterEach, describe, it } from "vitest";
3
3
  import { LogErrorClasses } from "../src/logging-wrapper-entities.js";
4
4
  import {
5
5
  DEFAULT_METHOD,
@@ -11,117 +11,128 @@ import {
11
11
  parseLogEntry,
12
12
  runErrorTest,
13
13
  } from "./helpers/fastify-test-helpers.js";
14
- import { httpErrors } from '@fastify/sensible';
15
14
 
16
- test("Error data are correctly set", async (t) => {
17
- const { server, loggingDestination } = initializeServer();
18
- t.after(() => server.close());
19
- await runErrorTest({
20
- server,
21
- loggingDestination,
22
- inputStatusCode: "500",
23
- expectedStatusCode: 500,
24
- errorMessage: "WHoooopS!",
25
- expectedClass: LogErrorClasses.ServerError,
15
+ describe("Error data are correctly set", () => {
16
+ it("should pass", async () => {
17
+ const { server, loggingDestination } = initializeServer();
18
+ afterEach(() => server.close());
19
+ await runErrorTest({
20
+ server,
21
+ loggingDestination,
22
+ inputStatusCode: "500",
23
+ expectedStatusCode: 500,
24
+ errorMessage: "WHoooopS!",
25
+ expectedClass: LogErrorClasses.ServerError,
26
+ });
26
27
  });
27
28
  });
28
29
 
29
- test("Unknown Error route logs expected values", async (t) => {
30
- const { server, loggingDestination } = initializeServer();
31
- t.after(() => server.close());
32
- await runErrorTest({
33
- server,
34
- loggingDestination,
35
- inputStatusCode: "399",
36
- expectedStatusCode: 500,
37
- errorMessage: "Unknown!",
38
- expectedClass: LogErrorClasses.UnknownError,
30
+ describe("Unknown Error route logs expected values", () => {
31
+ it("should pass", async () => {
32
+ const { server, loggingDestination } = initializeServer();
33
+ afterEach(() => server.close());
34
+ await runErrorTest({
35
+ server,
36
+ loggingDestination,
37
+ inputStatusCode: "399",
38
+ expectedStatusCode: 500,
39
+ errorMessage: "Unknown!",
40
+ expectedClass: LogErrorClasses.UnknownError,
41
+ });
39
42
  });
40
43
  });
41
44
 
42
- test("400 Error route logs expected values", async (t) => {
43
- const { server, loggingDestination } = initializeServer();
44
- t.after(() => server.close());
45
- await runErrorTest({
46
- server,
47
- loggingDestination,
48
- inputStatusCode: "400",
49
- expectedStatusCode: 400,
50
- errorMessage: "Bad request!",
51
- expectedClass: LogErrorClasses.RequestError,
45
+ describe("400 Error route logs expected values", () => {
46
+ it("should pass", async () => {
47
+ const { server, loggingDestination } = initializeServer();
48
+ afterEach(() => server.close());
49
+ await runErrorTest({
50
+ server,
51
+ loggingDestination,
52
+ inputStatusCode: "400",
53
+ expectedStatusCode: 400,
54
+ errorMessage: "Bad request!",
55
+ expectedClass: LogErrorClasses.RequestError,
56
+ });
52
57
  });
53
58
  });
54
59
 
55
- test("422 Validation Error route logs expected values", async (t) => {
56
- const { server, loggingDestination } = initializeServer();
57
- t.after(() => server.close());
58
- await runErrorTest({
59
- server,
60
- loggingDestination,
61
- inputStatusCode: "422",
62
- expectedStatusCode: 422,
63
- errorMessage: "Bad request!",
64
- expectedClass: LogErrorClasses.ValidationError,
60
+ describe("422 Validation Error route logs expected values", () => {
61
+ it("should pass", async () => {
62
+ const { server, loggingDestination } = initializeServer();
63
+ afterEach(() => server.close());
64
+ await runErrorTest({
65
+ server,
66
+ loggingDestination,
67
+ inputStatusCode: "422",
68
+ expectedStatusCode: 422,
69
+ errorMessage: "Bad request!",
70
+ expectedClass: LogErrorClasses.ValidationError,
71
+ });
65
72
  });
66
73
  });
67
74
 
68
- test("Error without status code logs expected values", async (t) => {
69
- const { server, loggingDestination } = initializeServer();
70
- t.after(() => server.close());
71
- await runErrorTest({
72
- server,
73
- loggingDestination,
74
- inputStatusCode: undefined,
75
- expectedStatusCode: 500,
76
- errorMessage: "Unknown!",
77
- expectedClass: LogErrorClasses.UnknownError,
78
- expectedFastifyCode: "UNHANDLED_EXCEPTION",
75
+ describe("Error without status code logs expected values", () => {
76
+ it("should pass", async () => {
77
+ const { server, loggingDestination } = initializeServer();
78
+ afterEach(() => server.close());
79
+ await runErrorTest({
80
+ server,
81
+ loggingDestination,
82
+ inputStatusCode: undefined,
83
+ expectedStatusCode: 500,
84
+ errorMessage: "Unknown!",
85
+ expectedClass: LogErrorClasses.UnknownError,
86
+ expectedFastifyCode: "UNHANDLED_EXCEPTION",
87
+ });
79
88
  });
80
89
  });
81
90
 
82
- test("Life events error logs expected values", async (t) => {
83
- const { server, loggingDestination } = initializeServer();
84
- t.after(() => server.close());
85
- const response = await server.inject({
86
- method: DEFAULT_METHOD,
87
- url: "/life-events-error",
88
- });
91
+ describe("Life events error logs expected values", () => {
92
+ it("should pass", async () => {
93
+ const { server, loggingDestination } = initializeServer();
94
+ afterEach(() => server.close());
95
+ const response = await server.inject({
96
+ method: DEFAULT_METHOD,
97
+ url: "/life-events-error",
98
+ });
89
99
 
90
- assert.ok(typeof response !== "undefined");
91
- assert.equal(response.statusCode, 500);
92
- const loggedRecords = loggingDestination.getLoggedRecords();
93
- assert.equal(loggedRecords.length, 4);
94
- const mockErrorInstance = httpErrors.createError("mock");
95
- checkExpectedRequestEntry({
96
- requestLogEntry: loggedRecords[0],
97
- inputPath: "/life-events-error",
98
- });
100
+ assert.ok(typeof response !== "undefined");
101
+ assert.equal(response.statusCode, 500);
102
+ const loggedRecords = loggingDestination.getLoggedRecords();
103
+ assert.equal(loggedRecords.length, 4);
104
+ const mockErrorInstance = httpErrors.createError("mock");
105
+ checkExpectedRequestEntry({
106
+ requestLogEntry: loggedRecords[0],
107
+ inputPath: "/life-events-error",
108
+ });
99
109
 
100
- checkExpectedErrorEntry({
101
- errorLogEntry: loggedRecords[1],
102
- inputPath: "/life-events-error",
103
- errorClass: LogErrorClasses.ServerError,
104
- errorMessage: "mock",
105
- errorCode: mockErrorInstance.name,
106
- expectedLevelName: "ERROR",
107
- });
108
- const parsed = parseLogEntry(loggedRecords[1]);
109
- assert.equal(parsed.error.process, "TESTING");
110
- assert.equal(parsed.error.parent.message, "I am the parent");
111
- assert.equal(parsed.error.parent.name, "Error");
112
- assert.equal(typeof parsed.error.parent.stack, "string");
110
+ checkExpectedErrorEntry({
111
+ errorLogEntry: loggedRecords[1],
112
+ inputPath: "/life-events-error",
113
+ errorClass: LogErrorClasses.ServerError,
114
+ errorMessage: "mock",
115
+ errorCode: mockErrorInstance.name,
116
+ expectedLevelName: "ERROR",
117
+ });
118
+ const parsed = parseLogEntry(loggedRecords[1]);
119
+ assert.equal(parsed.error.process, "TESTING");
120
+ assert.equal(parsed.error.parent.message, "I am the parent");
121
+ assert.equal(parsed.error.parent.name, "Error");
122
+ assert.equal(typeof parsed.error.parent.stack, "string");
113
123
 
114
- checkExpectedResponseEntry({
115
- responseLogEntry: loggedRecords[2],
116
- inputPath: "/life-events-error",
117
- responseStatusCode: 500,
118
- });
119
- checkExpectedApiTrackEntry({
120
- apiTrackLogEntry: loggedRecords[3],
121
- inputPath: "/life-events-error",
122
- responseStatusCode: 500,
123
- errorClass: LogErrorClasses.ServerError,
124
- errorMessage: "mock",
125
- errorCode: mockErrorInstance.name,
124
+ checkExpectedResponseEntry({
125
+ responseLogEntry: loggedRecords[2],
126
+ inputPath: "/life-events-error",
127
+ responseStatusCode: 500,
128
+ });
129
+ checkExpectedApiTrackEntry({
130
+ apiTrackLogEntry: loggedRecords[3],
131
+ inputPath: "/life-events-error",
132
+ responseStatusCode: 500,
133
+ errorClass: LogErrorClasses.ServerError,
134
+ errorMessage: "mock",
135
+ errorCode: mockErrorInstance.name,
136
+ });
126
137
  });
127
138
  });
@@ -1,106 +1,121 @@
1
- import { LogMessages } from "../src/logging-wrapper-entities.js";
2
- import { initializeServer, DEFAULT_METHOD, DEFAULT_PATH, checkExpectedRequestEntry, checkExpectedResponseEntry, parseLogEntry, checkGenericEntryFields } from "./helpers/fastify-test-helpers.js";
3
1
  import { REQUEST_ID_HEADER } from "@ogcio/shared-errors";
4
- import assert from "node:assert";
5
- import { test } from 'node:test';
2
+ import { assert, afterEach, describe, it } from "vitest";
3
+ import { LogMessages } from "../src/logging-wrapper-entities.js";
4
+ import {
5
+ DEFAULT_METHOD,
6
+ DEFAULT_PATH,
7
+ checkExpectedRequestEntry,
8
+ checkExpectedResponseEntry,
9
+ checkGenericEntryFields,
10
+ initializeServer,
11
+ parseLogEntry,
12
+ } from "./helpers/fastify-test-helpers.js";
6
13
 
7
- test("Logging entries when all works fine are the expected ones", async (t) => {
8
- const { server, loggingDestination } = initializeServer();
9
- t.after(() => server.close());
14
+ describe("Logging entries when all works fine are the expected ones", () => {
15
+ it("should pass", async () => {
16
+ const { server, loggingDestination } = initializeServer();
17
+ afterEach(() => server.close());
10
18
 
11
- const response = await server.inject({
12
- method: DEFAULT_METHOD,
13
- url: DEFAULT_PATH,
14
- });
15
- assert.ok(typeof response !== "undefined");
16
- assert.equal(response?.statusCode, 200);
17
- const loggedRecords = loggingDestination.getLoggedRecords();
18
- assert.equal(loggedRecords.length, 3);
19
- checkExpectedRequestEntry({
20
- requestLogEntry: loggedRecords[0],
21
- });
22
- checkExpectedResponseEntry({
23
- responseLogEntry: loggedRecords[1],
24
- responseStatusCode: 200,
25
- });
26
- checkExpectedResponseEntry({
27
- responseLogEntry: loggedRecords[2],
28
- responseStatusCode: 200,
29
- expectedMessage: LogMessages.ApiTrack,
19
+ const response = await server.inject({
20
+ method: DEFAULT_METHOD,
21
+ url: DEFAULT_PATH,
22
+ });
23
+ assert.ok(typeof response !== "undefined");
24
+ assert.equal(response?.statusCode, 200);
25
+ const loggedRecords = loggingDestination.getLoggedRecords();
26
+ assert.equal(loggedRecords.length, 3);
27
+ checkExpectedRequestEntry({
28
+ requestLogEntry: loggedRecords[0],
29
+ });
30
+ checkExpectedResponseEntry({
31
+ responseLogEntry: loggedRecords[1],
32
+ responseStatusCode: 200,
33
+ });
34
+ checkExpectedResponseEntry({
35
+ responseLogEntry: loggedRecords[2],
36
+ responseStatusCode: 200,
37
+ expectedMessage: LogMessages.ApiTrack,
38
+ });
30
39
  });
31
40
  });
32
41
 
33
- test("Request id is overriden by header", async (t) => {
34
- const { server, loggingDestination } = initializeServer();
35
- t.after(() => server.close());
36
- const customRequestId = "Another request id";
37
- const response = await server.inject({
38
- method: DEFAULT_METHOD,
39
- url: DEFAULT_PATH,
40
- headers: { [REQUEST_ID_HEADER]: customRequestId },
41
- });
42
- assert.ok(typeof response !== "undefined");
43
- assert.equal(response?.statusCode, 200);
44
- const logged = loggingDestination.getLoggedRecords();
45
- checkExpectedRequestEntry({
46
- requestLogEntry: logged[0],
47
- inputHeaders: { [REQUEST_ID_HEADER]: customRequestId },
42
+ describe("Request id is overriden by header", () => {
43
+ it("should pass", async () => {
44
+ const { server, loggingDestination } = initializeServer();
45
+ afterEach(() => server.close());
46
+ const customRequestId = "Another request id";
47
+ const response = await server.inject({
48
+ method: DEFAULT_METHOD,
49
+ url: DEFAULT_PATH,
50
+ headers: { [REQUEST_ID_HEADER]: customRequestId },
51
+ });
52
+ assert.ok(typeof response !== "undefined");
53
+ assert.equal(response?.statusCode, 200);
54
+ const logged = loggingDestination.getLoggedRecords();
55
+ checkExpectedRequestEntry({
56
+ requestLogEntry: logged[0],
57
+ inputHeaders: { [REQUEST_ID_HEADER]: customRequestId },
58
+ });
59
+ const parsedEntry = parseLogEntry(logged[0]);
60
+ assert.deepEqual(parsedEntry.request_id, customRequestId);
48
61
  });
49
- const parsedEntry = parseLogEntry(logged[0]);
50
- assert.deepEqual(parsedEntry.request_id, customRequestId);
51
62
  });
52
63
 
53
- test("Logging context is reset between requests", async (t) => {
54
- const { server, loggingDestination } = initializeServer();
55
- t.after(() => server.close());
64
+ describe("Logging context is reset between requests", () => {
65
+ it("should pass", async () => {
66
+ const { server, loggingDestination } = initializeServer();
67
+ afterEach(() => server.close());
56
68
 
57
- let response = await server.inject({
58
- method: DEFAULT_METHOD,
59
- url: DEFAULT_PATH,
60
- });
69
+ let response = await server.inject({
70
+ method: DEFAULT_METHOD,
71
+ url: DEFAULT_PATH,
72
+ });
61
73
 
62
- assert.ok(typeof response !== "undefined");
63
- assert.equal(response?.statusCode, 200);
64
- let loggedRecords = loggingDestination.getLoggedRecords();
65
- assert.equal(loggedRecords.length, 3);
66
- let parsedResponse = parseLogEntry(loggedRecords[1]);
67
- assert.ok(typeof parsedResponse.response !== "undefined");
74
+ assert.ok(typeof response !== "undefined");
75
+ assert.equal(response?.statusCode, 200);
76
+ let loggedRecords = loggingDestination.getLoggedRecords();
77
+ assert.equal(loggedRecords.length, 3);
78
+ let parsedResponse = parseLogEntry(loggedRecords[1]);
79
+ assert.ok(typeof parsedResponse.response !== "undefined");
68
80
 
69
- response = await server.inject({
70
- method: DEFAULT_METHOD,
71
- url: DEFAULT_PATH,
81
+ response = await server.inject({
82
+ method: DEFAULT_METHOD,
83
+ url: DEFAULT_PATH,
84
+ });
85
+ assert.ok(typeof response !== "undefined");
86
+ assert.equal(response?.statusCode, 200);
87
+ loggedRecords = loggingDestination.getLoggedRecords();
88
+ assert.equal(loggedRecords.length, 6);
89
+ // 3 is the New Request for 2nd call
90
+ parsedResponse = parseLogEntry(loggedRecords[3]);
91
+ // if undefined it means that the logging context
92
+ // has been reset between requests
93
+ assert.ok(typeof parsedResponse.response === "undefined");
72
94
  });
73
- assert.ok(typeof response !== "undefined");
74
- assert.equal(response?.statusCode, 200);
75
- loggedRecords = loggingDestination.getLoggedRecords();
76
- assert.equal(loggedRecords.length, 6);
77
- // 3 is the New Request for 2nd call
78
- parsedResponse = parseLogEntry(loggedRecords[3]);
79
- // if undefined it means that the logging context
80
- // has been reset between requests
81
- assert.ok(typeof parsedResponse.response === "undefined");
82
95
  });
83
96
 
84
- test("Additional logs are correctly written", async (t) => {
85
- const { server, loggingDestination } = initializeServer();
86
- t.after(() => server.close());
87
- const logMessage = "Testing additional logs";
97
+ describe("Additional logs are correctly written", () => {
98
+ it("should pass", async () => {
99
+ const { server, loggingDestination } = initializeServer();
100
+ afterEach(() => server.close());
101
+ const logMessage = "Testing additional logs";
88
102
 
89
- const response = await server.inject({
90
- method: "POST",
91
- url: "/logs",
92
- body: { log_entry: logMessage },
93
- });
103
+ const response = await server.inject({
104
+ method: "POST",
105
+ url: "/logs",
106
+ body: { log_entry: logMessage },
107
+ });
94
108
 
95
- assert.ok(typeof response !== "undefined");
96
- assert.equal(response?.statusCode, 200);
97
- const loggedRecords = loggingDestination.getLoggedRecords();
98
- assert.equal(loggedRecords.length, 4);
99
- const parsedAdditional = parseLogEntry(loggedRecords[1]);
100
- checkGenericEntryFields({
101
- parsedEntry: parsedAdditional,
102
- expectedLevelName: "INFO",
103
- expectedMessage: logMessage,
109
+ assert.ok(typeof response !== "undefined");
110
+ assert.equal(response?.statusCode, 200);
111
+ const loggedRecords = loggingDestination.getLoggedRecords();
112
+ assert.equal(loggedRecords.length, 4);
113
+ const parsedAdditional = parseLogEntry(loggedRecords[1]);
114
+ checkGenericEntryFields({
115
+ parsedEntry: parsedAdditional,
116
+ expectedLevelName: "INFO",
117
+ expectedMessage: logMessage,
118
+ });
119
+ assert.ok(typeof parsedAdditional.request !== "undefined");
104
120
  });
105
- assert.ok(typeof parsedAdditional.request !== "undefined");
106
121
  });
@@ -1,11 +1,11 @@
1
+ import { createError } from "@fastify/error";
2
+ import { httpErrors } from "@fastify/sensible";
1
3
  import Fastify from "fastify";
4
+ import type { DestinationStream } from "pino";
2
5
  import {
3
6
  getLoggingConfiguration,
4
7
  initializeLoggingHooks,
5
8
  } from "../../src/fastify-logging-wrapper.js";
6
- import { DestinationStream } from "pino";
7
- import { createError } from "@fastify/error";
8
- import { httpErrors } from "@fastify/sensible";
9
9
 
10
10
  export const buildFastify = (loggerDestination?: DestinationStream) => {
11
11
  const server = Fastify({
@@ -20,17 +20,17 @@ export const buildFastify = (loggerDestination?: DestinationStream) => {
20
20
 
21
21
  server.get("/error", async (request, _reply) => {
22
22
  const parsed = request.query as { [x: string]: unknown };
23
- const requestedStatusCode = Number(parsed["status_code"] ?? "500");
24
- const requestedMessage = String(parsed["error_message"] ?? "WHOOOPS");
23
+ const requestedStatusCode = Number(parsed.status_code ?? "500");
24
+ const requestedMessage = String(parsed.error_message ?? "WHOOOPS");
25
25
 
26
- if (!parsed["status_code"]) {
26
+ if (!parsed.status_code) {
27
27
  throw new Error(requestedMessage);
28
28
  }
29
29
 
30
30
  throw createError(
31
31
  "CUSTOM_CODE",
32
32
  requestedMessage as string,
33
- requestedStatusCode as number
33
+ requestedStatusCode as number,
34
34
  )();
35
35
  });
36
36
 
@@ -1,4 +1,4 @@
1
- import { PinoLoggerOptions } from "fastify/types/logger.js";
1
+ import type { PinoLoggerOptions } from "fastify/types/logger.js";
2
2
  import { pino } from "pino";
3
3
 
4
4
  export const buildLogger = (loggerConfiguration: PinoLoggerOptions) => {
@@ -1,14 +1,14 @@
1
- import { FastifyInstance } from "fastify";
1
+ import type { FastifyInstance } from "fastify";
2
+ import { assert } from "vitest";
3
+ import {
4
+ type LogErrorClasses,
5
+ LogMessages,
6
+ } from "../../src/logging-wrapper-entities.js";
2
7
  import { buildFastify } from "./build-fastify.js";
3
8
  import {
4
- TestingLoggerDestination,
9
+ type TestingLoggerDestination,
5
10
  getTestingDestinationLogger,
6
11
  } from "./build-logger.js";
7
- import {
8
- LogErrorClasses,
9
- LogMessages,
10
- } from "../../src/logging-wrapper-entities.js";
11
- import assert from 'node:assert/strict';
12
12
 
13
13
  export const DEFAULT_HOSTNAME = "localhost:80";
14
14
  export const DEFAULT_USER_AGENT = "lightMyRequest";
@@ -32,7 +32,7 @@ export const initializeServer = (): {
32
32
  return { server, loggingDestination };
33
33
  };
34
34
 
35
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
36
36
  export const parseLogEntry = (logEntry: string): { [x: string]: any } =>
37
37
  JSON.parse(logEntry);
38
38
 
@@ -75,7 +75,10 @@ export const checkExpectedRequestEntry = (params: {
75
75
  assert.equal(parsed.request?.method, params.inputMethod);
76
76
  assert.equal(parsed.request?.path, params.inputPath);
77
77
  assert.equal(parsed.request?.hostname, DEFAULT_HOSTNAME);
78
- assert.deepStrictEqual(parsed.request?.query_params, params.inputQueryParams ?? {});
78
+ assert.deepStrictEqual(
79
+ parsed.request?.query_params,
80
+ params.inputQueryParams ?? {},
81
+ );
79
82
  assert.deepStrictEqual(parsed.request?.headers, {
80
83
  ...DEFAULT_REQUEST_HEADERS,
81
84
  ...(params.inputHeaders ?? {}),
@@ -108,7 +111,10 @@ export const checkExpectedResponseEntry = (params: {
108
111
  assert.equal(parsed.request.method, params.inputMethod);
109
112
  assert.equal(parsed.request.path, params.inputPath);
110
113
  assert.equal(parsed.request.hostname, DEFAULT_HOSTNAME);
111
- assert.deepStrictEqual(parsed.request.query_params, params.inputQueryParams ?? {});
114
+ assert.deepStrictEqual(
115
+ parsed.request.query_params,
116
+ params.inputQueryParams ?? {},
117
+ );
112
118
  assert.ok(typeof parsed.response !== "undefined");
113
119
  assert.equal(parsed.response.status_code, params.responseStatusCode);
114
120
  assert.equal(parsed.response.headers["content-type"], DEFAULT_CONTENT_TYPE);
@@ -173,7 +179,10 @@ export const checkExpectedErrorEntry = (params: {
173
179
  assert.equal(parsed.request?.method, params.inputMethod);
174
180
  assert.equal(parsed.request?.path, params.inputPath);
175
181
  assert.equal(parsed.request?.hostname, DEFAULT_HOSTNAME);
176
- assert.deepStrictEqual(parsed.request?.query_params, params.inputQueryParams ?? {});
182
+ assert.deepStrictEqual(
183
+ parsed.request?.query_params,
184
+ params.inputQueryParams ?? {},
185
+ );
177
186
  assert.ok(typeof parsed.error !== "undefined");
178
187
  assert.equal(parsed.error.class, params.errorClass);
179
188
  assert.equal(parsed.error.code, params.errorCode);
@@ -1,10 +1,8 @@
1
- import { Level } from "pino";
2
- import { getLoggerConfiguration } from "../src/logging-wrapper.js";
3
- import { buildLogger } from "./helpers/build-logger.js";
4
1
  import { hostname } from "os";
2
+ import { assert, describe, it } from "vitest";
5
3
  import { REDACTED_VALUE } from "../src/logging-wrapper-entities.js";
6
- import assert from "node:assert";
7
- import { test } from "node:test";
4
+ import { getLoggerConfiguration } from "../src/logging-wrapper.js";
5
+ import { buildLogger } from "./helpers/build-logger.js";
8
6
 
9
7
  const getRandomFieldValue = () => Math.random().toString(36).slice(2);
10
8
 
@@ -106,63 +104,74 @@ const methodsDataProvider = [
106
104
  },
107
105
  ];
108
106
 
109
- test("Basic format is the expected one", async (t) => {
110
- const { logger, loggedRecordsMethod } = buildLogger({
111
- ...getLoggerConfiguration("debug"),
112
- });
113
- logger.debug("test message");
114
- logger.info("another message");
107
+ describe("Basic format is the expected one", () => {
108
+ it("should pass", async () => {
109
+ const { logger, loggedRecordsMethod } = buildLogger({
110
+ ...getLoggerConfiguration({ level: "debug" }),
111
+ });
112
+ logger.debug("test message");
113
+ logger.info("another message");
115
114
 
116
- const loggedRecords = loggedRecordsMethod();
117
- assert.strictEqual(loggedRecords.length, 2);
115
+ const loggedRecords = loggedRecordsMethod();
116
+ assert.strictEqual(loggedRecords.length, 2);
118
117
 
119
- const parsed = JSON.parse(loggedRecords[0]);
120
- assert.strictEqual(typeof parsed.timestamp, "number");
121
- assert.ok(
122
- parsed.timestamp > Date.now() - 2000,
123
- "the timestamp must be newer than 2 seconds ago",
124
- );
125
- delete parsed.timestamp;
126
- assert.deepStrictEqual(parsed, {
127
- level: 20,
128
- level_name: "DEBUG",
129
- hostname: hostname(),
130
- message: "test message",
118
+ const parsed = JSON.parse(loggedRecords[0]);
119
+ assert.strictEqual(typeof parsed.timestamp, "number");
120
+ assert.ok(
121
+ parsed.timestamp > Date.now() - 2000,
122
+ "the timestamp must be newer than 2 seconds ago",
123
+ );
124
+ // biome-ignore lint/performance/noDelete: Would change behaviour of the test
125
+ delete parsed.timestamp;
126
+ assert.deepStrictEqual(parsed, {
127
+ level: 20,
128
+ level_name: "DEBUG",
129
+ hostname: hostname(),
130
+ message: "test message",
131
+ });
131
132
  });
132
133
  });
133
134
 
134
- test("Fields are redacted as expected", async (t) => {
135
- const { logger, loggedRecordsMethod } = buildLogger({
136
- ...getLoggerConfiguration(),
137
- });
138
- logger.warn(toRedactFields.input_value);
135
+ describe("Fields are redacted as expected", () => {
136
+ it("should pass", async () => {
137
+ const { logger, loggedRecordsMethod } = buildLogger({
138
+ ...getLoggerConfiguration(),
139
+ });
140
+ logger.warn(toRedactFields.input_value);
139
141
 
140
- const loggedRecords = loggedRecordsMethod();
141
- const parsed = JSON.parse(loggedRecords[0]);
142
- delete parsed.hostname;
143
- delete parsed.level;
144
- delete parsed.level_name;
145
- delete parsed.timestamp;
142
+ const loggedRecords = loggedRecordsMethod();
143
+ const parsed = JSON.parse(loggedRecords[0]);
144
+ // biome-ignore lint/performance/noDelete: Would change behaviour of the test
145
+ delete parsed.hostname;
146
+ // biome-ignore lint/performance/noDelete: Would change behaviour of the test
147
+ delete parsed.level;
148
+ // biome-ignore lint/performance/noDelete: Would change behaviour of the test
149
+ delete parsed.level_name;
150
+ // biome-ignore lint/performance/noDelete: Would change behaviour of the test
151
+ delete parsed.timestamp;
146
152
 
147
- assert.deepStrictEqual(parsed, toRedactFields.expected_output);
153
+ assert.deepStrictEqual(parsed, toRedactFields.expected_output);
154
+ });
148
155
  });
149
156
 
150
- methodsDataProvider.forEach((methodDataProvider) =>
151
- test(`Methods are writing correct levels - ${methodDataProvider.method}`, async (t) => {
152
- const { logger, loggedRecordsMethod } = buildLogger({
153
- ...getLoggerConfiguration("trace"),
154
- });
157
+ for (const methodDataProvider of methodsDataProvider) {
158
+ describe(`Methods are writing correct levels - ${methodDataProvider.method}`, () => {
159
+ it("should pass", async () => {
160
+ const { logger, loggedRecordsMethod } = buildLogger({
161
+ ...getLoggerConfiguration({ level: "trace" }),
162
+ });
155
163
 
156
- logger[methodDataProvider.method]("test");
164
+ logger[methodDataProvider.method]("test");
157
165
 
158
- const loggedRecords = loggedRecordsMethod();
159
- assert.strictEqual(loggedRecords.length, 1);
160
- const parsed = JSON.parse(loggedRecords[0]);
166
+ const loggedRecords = loggedRecordsMethod();
167
+ assert.strictEqual(loggedRecords.length, 1);
168
+ const parsed = JSON.parse(loggedRecords[0]);
161
169
 
162
- assert.strictEqual(parsed.level, methodDataProvider.expected.level);
163
- assert.strictEqual(
164
- parsed.level_name,
165
- methodDataProvider.expected.level_name,
166
- );
167
- }),
168
- );
170
+ assert.strictEqual(parsed.level, methodDataProvider.expected.level);
171
+ assert.strictEqual(
172
+ parsed.level_name,
173
+ methodDataProvider.expected.level_name,
174
+ );
175
+ });
176
+ });
177
+ }
@@ -1,5 +1,6 @@
1
- import { FastifyServerOptions, FastifyInstance } from "fastify";
2
- import { DestinationStream } from "pino";
1
+ import type { FastifyInstance, FastifyServerOptions } from "fastify";
2
+ import type { PinoLoggerOptions } from "fastify/types/logger.js";
3
+ import { type DestinationStream } from "pino";
3
4
  export declare const initializeLoggingHooks: (server: FastifyInstance) => void;
4
- export declare const getLoggingConfiguration: (loggerDestination?: DestinationStream) => FastifyServerOptions;
5
+ export declare const getLoggingConfiguration: (loggerDestination?: DestinationStream, customLoggerOptions?: PinoLoggerOptions) => FastifyServerOptions;
5
6
  //# sourceMappingURL=fastify-logging-wrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastify-logging-wrapper.d.ts","sourceRoot":"","sources":["../src/fastify-logging-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAchE,OAAO,EAAQ,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAK/C,eAAO,MAAM,sBAAsB,WAAY,eAAe,KAAG,IA6BhE,CAAC;AAEF,eAAO,MAAM,uBAAuB,uBACd,iBAAiB,KACpC,oBAMD,CAAC"}
1
+ {"version":3,"file":"fastify-logging-wrapper.d.ts","sourceRoot":"","sources":["../src/fastify-logging-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,EAAE,KAAK,iBAAiB,EAAQ,MAAM,MAAM,CAAC;AAgBpD,eAAO,MAAM,sBAAsB,WAAY,eAAe,KAAG,IA6BhE,CAAC;AAEF,eAAO,MAAM,uBAAuB,uBACd,iBAAiB,wBACf,iBAAiB,KACtC,oBAMD,CAAC"}
@@ -1,8 +1,8 @@
1
+ import { REQUEST_ID_HEADER } from "@ogcio/shared-errors";
1
2
  import hyperid from "hyperid";
3
+ import { pino } from "pino";
2
4
  import { LogMessages, REQUEST_ID_LOG_LABEL, } from "./logging-wrapper-entities.js";
3
5
  import { getLoggerConfiguration, getLoggingContextError, getPartialLoggingContextError, parseFullLoggingRequest, resetLoggingContext, setLoggingContext, } from "./logging-wrapper.js";
4
- import { pino } from "pino";
5
- import { REQUEST_ID_HEADER } from "@ogcio/shared-errors";
6
6
  const hyperidInstance = hyperid({ fixedLength: true, urlSafe: true });
7
7
  export const initializeLoggingHooks = (server) => {
8
8
  server.addHook("preHandler", (request, _reply, done) => {
@@ -24,8 +24,8 @@ export const initializeLoggingHooks = (server) => {
24
24
  done();
25
25
  });
26
26
  };
27
- export const getLoggingConfiguration = (loggerDestination) => ({
28
- logger: pino(getLoggerConfiguration(), loggerDestination),
27
+ export const getLoggingConfiguration = (loggerDestination, customLoggerOptions) => ({
28
+ logger: pino(getLoggerConfiguration(customLoggerOptions), loggerDestination),
29
29
  disableRequestLogging: true,
30
30
  genReqId: () => hyperidInstance(),
31
31
  requestIdLogLabel: REQUEST_ID_LOG_LABEL,
@@ -1 +1 @@
1
- {"version":3,"file":"fastify-logging-wrapper.js","sourceRoot":"","sources":["../src/fastify-logging-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EACL,WAAW,EACX,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAqB,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,eAAe,GAAG,OAAO,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,MAAuB,EAAQ,EAAE;IACtE,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QACrD,iBAAiB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,CACd,EAAE,OAAO,EAAE,uBAAuB,CAAC,OAAO,CAAC,EAAE,EAC7C,WAAW,CAAC,UAAU,CACvB,CAAC;QACF,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACjD,iBAAiB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,C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AE,sBAAsB,EAAE,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;QAE1E,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,iBAAqC,EACrC,mBAAuC,EACjB,EAAE,CAAC,CAAC;IAC1B,MAAM,EAAE,IAAI,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,EAAE,iBAAiB,CAAC;IAC5E,qBAAqB,EAAE,IAAI;IAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE;IACjC,iBAAiB,EAAE,oBAAoB;IACvC,eAAe,EAAE,iBAAiB;CACnC,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { getLoggingConfiguration, initializeLoggingHooks, } from "./fastify-logging-wrapper.js";
2
2
  export { toLoggingError, LogMessages, LoggingError, } from "./logging-wrapper-entities.js";
3
- export { getLoggingContextError, setLoggingContext } from "./logging-wrapper.js";
3
+ export { getLoggingContextError, setLoggingContext, } from "./logging-wrapper.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { getLoggingConfiguration, initializeLoggingHooks, } from "./fastify-logging-wrapper.js";
2
2
  export { toLoggingError, LogMessages, } from "./logging-wrapper-entities.js";
3
- export { getLoggingContextError, setLoggingContext } from "./logging-wrapper.js";
3
+ export { getLoggingContextError, setLoggingContext, } from "./logging-wrapper.js";
4
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,WAAW,GAEZ,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,WAAW,GAEZ,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { FastifyError } from "fastify";
2
- import { HttpError } from "@fastify/sensible";
1
+ import type { FastifyError } from "fastify";
2
+ import type { HttpError } from "@fastify/sensible";
3
3
  export interface LoggingRequest {
4
4
  scheme: string;
5
5
  method: string;
@@ -1 +1 @@
1
- {"version":3,"file":"logging-wrapper-entities.d.ts","sourceRoot":"","sources":["../src/logging-wrapper-entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAG7C,MAAM,W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cAAc;IAC7B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,oBAAY,WAAW;IACrB,UAAU,gBAAgB;IAC1B,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,QAAQ,cAAc;CACvB;AAED,oBAAY,eAAe;IACzB,WAAW,iBAAiB;IAC5B,eAAe,qBAAqB;IACpC,YAAY,kBAAkB;IAC9B,YAAY,kBAAkB;IAC9B,YAAY,kBAAkB;CAC/B;AAED,eAAO,MAAM,cAAc,eAAe,CAAC;AAE3C,eAAO,MAAM,cAAc,UAO1B,CAAC;AAEF,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAIjD,eAAO,MAAM,cAAc,UAClB,SAAS,GAAG,YAAY,KAC9B,YAyBF,CAAC"}
@@ -1,4 +1,4 @@
1
- import { parseErrorForLogging, } from "@ogcio/shared-errors";
1
+ import { parseErrorForLogging } from "@ogcio/shared-errors";
2
2
  import { isHttpError } from "http-errors";
3
3
  export var LogMessages;
4
4
  (function (LogMessages) {
@@ -1 +1 @@
1
- {"version":3,"file":"logging-wrapper-entities.js","sourceRoot":"","sources":["../src/logging-wrapper-entities.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AAqCxC,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,yCAA0B,CAAA;IAC1B,oCAAqB,CAAA;IACrB,8BAAe,CAAA;IACf,qCAAsB,CAAA;AACxB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAED,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,+CAA4B,CAAA;IAC5B,uDAAoC,CAAA;IACpC,iDAA8B,CAAA;IAC9B,iDAA8B,CAAA;IA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C;IACtC,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE5C,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QACvB,OAAO,eAAe,CAAC,YAAY,CAAC;IACtC,CAAC;IAED,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;QACtB,OAAO,eAAe,CAAC,WAAW,CAAC;IACrC,CAAC;IAED,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QACvB,OAAO,eAAe,CAAC,eAAe,CAAC;IACzC,CAAC;IAED,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;QACtB,OAAO,eAAe,CAAC,YAAY,CAAC;IACtC,CAAC;IAED,OAAO,eAAe,CAAC,YAAY,CAAC;AACtC,CAAC,CAAC"}
1
+ {"version":3,"file":"logging-wrapper-entities.js","sourceRoot":"","sources":["../src/logging-wrapper-entities.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAqC1C,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,yCAA0B,CAAA;IAC1B,oCAAqB,CAAA;IACrB,8BAAe,CAAA;IACf,qCAAsB,CAAA;AACxB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAED,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,+CAA4B,CAAA;IAC5B,uDAAoC,CAAA;IACpC,iDAA8B,CAAA;IAC9B,iDAA8B,CAAA;IAC9B,iDAA8B,CAAA;AAChC,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3C,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,mCAAmC;IACnC,wBAAwB;IACxB,4BAA4B;IAC5B,qBAAqB;IACrB,yBAAyB;IACzB,kCAAkC;CACnC,CAAC;AAE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;IACrC,CAAC;IAED,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QACvB,OAAO,eAAe,CAAC,eAAe,CAAC;IACzC,CAAC;IAED,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;QACtB,OAAO,eAAe,CAAC,YAAY,CAAC;IACtC,CAAC;IAED,OAAO,eAAe,CAAC,YAAY,CAAC;AACtC,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
- import { FastifyRequest, FastifyReply, FastifyError } from "fastify";
2
- import { LoggingContext, FullLoggingRequest, LoggingError } from "./logging-wrapper-entities.js";
3
- import { LogLevel, PinoLoggerOptions } from "fastify/types/logger.js";
4
- import { HttpError } from "@fastify/sensible";
1
+ import type { HttpError } from "@fastify/sensible";
2
+ import type { FastifyError, FastifyReply, FastifyRequest } from "fastify";
3
+ import type { PinoLoggerOptions } from "fastify/types/logger.js";
4
+ import { type FullLoggingRequest, type LoggingContext, type LoggingError } from "./logging-wrapper-entities.js";
5
5
  type INPUT_ERROR_TYPES = FastifyError | HttpError;
6
6
  export declare const getLoggingContext: (params: {
7
7
  includeError: boolean;
@@ -15,6 +15,6 @@ export declare const resetLoggingContext: () => void;
15
15
  export declare const getLoggingContextError: () => LoggingError | undefined;
16
16
  export declare const getPartialLoggingContextError: () => Omit<LoggingError, "trace"> | undefined;
17
17
  export declare const parseFullLoggingRequest: (req: FastifyRequest) => FullLoggingRequest;
18
- export declare const getLoggerConfiguration: (minimumLevel?: LogLevel) => PinoLoggerOptions;
18
+ export declare const getLoggerConfiguration: (customLoggerOptions?: PinoLoggerOptions) => PinoLoggerOptions;
19
19
  export {};
20
20
  //# sourceMappingURL=logging-wrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logging-wrapper.d.ts","sourceRoot":"","sources":["../src/logging-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAErE,OAAO,EACL,cAAc,EAEd,kBAA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;IACxC,YAAY,EAAE,OAAO,CAAC;CACvB,KAAG,cAGyC,CAAC;AAE9C,eAAO,MAAM,iBAAiB,WAAY;IACxC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B,KAAG,IAUH,CAAC;AAEF,eAAO,MAAM,mBAAmB,QAAO,IAItC,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAO,YAAY,GAAG,SACR,CAAC;AAElD,eAAO,MAAM,6BAA6B,QACtC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,GAC3B,SAGF,CAAC;AAaH,eAAO,MAAM,uBAAuB,QAC7B,cAAc,KAClB,kBAKD,CAAC;AAOH,eAAO,MAAM,sBAAsB,yBACX,iBAAiB,KACtC,iBAmBD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { hostname } from "os";
2
- import { REDACTED_VALUE, REDACTED_PATHS, MESSAGE_KEY, toLoggingError, } from "./logging-wrapper-entities.js";
2
+ import { MESSAGE_KEY, REDACTED_PATHS, REDACTED_VALUE, toLoggingError, } from "./logging-wrapper-entities.js";
3
3
  const loggingContext = {};
4
4
  export const getLoggingContext = (params) => params.includeError
5
5
  ? loggingContext
@@ -43,7 +43,7 @@ const parseLoggingResponse = (res) => ({
43
43
  status_code: res.statusCode,
44
44
  headers: res.getHeaders(),
45
45
  });
46
- export const getLoggerConfiguration = (minimumLevel = "debug") => ({
46
+ export const getLoggerConfiguration = (customLoggerOptions) => ({
47
47
  base: { hostname: hostname() },
48
48
  messageKey: MESSAGE_KEY,
49
49
  mixin: () => ({
@@ -61,6 +61,6 @@ export const getLoggerConfiguration = (minimumLevel = "debug") => ({
61
61
  level_name: name.toUpperCase(),
62
62
  }),
63
63
  },
64
- level: minimumLevel,
64
+ ...(customLoggerOptions ?? {}),
65
65
  });
66
66
  //# sourceMappingURL=logging-wrapper.js.map
@@ -1 +1 @@
1
- {"version":3,"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EAAE,CAAC,CAAC;IACxB,GAAG,mBAAmB,CAAC,GAAG,CAAC;IAC3B,OAAO,EAAE,GAAG,CAAC,OAAO;IACpB,SAAS,EAAE,GAAG,CAAC,EAAE;IACjB,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,SAAS;CACnD,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,CAAC,GAAiB,EAAmB,EAAE,CAAC,CAAC;IACpE,WAAW,EAAE,GAAG,CAAC,UAAU;IAC3B,OAAO,EAAE,GAAG,CAAC,UAAU,EAAE;CAC1B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,mBAAuC,EACpB,EAAE,CAAC,CAAC;IACvB,IAAI,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;IAC9B,UAAU,EAAE,WAAW;IACvB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACZ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,GAAG,iBAAiB,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;KAC9C,CAAC;IACF,MAAM,EAAE;QACN,KAAK,EAAE,cAAc;QACrB,MAAM,EAAE,cAAc;KACvB;IACD,SAAS,EAAE,KAAK;IAChB,UAAU,EAAE;QACV,KAAK,EAAE,CAAC,IAAY,EAAE,QAAgB,EAAE,EAAE,CAAC,CAAC;YAC1C,KAAK,EAAE,QAAQ;YACf,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE;SAC/B,CAAC;KACH;IACD,GAAG,CAAC,mBAAmB,IAAI,EAAE,CAAC;CAC/B,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@ogcio/fastify-logging-wrapper",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "rm -rf dist tsconfig.prod.tsbuildinfo tsconfig.tsbuildinfo && tsc -p tsconfig.prod.json",
9
- "test": "tap --jobs=1 --allow-incomplete-coverage __tests__/**/*.test.ts"
9
+ "test": "vitest run --coverage --outputFile=results.xml",
10
+ "prepublishOnly": "npm i && npm run build && npm run test"
10
11
  },
11
12
  "keywords": [],
12
13
  "author": {
@@ -18,7 +19,8 @@
18
19
  "dependencies": {
19
20
  "@fastify/error": "^4.0.0",
20
21
  "@fastify/sensible": "^5.6.0",
21
- "fastify": "^4.28.1",
22
+ "@ogcio/shared-errors": "^1.0.0",
23
+ "fastify": "^4.29.0",
22
24
  "hyperid": "^3.3.0"
23
25
  },
24
26
  "devDependencies": {
@@ -29,4 +31,4 @@
29
31
  "url": "git+https://github.com/ogcio/shared-node-utils.git",
30
32
  "directory": "packages/fastify-logging-wrapper"
31
33
  }
32
- }
34
+ }
@@ -1,5 +1,8 @@
1
- import { FastifyServerOptions, FastifyInstance } from "fastify";
1
+ import { REQUEST_ID_HEADER } from "@ogcio/shared-errors";
2
+ import type { FastifyInstance, FastifyServerOptions } from "fastify";
3
+ import type { PinoLoggerOptions } from "fastify/types/logger.js";
2
4
  import hyperid from "hyperid";
5
+ import { type DestinationStream, pino } from "pino";
3
6
  import {
4
7
  LogMessages,
5
8
  REQUEST_ID_LOG_LABEL,
@@ -12,8 +15,6 @@ import {
12
15
  resetLoggingContext,
13
16
  setLoggingContext,
14
17
  } from "./logging-wrapper.js";
15
- import { pino, DestinationStream } from "pino";
16
- import { REQUEST_ID_HEADER } from "@ogcio/shared-errors";
17
18
 
18
19
  const hyperidInstance = hyperid({ fixedLength: true, urlSafe: true });
19
20
 
@@ -50,8 +51,9 @@ export const initializeLoggingHooks = (server: FastifyInstance): void => {
50
51
 
51
52
  export const getLoggingConfiguration = (
52
53
  loggerDestination?: DestinationStream,
54
+ customLoggerOptions?: PinoLoggerOptions,
53
55
  ): FastifyServerOptions => ({
54
- logger: pino(getLoggerConfiguration(), loggerDestination),
56
+ logger: pino(getLoggerConfiguration(customLoggerOptions), loggerDestination),
55
57
  disableRequestLogging: true,
56
58
  genReqId: () => hyperidInstance(),
57
59
  requestIdLogLabel: REQUEST_ID_LOG_LABEL,
package/src/index.ts CHANGED
@@ -8,4 +8,7 @@ export {
8
8
  LoggingError,
9
9
  } from "./logging-wrapper-entities.js";
10
10
 
11
- export { getLoggingContextError, setLoggingContext } from "./logging-wrapper.js";
11
+ export {
12
+ getLoggingContextError,
13
+ setLoggingContext,
14
+ } from "./logging-wrapper.js";
@@ -1,9 +1,7 @@
1
- import { FastifyError } from "fastify";
2
- import {
3
- parseErrorForLogging,
4
- } from "@ogcio/shared-errors";
5
- import { HttpError} from "@fastify/sensible";
6
- import {isHttpError} from "http-errors";
1
+ import type { FastifyError } from "fastify";
2
+ import { parseErrorForLogging } from "@ogcio/shared-errors";
3
+ import type { HttpError } from "@fastify/sensible";
4
+ import { isHttpError } from "http-errors";
7
5
 
8
6
  export interface LoggingRequest {
9
7
  scheme: string;
@@ -101,9 +99,7 @@ export const toLoggingError = (
101
99
  };
102
100
  };
103
101
 
104
- const parseErrorClass = (
105
- error: FastifyError | HttpError,
106
- ): LogErrorClasses => {
102
+ const parseErrorClass = (error: FastifyError | HttpError): LogErrorClasses => {
107
103
  if (!error.statusCode) {
108
104
  return LogErrorClasses.UnknownError;
109
105
  }
@@ -1,18 +1,18 @@
1
- import { FastifyRequest, FastifyReply, FastifyError } from "fastify";
2
1
  import { hostname } from "os";
2
+ import type { HttpError } from "@fastify/sensible";
3
+ import type { FastifyError, FastifyReply, FastifyRequest } from "fastify";
4
+ import type { LogLevel, PinoLoggerOptions } from "fastify/types/logger.js";
3
5
  import {
4
- LoggingContext,
5
- LoggingRequest,
6
- FullLoggingRequest,
7
- LoggingResponse,
8
- LoggingError,
9
- REDACTED_VALUE,
10
- REDACTED_PATHS,
6
+ type FullLoggingRequest,
7
+ type LoggingContext,
8
+ type LoggingError,
9
+ type LoggingRequest,
10
+ type LoggingResponse,
11
11
  MESSAGE_KEY,
12
+ REDACTED_PATHS,
13
+ REDACTED_VALUE,
12
14
  toLoggingError,
13
15
  } from "./logging-wrapper-entities.js";
14
- import { LogLevel, PinoLoggerOptions } from "fastify/types/logger.js";
15
- import { HttpError } from "@fastify/sensible";
16
16
 
17
17
  const loggingContext: LoggingContext = {};
18
18
 
@@ -83,7 +83,7 @@ const parseLoggingResponse = (res: FastifyReply): LoggingResponse => ({
83
83
  });
84
84
 
85
85
  export const getLoggerConfiguration = (
86
- minimumLevel: LogLevel = "debug",
86
+ customLoggerOptions?: PinoLoggerOptions,
87
87
  ): PinoLoggerOptions => ({
88
88
  base: { hostname: hostname() },
89
89
  messageKey: MESSAGE_KEY,
@@ -102,5 +102,5 @@ export const getLoggerConfiguration = (
102
102
  level_name: name.toUpperCase(),
103
103
  }),
104
104
  },
105
- level: minimumLevel,
105
+ ...(customLoggerOptions ?? {}),
106
106
  });
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ reporters: "default",
6
+ coverage: {
7
+ reporter: ["text", "cobertura"],
8
+ provider: "istanbul",
9
+ },
10
+ include: [
11
+ "**/@(test?(s)|__test?(s)__)/**/*.test.@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)",
12
+ "**/*.@(test?(s)|spec).@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)",
13
+ "**/test?(s).@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)",
14
+ ],
15
+ exclude: ["**/@(fixture*(s)|dist|node_modules)/**"],
16
+ maxConcurrency: 1,
17
+ testTimeout: 30000, // Timeout in milliseconds (30 seconds)
18
+ },
19
+ });