@ogcio/fastify-logging-wrapper 5.1.1 → 5.1.2
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.
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import type { FastifyServerOptions,
|
|
1
|
+
import type { FastifyInstance, FastifyServerOptions, RawServerBase } from "fastify";
|
|
2
|
+
import type { FastifyLoggerOptions, PinoLoggerOptions } from "fastify/types/logger.js";
|
|
2
3
|
import { type DestinationStream } from "pino";
|
|
3
|
-
import type { PinoLoggerOptions } from "fastify/types/logger.js";
|
|
4
4
|
export declare const initializeLoggingHooks: (server: FastifyInstance) => void;
|
|
5
5
|
export declare const getLoggingConfiguration: (customConfig?: {
|
|
6
6
|
pinoOptions?: PinoLoggerOptions;
|
|
7
7
|
loggerDestination?: DestinationStream;
|
|
8
|
+
additionalLoggerConfigs?: never;
|
|
9
|
+
} | {
|
|
10
|
+
pinoOptions?: never;
|
|
11
|
+
loggerDestination?: never;
|
|
12
|
+
additionalLoggerConfigs?: FastifyLoggerOptions<RawServerBase> & PinoLoggerOptions;
|
|
8
13
|
}) => FastifyServerOptions;
|
|
9
14
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"fastify-logging-wrapper.d.ts","sourceRoot":"","sources":["../src/fastify-logging-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,aAAa,EACd,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,KAAK,iBAAiB,EAAQ,MAAM,MAAM,CAAC;AAgBpD,eAAO,MAAM,sBAAsB,WAAY,eAAe,KAAG,IA6BhE,CAAC;AAEF,eAAO,MAAM,uBAAuB,kBAE9B;IACE,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,uBAAuB,CAAC,EAAE,KAAK,CAAC;CACjC,GACD;IACE,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,iBAAiB,CAAC,EAAE,KAAK,CAAC;IAC1B,uBAAuB,CAAC,EAAE,oBAAoB,CAAC,aAAa,CAAC,GAC3D,iBAAiB,CAAC;CACrB,KACJ,oBA2BF,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) => {
|
|
@@ -25,7 +25,7 @@ export const initializeLoggingHooks = (server) => {
|
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
export const getLoggingConfiguration = (customConfig) => {
|
|
28
|
-
if (customConfig)
|
|
28
|
+
if (customConfig?.pinoOptions || customConfig?.loggerDestination)
|
|
29
29
|
return {
|
|
30
30
|
loggerInstance: pino({ ...getLoggerConfiguration(), ...(customConfig?.pinoOptions ?? {}) }, customConfig?.loggerDestination),
|
|
31
31
|
disableRequestLogging: true,
|
|
@@ -33,8 +33,15 @@ export const getLoggingConfiguration = (customConfig) => {
|
|
|
33
33
|
requestIdLogLabel: REQUEST_ID_LOG_LABEL,
|
|
34
34
|
requestIdHeader: REQUEST_ID_HEADER,
|
|
35
35
|
};
|
|
36
|
+
let loggerConfiguration = getLoggerConfiguration();
|
|
37
|
+
if (customConfig?.additionalLoggerConfigs) {
|
|
38
|
+
loggerConfiguration = {
|
|
39
|
+
...loggerConfiguration,
|
|
40
|
+
...customConfig?.additionalLoggerConfigs,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
36
43
|
return {
|
|
37
|
-
logger:
|
|
44
|
+
logger: loggerConfiguration,
|
|
38
45
|
disableRequestLogging: true,
|
|
39
46
|
genReqId: () => hyperidInstance(),
|
|
40
47
|
requestIdLogLabel: REQUEST_ID_LOG_LABEL,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify-logging-wrapper.js","sourceRoot":"","sources":["../src/fastify-logging-wrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fastify-logging-wrapper.js","sourceRoot":"","sources":["../src/fastify-logging-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAUzD,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAA0B,IAAI,EAAE,MAAM,MAAM,CAAC;AACpD,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;AAE9B,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,IAA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,IAAI,EAAE,CAAC,EAAE,EACrE,YAAY,EAAE,iBAAiB,CAChC;YACD,qBAAqB,EAAE,IAAI;YAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE;YACjC,iBAAiB,EAAE,oBAAoB;YACvC,eAAe,EAAE,iBAAiB;SACnC,CAAC;IAEJ,IAAI,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;IACnD,IAAI,YAAY,EAAE,uBAAuB,EAAE,CAAC;QAC1C,mBAAmB,GAAG;YACpB,GAAG,mBAAmB;YACtB,GAAG,YAAY,EAAE,uBAAuB;SACzC,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,EAAE,mBAAmB;QAC3B,qBAAqB,EAAE,IAAI;QAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE;QACjC,iBAAiB,EAAE,oBAAoB;QACvC,eAAe,EAAE,iBAAiB;KACnC,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ogcio/fastify-logging-wrapper",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
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": "vitest run --coverage --outputFile=results.xml"
|
|
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": {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { REQUEST_ID_HEADER } from "@ogcio/shared-errors";
|
|
2
|
+
import type {
|
|
3
|
+
FastifyInstance,
|
|
4
|
+
FastifyServerOptions,
|
|
5
|
+
RawServerBase,
|
|
6
|
+
} from "fastify";
|
|
7
|
+
import type {
|
|
8
|
+
FastifyLoggerOptions,
|
|
9
|
+
PinoLoggerOptions,
|
|
10
|
+
} from "fastify/types/logger.js";
|
|
2
11
|
import hyperid from "hyperid";
|
|
12
|
+
import { type DestinationStream, pino } from "pino";
|
|
3
13
|
import {
|
|
4
14
|
LogMessages,
|
|
5
15
|
REQUEST_ID_LOG_LABEL,
|
|
@@ -12,9 +22,6 @@ import {
|
|
|
12
22
|
resetLoggingContext,
|
|
13
23
|
setLoggingContext,
|
|
14
24
|
} from "./logging-wrapper.js";
|
|
15
|
-
import { pino, type DestinationStream } from "pino";
|
|
16
|
-
import { REQUEST_ID_HEADER } from "@ogcio/shared-errors";
|
|
17
|
-
import type { PinoLoggerOptions } from "fastify/types/logger.js";
|
|
18
25
|
|
|
19
26
|
const hyperidInstance = hyperid({ fixedLength: true, urlSafe: true });
|
|
20
27
|
|
|
@@ -49,11 +56,21 @@ export const initializeLoggingHooks = (server: FastifyInstance): void => {
|
|
|
49
56
|
});
|
|
50
57
|
};
|
|
51
58
|
|
|
52
|
-
export const getLoggingConfiguration = (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
export const getLoggingConfiguration = (
|
|
60
|
+
customConfig?:
|
|
61
|
+
| {
|
|
62
|
+
pinoOptions?: PinoLoggerOptions;
|
|
63
|
+
loggerDestination?: DestinationStream;
|
|
64
|
+
additionalLoggerConfigs?: never;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
pinoOptions?: never;
|
|
68
|
+
loggerDestination?: never;
|
|
69
|
+
additionalLoggerConfigs?: FastifyLoggerOptions<RawServerBase> &
|
|
70
|
+
PinoLoggerOptions;
|
|
71
|
+
},
|
|
72
|
+
): FastifyServerOptions => {
|
|
73
|
+
if (customConfig?.pinoOptions || customConfig?.loggerDestination)
|
|
57
74
|
return {
|
|
58
75
|
loggerInstance: pino(
|
|
59
76
|
{ ...getLoggerConfiguration(), ...(customConfig?.pinoOptions ?? {}) },
|
|
@@ -65,8 +82,15 @@ export const getLoggingConfiguration = (customConfig?: {
|
|
|
65
82
|
requestIdHeader: REQUEST_ID_HEADER,
|
|
66
83
|
};
|
|
67
84
|
|
|
85
|
+
let loggerConfiguration = getLoggerConfiguration();
|
|
86
|
+
if (customConfig?.additionalLoggerConfigs) {
|
|
87
|
+
loggerConfiguration = {
|
|
88
|
+
...loggerConfiguration,
|
|
89
|
+
...customConfig?.additionalLoggerConfigs,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
68
92
|
return {
|
|
69
|
-
logger:
|
|
93
|
+
logger: loggerConfiguration,
|
|
70
94
|
disableRequestLogging: true,
|
|
71
95
|
genReqId: () => hyperidInstance(),
|
|
72
96
|
requestIdLogLabel: REQUEST_ID_LOG_LABEL,
|