@logtape/fastify 1.4.0-dev.428 → 1.4.0-dev.438
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/dist/mod.cjs +16 -1
- package/dist/mod.d.cts +28 -3
- package/dist/mod.d.cts.map +1 -1
- package/dist/mod.d.ts +28 -3
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +16 -1
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
package/dist/mod.cjs
CHANGED
|
@@ -4,7 +4,7 @@ const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/log
|
|
|
4
4
|
//#region src/mod.ts
|
|
5
5
|
/**
|
|
6
6
|
* Creates a Pino-compatible logger that wraps LogTape.
|
|
7
|
-
* This logger can be used as Fastify's `loggerInstance
|
|
7
|
+
* This logger can be used as Fastify's `loggerInstance` (v5) or `logger` (v4).
|
|
8
8
|
*
|
|
9
9
|
* @example Basic usage
|
|
10
10
|
* ```typescript
|
|
@@ -21,6 +21,21 @@ const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/log
|
|
|
21
21
|
* });
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
|
+
* @example Basic usage (Fastify v4)
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import Fastify from "fastify";
|
|
27
|
+
* import { configure } from "@logtape/logtape";
|
|
28
|
+
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
29
|
+
*
|
|
30
|
+
* await configure({
|
|
31
|
+
* // ... LogTape configuration
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const fastify = Fastify({
|
|
35
|
+
* logger: getLogTapeFastifyLogger(),
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
24
39
|
* @example With custom category
|
|
25
40
|
* ```typescript
|
|
26
41
|
* const fastify = Fastify({
|
package/dist/mod.d.cts
CHANGED
|
@@ -42,9 +42,9 @@ interface PinoLogMethod {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* A Pino-compatible logger interface that wraps LogTape.
|
|
45
|
-
* This interface satisfies Fastify's `loggerInstance` requirements.
|
|
45
|
+
* This interface satisfies Fastify's `loggerInstance` (v5) or `logger` (v4) requirements.
|
|
46
46
|
*
|
|
47
|
-
* @example
|
|
47
|
+
* @example Fastify v5
|
|
48
48
|
* ```typescript
|
|
49
49
|
* import Fastify from "fastify";
|
|
50
50
|
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
@@ -54,6 +54,16 @@ interface PinoLogMethod {
|
|
|
54
54
|
* });
|
|
55
55
|
* ```
|
|
56
56
|
*
|
|
57
|
+
* @example Fastify v4
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import Fastify from "fastify";
|
|
60
|
+
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
61
|
+
*
|
|
62
|
+
* const fastify = Fastify({
|
|
63
|
+
* logger: getLogTapeFastifyLogger(),
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
57
67
|
* @since 1.3.0
|
|
58
68
|
*/
|
|
59
69
|
interface PinoLikeLogger {
|
|
@@ -78,7 +88,7 @@ interface PinoLikeLogger {
|
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
90
|
* Creates a Pino-compatible logger that wraps LogTape.
|
|
81
|
-
* This logger can be used as Fastify's `loggerInstance
|
|
91
|
+
* This logger can be used as Fastify's `loggerInstance` (v5) or `logger` (v4).
|
|
82
92
|
*
|
|
83
93
|
* @example Basic usage
|
|
84
94
|
* ```typescript
|
|
@@ -95,6 +105,21 @@ interface PinoLikeLogger {
|
|
|
95
105
|
* });
|
|
96
106
|
* ```
|
|
97
107
|
*
|
|
108
|
+
* @example Basic usage (Fastify v4)
|
|
109
|
+
* ```typescript
|
|
110
|
+
* import Fastify from "fastify";
|
|
111
|
+
* import { configure } from "@logtape/logtape";
|
|
112
|
+
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
113
|
+
*
|
|
114
|
+
* await configure({
|
|
115
|
+
* // ... LogTape configuration
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* const fastify = Fastify({
|
|
119
|
+
* logger: getLogTapeFastifyLogger(),
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
98
123
|
* @example With custom category
|
|
99
124
|
* ```typescript
|
|
100
125
|
* const fastify = Fastify({
|
package/dist/mod.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;AAMA;AAaA;AA4BA;
|
|
1
|
+
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;AAMA;AAaA;AA4BA;AAiCiB,KA1EL,SAAA,GA0EmB,OAAA,GAAA,OAAA,GAAA,MAAA,GAAA,MAAA,GAAA,OAAA,GAAA,OAAA,GAAA,QAAA;;;;;AAQvB,UArES,qBAAA,CAqET;EAAa;;;;EAQyC,SAAA,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA,MAAA,EAAA;EAoD9C;;;;AAEC;;mBAtHE;;;;;;;;;;;;;;UAeF,aAAA;;QAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+BS,cAAA;;SAER;;SAEA;;QAED;;QAEA;;SAEC;;SAEA;;;;oBAIW,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoDhC,uBAAA,WACL,wBACR"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -42,9 +42,9 @@ interface PinoLogMethod {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* A Pino-compatible logger interface that wraps LogTape.
|
|
45
|
-
* This interface satisfies Fastify's `loggerInstance` requirements.
|
|
45
|
+
* This interface satisfies Fastify's `loggerInstance` (v5) or `logger` (v4) requirements.
|
|
46
46
|
*
|
|
47
|
-
* @example
|
|
47
|
+
* @example Fastify v5
|
|
48
48
|
* ```typescript
|
|
49
49
|
* import Fastify from "fastify";
|
|
50
50
|
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
@@ -54,6 +54,16 @@ interface PinoLogMethod {
|
|
|
54
54
|
* });
|
|
55
55
|
* ```
|
|
56
56
|
*
|
|
57
|
+
* @example Fastify v4
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import Fastify from "fastify";
|
|
60
|
+
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
61
|
+
*
|
|
62
|
+
* const fastify = Fastify({
|
|
63
|
+
* logger: getLogTapeFastifyLogger(),
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
57
67
|
* @since 1.3.0
|
|
58
68
|
*/
|
|
59
69
|
interface PinoLikeLogger {
|
|
@@ -78,7 +88,7 @@ interface PinoLikeLogger {
|
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
90
|
* Creates a Pino-compatible logger that wraps LogTape.
|
|
81
|
-
* This logger can be used as Fastify's `loggerInstance
|
|
91
|
+
* This logger can be used as Fastify's `loggerInstance` (v5) or `logger` (v4).
|
|
82
92
|
*
|
|
83
93
|
* @example Basic usage
|
|
84
94
|
* ```typescript
|
|
@@ -95,6 +105,21 @@ interface PinoLikeLogger {
|
|
|
95
105
|
* });
|
|
96
106
|
* ```
|
|
97
107
|
*
|
|
108
|
+
* @example Basic usage (Fastify v4)
|
|
109
|
+
* ```typescript
|
|
110
|
+
* import Fastify from "fastify";
|
|
111
|
+
* import { configure } from "@logtape/logtape";
|
|
112
|
+
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
113
|
+
*
|
|
114
|
+
* await configure({
|
|
115
|
+
* // ... LogTape configuration
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* const fastify = Fastify({
|
|
119
|
+
* logger: getLogTapeFastifyLogger(),
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
98
123
|
* @example With custom category
|
|
99
124
|
* ```typescript
|
|
100
125
|
* const fastify = Fastify({
|
package/dist/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;AAMA;AAaA;AA4BA;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;AAMA;AAaA;AA4BA;AAiCiB,KA1EL,SAAA,GA0EmB,OAAA,GAAA,OAAA,GAAA,MAAA,GAAA,MAAA,GAAA,OAAA,GAAA,OAAA,GAAA,QAAA;;;;;AAQvB,UArES,qBAAA,CAqET;EAAa;;;;EAQyC,SAAA,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA,MAAA,EAAA;EAoD9C;;;;AAEC;;mBAtHE;;;;;;;;;;;;;;UAeF,aAAA;;QAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+BS,cAAA;;SAER;;SAEA;;QAED;;QAEA;;SAEC;;SAEA;;;;oBAIW,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoDhC,uBAAA,WACL,wBACR"}
|
package/dist/mod.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getLogger } from "@logtape/logtape";
|
|
|
3
3
|
//#region src/mod.ts
|
|
4
4
|
/**
|
|
5
5
|
* Creates a Pino-compatible logger that wraps LogTape.
|
|
6
|
-
* This logger can be used as Fastify's `loggerInstance
|
|
6
|
+
* This logger can be used as Fastify's `loggerInstance` (v5) or `logger` (v4).
|
|
7
7
|
*
|
|
8
8
|
* @example Basic usage
|
|
9
9
|
* ```typescript
|
|
@@ -20,6 +20,21 @@ import { getLogger } from "@logtape/logtape";
|
|
|
20
20
|
* });
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
|
+
* @example Basic usage (Fastify v4)
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import Fastify from "fastify";
|
|
26
|
+
* import { configure } from "@logtape/logtape";
|
|
27
|
+
* import { getLogTapeFastifyLogger } from "@logtape/fastify";
|
|
28
|
+
*
|
|
29
|
+
* await configure({
|
|
30
|
+
* // ... LogTape configuration
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* const fastify = Fastify({
|
|
34
|
+
* logger: getLogTapeFastifyLogger(),
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
23
38
|
* @example With custom category
|
|
24
39
|
* ```typescript
|
|
25
40
|
* const fastify = Fastify({
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","names":["options: FastifyLogTapeOptions","category: string | readonly string[]","template: string","logger: Logger","initialLevel: PinoLevel","bindings: Record<string, unknown>","_level: string","logFn: (msg: string, props?: Record<string, unknown>) => void","objOrMsg: Record<string, unknown> | string","pinoLogger: PinoLikeLogger","childBindings: Record<string, unknown>","newLevel: string"],"sources":["../src/mod.ts"],"sourcesContent":["import { getLogger, type Logger } from \"@logtape/logtape\";\n\n/**\n * Pino log levels as strings.\n * @since 1.3.0\n */\nexport type PinoLevel =\n | \"trace\"\n | \"debug\"\n | \"info\"\n | \"warn\"\n | \"error\"\n | \"fatal\"\n | \"silent\";\n\n/**\n * Options for configuring the Fastify LogTape logger.\n * @since 1.3.0\n */\nexport interface FastifyLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"fastify\"]\n */\n readonly category?: string | readonly string[];\n\n /**\n * The initial log level. This is tracked internally to satisfy\n * Pino's level property requirement.\n * Note: Actual filtering is controlled by LogTape configuration.\n * @default \"info\"\n */\n readonly level?: PinoLevel;\n}\n\n/**\n * Pino-style log method supporting multiple signatures.\n *\n * Supports the following calling conventions:\n * - `logger.info(\"message\")` - Simple message\n * - `logger.info(\"message %s\", arg)` - Printf-style interpolation\n * - `logger.info({ key: \"value\" }, \"message\")` - Object with message\n * - `logger.info({ key: \"value\" })` - Object only\n * - `logger.info({ msg: \"message\", key: \"value\" })` - Object with msg property\n *\n * @since 1.3.0\n */\nexport interface PinoLogMethod {\n /** Log with object and optional message */\n (obj: Record<string, unknown>, msg?: string, ...args: unknown[]): void;\n /** Log with just a message and optional interpolation args */\n (msg: string, ...args: unknown[]): void;\n}\n\n/**\n * A Pino-compatible logger interface that wraps LogTape.\n * This interface satisfies Fastify's `loggerInstance` requirements.\n *\n * @example\n * ```typescript\n * import Fastify from \"fastify\";\n * import { getLogTapeFastifyLogger } from \"@logtape/fastify\";\n *\n * const fastify = Fastify({\n * loggerInstance: getLogTapeFastifyLogger(),\n * });\n * ```\n *\n * @since 1.3.0\n */\nexport interface PinoLikeLogger {\n /** Log at trace level */\n trace: PinoLogMethod;\n /** Log at debug level */\n debug: PinoLogMethod;\n /** Log at info level */\n info: PinoLogMethod;\n /** Log at warn level */\n warn: PinoLogMethod;\n /** Log at error level */\n error: PinoLogMethod;\n /** Log at fatal level */\n fatal: PinoLogMethod;\n /** No-op silent method for Pino compatibility */\n silent: () => void;\n /** Create a child logger with additional bindings */\n child: (bindings: Record<string, unknown>) => PinoLikeLogger;\n /** Current log level (readable/writable for Pino compatibility) */\n level: string;\n}\n\n/**\n * Creates a Pino-compatible logger that wraps LogTape.\n * This logger can be used as Fastify's `loggerInstance`.\n *\n * @example Basic usage\n * ```typescript\n * import Fastify from \"fastify\";\n * import { configure } from \"@logtape/logtape\";\n * import { getLogTapeFastifyLogger } from \"@logtape/fastify\";\n *\n * await configure({\n * // ... LogTape configuration\n * });\n *\n * const fastify = Fastify({\n * loggerInstance: getLogTapeFastifyLogger(),\n * });\n * ```\n *\n * @example With custom category\n * ```typescript\n * const fastify = Fastify({\n * loggerInstance: getLogTapeFastifyLogger({\n * category: [\"myapp\", \"http\"],\n * }),\n * });\n * ```\n *\n * @param options Configuration options for the logger.\n * @returns A Pino-compatible logger wrapping LogTape.\n * @since 1.3.0\n */\nexport function getLogTapeFastifyLogger(\n options: FastifyLogTapeOptions = {},\n): PinoLikeLogger {\n const category = normalizeCategory(options.category ?? [\"fastify\"]);\n const logger = getLogger(category);\n const initialLevel = options.level ?? \"info\";\n\n return createPinoLikeLogger(logger, initialLevel);\n}\n\n/**\n * Normalize category to array format.\n */\nfunction normalizeCategory(\n category: string | readonly string[],\n): readonly string[] {\n return typeof category === \"string\" ? [category] : category;\n}\n\n/**\n * Format message with printf-style interpolation.\n * Supports: %s (string), %d (number), %j (JSON), %o/%O (object), %% (escaped %)\n */\nfunction formatMessage(template: string, ...args: unknown[]): string {\n let argIndex = 0;\n return template.replace(/%[sdjoO%]/g, (match) => {\n if (match === \"%%\") return \"%\";\n if (argIndex >= args.length) return match;\n\n const arg = args[argIndex++];\n switch (match) {\n case \"%s\":\n return String(arg);\n case \"%d\":\n return Number(arg).toString();\n case \"%j\":\n case \"%o\":\n case \"%O\":\n return JSON.stringify(arg);\n default:\n return match;\n }\n });\n}\n\n/**\n * Creates a Pino-like logger wrapper around a LogTape logger.\n */\nfunction createPinoLikeLogger(\n logger: Logger,\n initialLevel: PinoLevel,\n bindings: Record<string, unknown> = {},\n): PinoLikeLogger {\n // Track level internally for Pino compatibility\n let _level: string = initialLevel;\n\n // If there are bindings, create a contextual logger\n const contextLogger = Object.keys(bindings).length > 0\n ? logger.with(bindings)\n : logger;\n\n /**\n * Create a log method for a specific level.\n */\n function createLogMethod(\n logFn: (msg: string, props?: Record<string, unknown>) => void,\n ): PinoLogMethod {\n return function pinoLogMethod(\n objOrMsg: Record<string, unknown> | string,\n ...restArgs: unknown[]\n ): void {\n // Detect calling convention\n if (typeof objOrMsg === \"string\") {\n // Called as: logger.info(\"message\") or logger.info(\"message %s\", arg)\n const message = formatMessage(objOrMsg, ...restArgs);\n logFn(message);\n } else if (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n // Called as: logger.info({ key: value }, \"message\") or logger.info({ key: value })\n const properties = { ...objOrMsg };\n const [msgOrArg, ...args] = restArgs;\n\n if (typeof msgOrArg === \"string\") {\n // Has message string: logger.info({ foo: 1 }, \"message %s\", arg)\n const message = formatMessage(msgOrArg, ...args);\n logFn(message, properties);\n } else if (\"msg\" in properties && typeof properties.msg === \"string\") {\n // Extract message from object: logger.info({ msg: \"hello\", foo: 1 })\n const message = properties.msg as string;\n delete properties.msg;\n logFn(message, properties);\n } else {\n // Object-only logging: logger.info({ foo: 1 })\n logFn(\"{*}\", properties);\n }\n }\n } as PinoLogMethod;\n }\n\n const pinoLogger: PinoLikeLogger = {\n trace: createLogMethod((msg, props) => contextLogger.trace(msg, props)),\n debug: createLogMethod((msg, props) => contextLogger.debug(msg, props)),\n info: createLogMethod((msg, props) => contextLogger.info(msg, props)),\n warn: createLogMethod((msg, props) => contextLogger.warn(msg, props)),\n error: createLogMethod((msg, props) => contextLogger.error(msg, props)),\n fatal: createLogMethod((msg, props) => contextLogger.fatal(msg, props)),\n\n silent: () => {\n // No-op for silent level\n },\n\n child: (childBindings: Record<string, unknown>) => {\n // Merge parent bindings with child bindings\n const mergedBindings = { ...bindings, ...childBindings };\n return createPinoLikeLogger(logger, _level as PinoLevel, mergedBindings);\n },\n\n get level() {\n return _level;\n },\n\n set level(newLevel: string) {\n // Store level for Pino compatibility\n // Note: Actual filtering is handled by LogTape configuration\n _level = newLevel;\n },\n };\n\n return pinoLogger;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HA,SAAgB,wBACdA,UAAiC,CAAE,GACnB;CAChB,MAAM,WAAW,kBAAkB,QAAQ,YAAY,CAAC,SAAU,EAAC;CACnE,MAAM,SAAS,UAAU,SAAS;CAClC,MAAM,eAAe,QAAQ,SAAS;AAEtC,QAAO,qBAAqB,QAAQ,aAAa;AAClD;;;;AAKD,SAAS,kBACPC,UACmB;AACnB,eAAc,aAAa,WAAW,CAAC,QAAS,IAAG;AACpD;;;;;AAMD,SAAS,cAAcC,UAAkB,GAAG,MAAyB;CACnE,IAAI,WAAW;AACf,QAAO,SAAS,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EACrE,MAAM,gBAAgB,CAAC,KAAK,UAAU,cAAc,KAAK,KAAK,MAAM,CAAC;EACrE,OAAO,gBAAgB,CAAC,KAAK,UAAU,cAAc,MAAM,KAAK,MAAM,CAAC;EACvE,OAAO,gBAAgB,CAAC,KAAK,UAAU,cAAc,MAAM,KAAK,MAAM,CAAC;EAEvE,QAAQ,MAAM,CAEb;EAED,OAAO,CAACC,kBAA2C;GAEjD,MAAM,iBAAiB;IAAE,GAAG;IAAU,GAAG;GAAe;AACxD,UAAO,qBAAqB,QAAQ,QAAqB,eAAe;EACzE;EAED,IAAI,QAAQ;AACV,UAAO;EACR;EAED,IAAI,MAAMC,UAAkB;AAG1B,YAAS;EACV;CACF;AAED,QAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"mod.js","names":["options: FastifyLogTapeOptions","category: string | readonly string[]","template: string","logger: Logger","initialLevel: PinoLevel","bindings: Record<string, unknown>","_level: string","logFn: (msg: string, props?: Record<string, unknown>) => void","objOrMsg: Record<string, unknown> | string","pinoLogger: PinoLikeLogger","childBindings: Record<string, unknown>","newLevel: string"],"sources":["../src/mod.ts"],"sourcesContent":["import { getLogger, type Logger } from \"@logtape/logtape\";\n\n/**\n * Pino log levels as strings.\n * @since 1.3.0\n */\nexport type PinoLevel =\n | \"trace\"\n | \"debug\"\n | \"info\"\n | \"warn\"\n | \"error\"\n | \"fatal\"\n | \"silent\";\n\n/**\n * Options for configuring the Fastify LogTape logger.\n * @since 1.3.0\n */\nexport interface FastifyLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"fastify\"]\n */\n readonly category?: string | readonly string[];\n\n /**\n * The initial log level. This is tracked internally to satisfy\n * Pino's level property requirement.\n * Note: Actual filtering is controlled by LogTape configuration.\n * @default \"info\"\n */\n readonly level?: PinoLevel;\n}\n\n/**\n * Pino-style log method supporting multiple signatures.\n *\n * Supports the following calling conventions:\n * - `logger.info(\"message\")` - Simple message\n * - `logger.info(\"message %s\", arg)` - Printf-style interpolation\n * - `logger.info({ key: \"value\" }, \"message\")` - Object with message\n * - `logger.info({ key: \"value\" })` - Object only\n * - `logger.info({ msg: \"message\", key: \"value\" })` - Object with msg property\n *\n * @since 1.3.0\n */\nexport interface PinoLogMethod {\n /** Log with object and optional message */\n (obj: Record<string, unknown>, msg?: string, ...args: unknown[]): void;\n /** Log with just a message and optional interpolation args */\n (msg: string, ...args: unknown[]): void;\n}\n\n/**\n * A Pino-compatible logger interface that wraps LogTape.\n * This interface satisfies Fastify's `loggerInstance` (v5) or `logger` (v4) requirements.\n *\n * @example Fastify v5\n * ```typescript\n * import Fastify from \"fastify\";\n * import { getLogTapeFastifyLogger } from \"@logtape/fastify\";\n *\n * const fastify = Fastify({\n * loggerInstance: getLogTapeFastifyLogger(),\n * });\n * ```\n *\n * @example Fastify v4\n * ```typescript\n * import Fastify from \"fastify\";\n * import { getLogTapeFastifyLogger } from \"@logtape/fastify\";\n *\n * const fastify = Fastify({\n * logger: getLogTapeFastifyLogger(),\n * });\n * ```\n *\n * @since 1.3.0\n */\nexport interface PinoLikeLogger {\n /** Log at trace level */\n trace: PinoLogMethod;\n /** Log at debug level */\n debug: PinoLogMethod;\n /** Log at info level */\n info: PinoLogMethod;\n /** Log at warn level */\n warn: PinoLogMethod;\n /** Log at error level */\n error: PinoLogMethod;\n /** Log at fatal level */\n fatal: PinoLogMethod;\n /** No-op silent method for Pino compatibility */\n silent: () => void;\n /** Create a child logger with additional bindings */\n child: (bindings: Record<string, unknown>) => PinoLikeLogger;\n /** Current log level (readable/writable for Pino compatibility) */\n level: string;\n}\n\n/**\n * Creates a Pino-compatible logger that wraps LogTape.\n * This logger can be used as Fastify's `loggerInstance` (v5) or `logger` (v4).\n *\n * @example Basic usage\n * ```typescript\n * import Fastify from \"fastify\";\n * import { configure } from \"@logtape/logtape\";\n * import { getLogTapeFastifyLogger } from \"@logtape/fastify\";\n *\n * await configure({\n * // ... LogTape configuration\n * });\n *\n * const fastify = Fastify({\n * loggerInstance: getLogTapeFastifyLogger(),\n * });\n * ```\n *\n * @example Basic usage (Fastify v4)\n * ```typescript\n * import Fastify from \"fastify\";\n * import { configure } from \"@logtape/logtape\";\n * import { getLogTapeFastifyLogger } from \"@logtape/fastify\";\n *\n * await configure({\n * // ... LogTape configuration\n * });\n *\n * const fastify = Fastify({\n * logger: getLogTapeFastifyLogger(),\n * });\n * ```\n *\n * @example With custom category\n * ```typescript\n * const fastify = Fastify({\n * loggerInstance: getLogTapeFastifyLogger({\n * category: [\"myapp\", \"http\"],\n * }),\n * });\n * ```\n *\n * @param options Configuration options for the logger.\n * @returns A Pino-compatible logger wrapping LogTape.\n * @since 1.3.0\n */\nexport function getLogTapeFastifyLogger(\n options: FastifyLogTapeOptions = {},\n): PinoLikeLogger {\n const category = normalizeCategory(options.category ?? [\"fastify\"]);\n const logger = getLogger(category);\n const initialLevel = options.level ?? \"info\";\n\n return createPinoLikeLogger(logger, initialLevel);\n}\n\n/**\n * Normalize category to array format.\n */\nfunction normalizeCategory(\n category: string | readonly string[],\n): readonly string[] {\n return typeof category === \"string\" ? [category] : category;\n}\n\n/**\n * Format message with printf-style interpolation.\n * Supports: %s (string), %d (number), %j (JSON), %o/%O (object), %% (escaped %)\n */\nfunction formatMessage(template: string, ...args: unknown[]): string {\n let argIndex = 0;\n return template.replace(/%[sdjoO%]/g, (match) => {\n if (match === \"%%\") return \"%\";\n if (argIndex >= args.length) return match;\n\n const arg = args[argIndex++];\n switch (match) {\n case \"%s\":\n return String(arg);\n case \"%d\":\n return Number(arg).toString();\n case \"%j\":\n case \"%o\":\n case \"%O\":\n return JSON.stringify(arg);\n default:\n return match;\n }\n });\n}\n\n/**\n * Creates a Pino-like logger wrapper around a LogTape logger.\n */\nfunction createPinoLikeLogger(\n logger: Logger,\n initialLevel: PinoLevel,\n bindings: Record<string, unknown> = {},\n): PinoLikeLogger {\n // Track level internally for Pino compatibility\n let _level: string = initialLevel;\n\n // If there are bindings, create a contextual logger\n const contextLogger = Object.keys(bindings).length > 0\n ? logger.with(bindings)\n : logger;\n\n /**\n * Create a log method for a specific level.\n */\n function createLogMethod(\n logFn: (msg: string, props?: Record<string, unknown>) => void,\n ): PinoLogMethod {\n return function pinoLogMethod(\n objOrMsg: Record<string, unknown> | string,\n ...restArgs: unknown[]\n ): void {\n // Detect calling convention\n if (typeof objOrMsg === \"string\") {\n // Called as: logger.info(\"message\") or logger.info(\"message %s\", arg)\n const message = formatMessage(objOrMsg, ...restArgs);\n logFn(message);\n } else if (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n // Called as: logger.info({ key: value }, \"message\") or logger.info({ key: value })\n const properties = { ...objOrMsg };\n const [msgOrArg, ...args] = restArgs;\n\n if (typeof msgOrArg === \"string\") {\n // Has message string: logger.info({ foo: 1 }, \"message %s\", arg)\n const message = formatMessage(msgOrArg, ...args);\n logFn(message, properties);\n } else if (\"msg\" in properties && typeof properties.msg === \"string\") {\n // Extract message from object: logger.info({ msg: \"hello\", foo: 1 })\n const message = properties.msg as string;\n delete properties.msg;\n logFn(message, properties);\n } else {\n // Object-only logging: logger.info({ foo: 1 })\n logFn(\"{*}\", properties);\n }\n }\n } as PinoLogMethod;\n }\n\n const pinoLogger: PinoLikeLogger = {\n trace: createLogMethod((msg, props) => contextLogger.trace(msg, props)),\n debug: createLogMethod((msg, props) => contextLogger.debug(msg, props)),\n info: createLogMethod((msg, props) => contextLogger.info(msg, props)),\n warn: createLogMethod((msg, props) => contextLogger.warn(msg, props)),\n error: createLogMethod((msg, props) => contextLogger.error(msg, props)),\n fatal: createLogMethod((msg, props) => contextLogger.fatal(msg, props)),\n\n silent: () => {\n // No-op for silent level\n },\n\n child: (childBindings: Record<string, unknown>) => {\n // Merge parent bindings with child bindings\n const mergedBindings = { ...bindings, ...childBindings };\n return createPinoLikeLogger(logger, _level as PinoLevel, mergedBindings);\n },\n\n get level() {\n return _level;\n },\n\n set level(newLevel: string) {\n // Store level for Pino compatibility\n // Note: Actual filtering is handled by LogTape configuration\n _level = newLevel;\n },\n };\n\n return pin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,cAAc,UAAU,GAAG,KAAK;AAChD,WAAM,SAAS,WAAW;IAC3B,WAAU,SAAS,qBAAqB,WAAW,QAAQ,UAAU;KAEpE,MAAM,UAAU,WAAW;AAC3B,YAAO,WAAW;AAClB,WAAM,SAAS,WAAW;IAC3B,MAEC,OAAM,OAAO,WAAW;GAE3B;EACF;CACF;CAED,MAAMC,aAA6B;EACjC,OAAO,gBAAgB,CAAC,KAAK,UAAU,cAAc,MAAM,KAAK,MAAM,CAAC;EACvE,OAAO,gBAAgB,CAAC,KAAK,UAAU,cAAc,MAAM,KAAK,MAAM,CAAC;EACvE,MAAM,gBAAgB,CAAC,KAAK,UAAU,cAAc,KAAK,KAAK,MAAM,CAAC;EACrE,MAAM,gBAAgB,CAAC,KAAK,UAAU,cAAc,KAAK,KAAK,MAAM,CAAC;EACrE,OAAO,gBAAgB,CAAC,KAAK,UAAU,cAAc,MAAM,KAAK,MAAM,CAAC;EACvE,OAAO,gBAAgB,CAAC,KAAK,UAAU,cAAc,MAAM,KAAK,MAAM,CAAC;EAEvE,QAAQ,MAAM,CAEb;EAED,OAAO,CAACC,kBAA2C;GAEjD,MAAM,iBAAiB;IAAE,GAAG;IAAU,GAAG;GAAe;AACxD,UAAO,qBAAqB,QAAQ,QAAqB,eAAe;EACzE;EAED,IAAI,QAAQ;AACV,UAAO;EACR;EAED,IAAI,MAAMC,UAAkB;AAG1B,YAAS;EACV;CACF;AAED,QAAO;AACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logtape/fastify",
|
|
3
|
-
"version": "1.4.0-dev.
|
|
3
|
+
"version": "1.4.0-dev.438+7b577399",
|
|
4
4
|
"description": "Fastify adapter for LogTape logging library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logging",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"dist/"
|
|
50
50
|
],
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@logtape/logtape": "^1.4.0-dev.
|
|
52
|
+
"@logtape/logtape": "^1.4.0-dev.438+7b577399"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@alinea/suite": "^0.6.3",
|