@ontrails/pino 0.2.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,63 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [`664e8bb`](https://github.com/outfitter-dev/trails/commit/664e8bb049e61f1d47cec1dd246606707af5d1a8): Point public installation examples at exact approved 0.2.0 versions and distinguish the prepared source release from pending npm publication.
8
+ - [`b3ddf91`](https://github.com/outfitter-dev/trails/commit/b3ddf918ada8211f44983512e2bbdfbc5b66d722): Prepare the first normal Trails release at `0.2.0` on `latest`, replacing the unpublished 1.0.0 source release. The target advances the original `0.1.0` source minor, which was never published under the current package names. Public packages remain in lockstep. Update consumer installation guidance and provide a temporary manifest bridge for old 1.0 beta sources. Published beta versions remain unchanged; minor 0.x releases may carry documented breaking changes.
9
+
10
+ The `1.0.0` section retained below records an unpublished preparation, not an npm release. Its accumulated changes are included in `0.2.0`; the section remains as source history alongside the published beta entries.
11
+
12
+ ## 1.0.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [`50e2779`](https://github.com/outfitter-dev/trails/commit/50e27796d074851bccd57d7df009db749757b457): Extract the real `@ontrails/logtape` and `@ontrails/pino` adapters from the
17
+ temporary observability subpaths. The new packages own their namesake foreign
18
+ dependencies and preserve Trails record metadata, levels, redaction boundaries,
19
+ and lifecycle behavior; the old subpaths are removed in the pre-v1 hard cut.
20
+
21
+ Add governed Regrade transitions for both exact import replacements and expose
22
+ the observability adapter target through the shared adapter readiness check.
23
+
24
+ ### Patch Changes
25
+
26
+ - [`47297d9`](https://github.com/outfitter-dev/trails/commit/47297d98230a4adb25b99b3c8a71217113379398): Treat both `null` and `undefined` Pino flush callback results as success, and verify asynchronous buffered destinations finish writing before the sink resolves.
27
+ - [`b1fbe57`](https://github.com/outfitter-dev/trails/commit/b1fbe574e6f44d1fecb5e3a000270955c0a77b7b): Publish Bun-validated package tarballs through an npm trusted-publishing adapter
28
+ binding, add exact repository metadata for each public workspace package, and
29
+ correct the native Bun release descriptor to its pack-only runtime boundary.
30
+
31
+ ## 1.0.0-beta.50
32
+
33
+ ## 1.0.0-beta.49
34
+
35
+ ## 1.0.0-beta.48
36
+
37
+ ## 1.0.0-beta.47
38
+
39
+ ## 1.0.0-beta.46
40
+
41
+ ## 1.0.0-beta.45
42
+
43
+ ## 1.0.0-beta.44
44
+
45
+ ### Patch Changes
46
+
47
+ - [`b1fbe57`](https://github.com/outfitter-dev/trails/commit/b1fbe574e6f44d1fecb5e3a000270955c0a77b7b): Publish Bun-validated package tarballs through an npm trusted-publishing adapter
48
+ binding, add exact repository metadata for each public workspace package, and
49
+ correct the native Bun release descriptor to its pack-only runtime boundary.
50
+
51
+ ## 1.0.0-beta.43
52
+
53
+ ### Minor Changes
54
+
55
+ - [`50e2779`](https://github.com/outfitter-dev/trails/commit/50e27796d074851bccd57d7df009db749757b457): Extract the real `@ontrails/logtape` and `@ontrails/pino` adapters from the
56
+ temporary observability subpaths. The new packages own their namesake foreign
57
+ dependencies and preserve Trails record metadata, levels, redaction boundaries,
58
+ and lifecycle behavior; the old subpaths are removed in the pre-v1 hard cut.
59
+
60
+ Add governed Regrade transitions for both exact import replacements and expose
61
+ the observability adapter target through the shared adapter readiness check.
62
+
63
+ All notable changes to this package are documented through the Trails release process.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @ontrails/pino
2
+
3
+ Real Pino adapter for Trails observability. This extracted package owns the Pino dependency boundary, keeping `@ontrails/observability` limited to Trails-native records, sink contracts, redaction, formatters, and built-ins.
4
+
5
+ ## Usage
6
+
7
+ ```typescript
8
+ import pino from 'pino';
9
+ import { createPinoSink } from '@ontrails/pino';
10
+
11
+ const logger = pino({ level: 'info' });
12
+ const sink = createPinoSink({ logger });
13
+
14
+ sink.write({
15
+ category: 'app.http',
16
+ level: 'info',
17
+ message: 'request received',
18
+ metadata: { requestId: 'req_123' },
19
+ timestamp: new Date(),
20
+ });
21
+
22
+ await sink.flush();
23
+ ```
24
+
25
+ Pass `pinoOptions` and an optional Pino destination when the adapter should construct the logger. For an asynchronously buffered destination, await `sink.flush()` before shutdown so accepted records reach Pino's destination. Trails records arrive after Trails-owned redaction, retain their category and timestamp as structured fields, and map `trace` through `fatal` directly to Pino levels. `silent` records do not reach Pino.
26
+
27
+ ## Installation
28
+
29
+ These commands target stable `0.2.0`. Run them after that version is published to npm.
30
+
31
+ ```bash
32
+ bun add --exact @ontrails/observability@0.2.0 @ontrails/pino@0.2.0
33
+ ```
34
+
35
+ ## Migration
36
+
37
+ This package is the final Pino adapter in the pre-v1 hard cut. No compatibility subpath remains; see the logging migration guide for the explicit historical import map.
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@ontrails/pino",
3
+ "version": "0.2.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/outfitter-dev/trails.git",
7
+ "directory": "adapters/pino"
8
+ },
9
+ "files": [
10
+ "src/**/*.ts",
11
+ "!src/**/__tests__/**",
12
+ "!src/**/*.test.ts",
13
+ "!src/**/*.test-d.ts",
14
+ "README.md",
15
+ "CHANGELOG.md"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": "./src/index.ts",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "scripts": {
23
+ "build": "tsc -b",
24
+ "test": "bun test",
25
+ "typecheck": "tsc --noEmit",
26
+ "lint": "oxlint ./src",
27
+ "clean": "rm -rf dist *.tsbuildinfo"
28
+ },
29
+ "dependencies": {
30
+ "pino": "^10.3.1"
31
+ },
32
+ "peerDependencies": {
33
+ "@ontrails/observability": "^0.2.0",
34
+ "zod": "^4.3.5"
35
+ },
36
+ "trails": {
37
+ "adapter": {
38
+ "target": "observability"
39
+ }
40
+ }
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,82 @@
1
+ import pino from 'pino';
2
+ import type { DestinationStream, Logger, LoggerOptions } from 'pino';
3
+
4
+ import type { LogLevel, LogRecord, LogSink } from '@ontrails/observability';
5
+
6
+ export interface PinoSinkOptions {
7
+ /** Destination used only when this adapter constructs the Pino logger itself. */
8
+ readonly destination?: DestinationStream | undefined;
9
+ /** Existing configured Pino logger to receive Trails records. */
10
+ readonly logger?: Logger | undefined;
11
+ /** Options used only when this adapter constructs the Pino logger itself. */
12
+ readonly pinoOptions?: LoggerOptions | undefined;
13
+ /** Sink name exposed to Trails observe configuration. Defaults to `pino`. */
14
+ readonly name?: string | undefined;
15
+ }
16
+
17
+ export interface PinoLogSink extends LogSink {
18
+ /** Flush an asynchronously buffered Pino destination, when one is present. */
19
+ flush(): Promise<void>;
20
+ }
21
+
22
+ type ForwardMethod = Exclude<LogLevel, 'silent'>;
23
+
24
+ const LEVEL_MAP: Record<LogLevel, ForwardMethod | undefined> = {
25
+ debug: 'debug',
26
+ error: 'error',
27
+ fatal: 'fatal',
28
+ info: 'info',
29
+ silent: undefined,
30
+ trace: 'trace',
31
+ warn: 'warn',
32
+ };
33
+
34
+ const buildPayload = (record: LogRecord): Record<string, unknown> => ({
35
+ ...record.metadata,
36
+ category: record.category,
37
+ timestamp: record.timestamp.toISOString(),
38
+ });
39
+
40
+ /* oxlint-disable eslint-plugin-promise/avoid-new, eslint-plugin-promise/prefer-await-to-callbacks -- Pino exposes callback-only flush completion; the Trails sink contract is promise-based. */
41
+ const flush = (logger: Logger): Promise<void> =>
42
+ new Promise((resolve, reject) => {
43
+ logger.flush((error) => {
44
+ if (error === null || error === undefined) {
45
+ resolve();
46
+ return;
47
+ }
48
+ reject(error);
49
+ });
50
+ });
51
+ /* oxlint-enable eslint-plugin-promise/avoid-new, eslint-plugin-promise/prefer-await-to-callbacks */
52
+
53
+ const resolveLogger = (options: PinoSinkOptions): Logger => {
54
+ if (options.logger !== undefined) {
55
+ return options.logger;
56
+ }
57
+ if (options.destination !== undefined) {
58
+ return pino(options.pinoOptions ?? {}, options.destination);
59
+ }
60
+ return options.pinoOptions === undefined ? pino() : pino(options.pinoOptions);
61
+ };
62
+
63
+ /**
64
+ * Create a Trails sink backed by a real Pino logger. If no logger is supplied,
65
+ * the adapter constructs one from `pinoOptions`; applications remain free to
66
+ * own destinations, transports, and richer Pino configuration directly.
67
+ */
68
+ export const createPinoSink = (options: PinoSinkOptions = {}): PinoLogSink => {
69
+ const logger = resolveLogger(options);
70
+
71
+ return {
72
+ flush: async (): Promise<void> => await flush(logger),
73
+ name: options.name ?? 'pino',
74
+ write(record: LogRecord): void {
75
+ const method = LEVEL_MAP[record.level];
76
+ if (method === undefined) {
77
+ return;
78
+ }
79
+ logger[method](buildPayload(record), record.message);
80
+ },
81
+ };
82
+ };