@nwire/logger-pino 0.7.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex Gefter / 200apps Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @nwire/logger-pino
2
+
3
+ > [Pino](https://github.com/pinojs/pino)-backed `Logger` adapter — structured logging.
4
+
5
+ ## What it does
6
+
7
+ Adapts pino to the `@nwire/logger` contract. Bindings flow through `child(bindings)` so envelope ids (correlationId, causationId, tenant, userId) attach with zero allocation overhead per log call. JSON-line output for production; `pino-pretty` for dev.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @nwire/logger-pino pino
13
+ # dev only:
14
+ pnpm add -D pino-pretty
15
+ ```
16
+
17
+ ## Quick start
18
+
19
+ ```ts
20
+ import { createPinoLogger } from "@nwire/logger-pino";
21
+ import { createApp } from "@nwire/forge";
22
+
23
+ const logger = createPinoLogger({
24
+ level: "info",
25
+ service: "learnflow-api",
26
+ transport: process.env.NODE_ENV === "development" ? { target: "pino-pretty" } : undefined,
27
+ });
28
+
29
+ const app = createApp("learnflow", { modules, logger });
30
+ ```
31
+
32
+ ## API surface
33
+
34
+ - `createPinoLogger({ level?, service?, transport?,... })` — produces a `Logger`. All `pino` options pass through.
35
+
36
+ ## When to use
37
+
38
+ Every production wire. Fits L2 and up.
39
+
40
+ ## Standalone use
41
+
42
+ For developers using `@nwire/logger-pino` **without the rest of Nwire** — pair it with any TypeScript project, any container, any HTTP framework.
43
+
44
+ ```ts
45
+ // See the package's main entry (src/) for the standalone surface.
46
+ // The exports below work without @nwire/app or @nwire/forge.
47
+ import {} from /* ...standalone exports... */ "@nwire/logger-pino";
48
+ ```
49
+
50
+ ## Within nwire-app
51
+
52
+ For developers using this package as part of the Nwire stack — register it via `app.use(...)` or it auto-wires when you compose `createApp({ modules })`.
53
+
54
+ ```ts
55
+ import { createApp } from "@nwire/forge";
56
+
57
+ const app = createApp({
58
+ /* ...config... */
59
+ });
60
+ // Adapter/plugin wiring happens here when applicable.
61
+ ```
62
+
63
+ ## See also
64
+
65
+ - [Architecture sketch §05 — Adapters tier](../../architecture-sketch.html#packages)
66
+ - Sibling packages: [@nwire/logger](../nwire-logger), [@nwire/observability](../nwire-observability)
@@ -0,0 +1,47 @@
1
+ /**
2
+ * `@nwire/logger-pino` — Pino-backed Logger adapter.
3
+ *
4
+ * import { createPinoLogger } from '@nwire/logger-pino'
5
+ *
6
+ * const logger = createPinoLogger({
7
+ * level: 'info',
8
+ * service: 'learnflow-api',
9
+ * transport: { target: 'pino-pretty' } // dev only
10
+ * })
11
+ *
12
+ * const app = createApp({ modules, logger })
13
+ *
14
+ * Pino is the production-grade structured logger for Node — high throughput,
15
+ * JSON output, child loggers with bindings (matches our envelope-id pattern).
16
+ *
17
+ * The adapter is thin: every Logger method maps directly to pino. Bindings
18
+ * flow through `child(bindings)` so envelope ids attach with zero allocation
19
+ * overhead per log call.
20
+ */
21
+ import { type Logger as PinoLogger, type LoggerOptions as PinoOptions } from "pino";
22
+ import type { Logger } from "@nwire/logger";
23
+ export interface CreatePinoLoggerOptions extends PinoOptions {
24
+ /** Service name baked into every log (`service` field). Recommended. */
25
+ readonly service?: string;
26
+ }
27
+ /**
28
+ * Wraps a pino instance behind the Nwire `Logger` interface.
29
+ */
30
+ export declare class PinoLoggerAdapter implements Logger {
31
+ private readonly pino;
32
+ constructor(pino: PinoLogger);
33
+ debug(message: string, fields?: Record<string, unknown>): void;
34
+ info(message: string, fields?: Record<string, unknown>): void;
35
+ warn(message: string, fields?: Record<string, unknown>): void;
36
+ error(message: string, fields?: Record<string, unknown>): void;
37
+ child(bindings: Record<string, unknown>): Logger;
38
+ }
39
+ /**
40
+ * Create a Logger backed by pino with sensible defaults.
41
+ *
42
+ * - Default level: `'info'` (override via `level`)
43
+ * - Default base bindings: `{ service }` when provided
44
+ * - All other pino options pass through
45
+ */
46
+ export declare function createPinoLogger(options?: CreatePinoLoggerOptions): Logger;
47
+ //# sourceMappingURL=logger-pino.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-pino.d.ts","sourceRoot":"","sources":["../src/logger-pino.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAa,EAAE,KAAK,MAAM,IAAI,UAAU,EAAE,KAAK,aAAa,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAC1F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,uBAAwB,SAAQ,WAAW;IAC1D,wEAAwE;IACxE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,MAAM;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAG9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAG7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAG7D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAG9D,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;CAGjD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,MAAM,CAS9E"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `@nwire/logger-pino` — Pino-backed Logger adapter.
3
+ *
4
+ * import { createPinoLogger } from '@nwire/logger-pino'
5
+ *
6
+ * const logger = createPinoLogger({
7
+ * level: 'info',
8
+ * service: 'learnflow-api',
9
+ * transport: { target: 'pino-pretty' } // dev only
10
+ * })
11
+ *
12
+ * const app = createApp({ modules, logger })
13
+ *
14
+ * Pino is the production-grade structured logger for Node — high throughput,
15
+ * JSON output, child loggers with bindings (matches our envelope-id pattern).
16
+ *
17
+ * The adapter is thin: every Logger method maps directly to pino. Bindings
18
+ * flow through `child(bindings)` so envelope ids attach with zero allocation
19
+ * overhead per log call.
20
+ */
21
+ import pino from "pino";
22
+ /**
23
+ * Wraps a pino instance behind the Nwire `Logger` interface.
24
+ */
25
+ export class PinoLoggerAdapter {
26
+ pino;
27
+ constructor(pino) {
28
+ this.pino = pino;
29
+ }
30
+ debug(message, fields) {
31
+ this.pino.debug(fields ?? {}, message);
32
+ }
33
+ info(message, fields) {
34
+ this.pino.info(fields ?? {}, message);
35
+ }
36
+ warn(message, fields) {
37
+ this.pino.warn(fields ?? {}, message);
38
+ }
39
+ error(message, fields) {
40
+ this.pino.error(fields ?? {}, message);
41
+ }
42
+ child(bindings) {
43
+ return new PinoLoggerAdapter(this.pino.child(bindings));
44
+ }
45
+ }
46
+ /**
47
+ * Create a Logger backed by pino with sensible defaults.
48
+ *
49
+ * - Default level: `'info'` (override via `level`)
50
+ * - Default base bindings: `{ service }` when provided
51
+ * - All other pino options pass through
52
+ */
53
+ export function createPinoLogger(options = {}) {
54
+ const { service, ...pinoOpts } = options;
55
+ const baseBindings = service ? { service } : undefined;
56
+ const instance = pino({
57
+ level: pinoOpts.level ?? "info",
58
+ ...pinoOpts,
59
+ base: { ...baseBindings, ...pinoOpts.base },
60
+ });
61
+ return new PinoLoggerAdapter(instance);
62
+ }
63
+ //# sourceMappingURL=logger-pino.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-pino.js","sourceRoot":"","sources":["../src/logger-pino.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,IAAsE,MAAM,MAAM,CAAC;AAQ1F;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACC;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,KAAK,CAAC,OAAe,EAAE,MAAgC;QACrD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,CAAC,OAAe,EAAE,MAAgC;QACpD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,CAAC,OAAe,EAAE,MAAgC;QACpD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IACD,KAAK,CAAC,OAAe,EAAE,MAAgC;QACrD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACD,KAAK,CAAC,QAAiC;QACrC,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1D,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAmC,EAAE;IACpE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAI,CAAC;QACpB,KAAK,EAAE,QAAQ,CAAC,KAAK,IAAI,MAAM;QAC/B,GAAG,QAAQ;QACX,IAAI,EAAE,EAAE,GAAG,YAAY,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE;KAC5C,CAAC,CAAC;IACH,OAAO,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACzC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@nwire/logger-pino",
3
+ "version": "0.7.0",
4
+ "description": "Nwire — Pino-backed Logger adapter. Production-grade structured logging; envelope ids auto-attached via child().",
5
+ "keywords": [
6
+ "adapter",
7
+ "logger",
8
+ "nwire",
9
+ "pino"
10
+ ],
11
+ "files": [
12
+ "dist",
13
+ "README.md"
14
+ ],
15
+ "type": "module",
16
+ "main": "./dist/logger-pino.js",
17
+ "types": "./dist/logger-pino.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/logger-pino.js",
21
+ "types": "./dist/logger-pino.d.ts"
22
+ }
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "dependencies": {
28
+ "pino": "^9.5.0",
29
+ "@nwire/logger": "0.7.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^22.19.9",
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^4.0.18"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc && node ../../scripts/fix-dist-extensions.mjs dist",
38
+ "dev": "tsc --watch",
39
+ "typecheck": "tsc --noEmit"
40
+ }
41
+ }