@watchtower15/pino 0.0.0-stage → 1.0.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 WatchTower15 Incorporated
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 CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @watchtower15/pino
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A pino transport that ships logs to WatchTower15, with `WT15_LOGS_TOKEN` read from the environment. It runs in pino's worker thread.
4
+
5
+ ```sh
6
+ npm install @watchtower15/sdk @watchtower15/pino pino
7
+ ```
8
+
9
+ ```ts
10
+ import pino from 'pino';
11
+
12
+ const logger = pino(
13
+ { name: 'billing' },
14
+ pino.transport({
15
+ targets: [
16
+ { target: 'pino/file', options: { destination: 1 } },
17
+ { target: '@watchtower15/pino', options: { stream: 'billing' } },
18
+ ],
19
+ }),
20
+ );
21
+ ```
22
+
23
+ Guide: <https://developer.watchtower15.com/sdks/node/pino/>. The support policy of all four packages is in the [core package's README](https://github.com/watchtower15/watchtower15-node/blob/main/packages/sdk/README.md#support-policy): Node.js 22.12 and later, TypeScript 5.0 and later, ES modules and CommonJS.
package/dist/index.cjs ADDED
@@ -0,0 +1,122 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ // \0rolldown/runtime.js
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
+ key = keys[i];
15
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+ let pino_abstract_transport = require("pino-abstract-transport");
27
+ pino_abstract_transport = __toESM(pino_abstract_transport, 1);
28
+ let _watchtower15_sdk = require("@watchtower15/sdk");
29
+ // src/index.ts
30
+ const LEVELS = {
31
+ fatal: "critical",
32
+ error: "error",
33
+ warn: "warning",
34
+ info: "info",
35
+ debug: "debug",
36
+ trace: "debug"
37
+ };
38
+ const NUMBERS = {
39
+ 10: "trace",
40
+ 20: "debug",
41
+ 30: "info",
42
+ 40: "warn",
43
+ 50: "error",
44
+ 60: "fatal"
45
+ };
46
+ const SKIPPED = /* @__PURE__ */ new Set([
47
+ "level",
48
+ "time",
49
+ "msg",
50
+ "pid",
51
+ "hostname"
52
+ ]);
53
+ /** pino's level (a number, or a label) as the API's level: fatal critical, error error, warn warning, info info, debug and trace debug. */
54
+ function levelOf(level) {
55
+ const label = typeof level === "number" ? NUMBERS[Math.round(level / 10) * 10] ?? (level >= 60 ? "fatal" : level >= 50 ? "error" : level >= 40 ? "warn" : level >= 30 ? "info" : level >= 20 ? "debug" : "trace") : String(level);
56
+ return LEVELS[label] ?? "info";
57
+ }
58
+ function timeOf(time) {
59
+ if (typeof time === "number" && Number.isFinite(time)) return new Date(time);
60
+ if (typeof time === "string") {
61
+ const at = new Date(time);
62
+ return Number.isNaN(at.getTime()) ? void 0 : at;
63
+ }
64
+ }
65
+ function stackOf(err) {
66
+ if (typeof err === "string") return err;
67
+ if (typeof err === "object" && err !== null) {
68
+ const { stack, message, type, name } = err;
69
+ if (typeof stack === "string" && stack !== "") return stack;
70
+ return [typeof type === "string" ? type : typeof name === "string" ? name : "Error", typeof message === "string" ? message : ""].filter((part) => part !== "").join(": ");
71
+ }
72
+ return null;
73
+ }
74
+ /** One pino record as a line: `msg`, then the other fields but level, time, msg, pid and hostname as JSON, an `err` as its stack. */
75
+ function toLine(record, stream) {
76
+ const { err, ...rest } = record;
77
+ const fields = {};
78
+ for (const [key, value] of Object.entries(rest)) if (!SKIPPED.has(key)) fields[key] = value;
79
+ let message = typeof record.msg === "string" ? record.msg : "";
80
+ if (Object.keys(fields).length > 0) message = `${message} ${JSON.stringify(fields)}`.trimStart();
81
+ const stack = err === void 0 ? null : stackOf(err);
82
+ if (stack !== null) message = `${message}\n${stack}`;
83
+ const line = {
84
+ message,
85
+ log_level: levelOf(record.level)
86
+ };
87
+ const at = timeOf(record.time);
88
+ if (at !== void 0) line.logged_at = at;
89
+ const name = stream ?? (typeof record.name === "string" ? record.name : void 0);
90
+ if (name !== void 0) line.stream_name = name;
91
+ if (record.wt15_report !== void 0) line.wt15_report = record.wt15_report;
92
+ return line;
93
+ }
94
+ /**
95
+ * The pino transport (D20), built on `pino-abstract-transport`, running in pino's worker thread: it builds its own client from its options (or
96
+ * `WT15_LOGS_TOKEN`), ships each record through a `LogShipper`, and awaits the shipper's flush when it closes.
97
+ */
98
+ function createPinoTransport(options = {}, deps = {}) {
99
+ const overrides = {};
100
+ if (options.logsToken !== void 0) overrides.logsToken = options.logsToken;
101
+ if (options.ingestUrl !== void 0) overrides.ingestUrl = options.ingestUrl;
102
+ const selfLogger = deps.selfLogger ?? (options.selfLog === true ? {
103
+ debug: () => void 0,
104
+ info: () => void 0,
105
+ error: () => void 0,
106
+ warn: (message) => void process.stderr.write(`${message}\n`)
107
+ } : null);
108
+ const shipper = new _watchtower15_sdk.LogShipper({
109
+ client: deps.client ?? (() => _watchtower15_sdk.WatchTower15.fromEnvironment(overrides)),
110
+ ...options.batchSize === void 0 ? {} : { batchSize: options.batchSize },
111
+ selfLogger
112
+ });
113
+ return (0, pino_abstract_transport.default)(async (source) => {
114
+ for await (const record of source) if (typeof record === "object" && record !== null) shipper.push(toLine(record, options.stream));
115
+ }, { async close() {
116
+ await shipper.close();
117
+ } });
118
+ }
119
+ exports.createPinoTransport = createPinoTransport;
120
+ exports.default = createPinoTransport;
121
+ exports.levelOf = levelOf;
122
+ exports.toLine = toLine;
@@ -0,0 +1,30 @@
1
+ import build from "pino-abstract-transport";
2
+ import { ClientLogger, LogLineInput, WatchTower15 } from "@watchtower15/sdk";
3
+ /** What `pino.transport({ target: '@watchtower15/pino', options })` takes (D20): everything crosses into a worker thread, so every option is plain data. */
4
+ export interface WatchTower15PinoOptions {
5
+ /** A log source token, `wt15ls_…`; `WT15_LOGS_TOKEN` when absent. */
6
+ logsToken?: string;
7
+ /** The ingest base URL; `WT15_INGEST_URL` or the default when absent. */
8
+ ingestUrl?: string;
9
+ /** The stream name of every record; the record's `name` when absent. */
10
+ stream?: string;
11
+ /** Lines in a batch: 100 when absent. */
12
+ batchSize?: number;
13
+ /** Writes a report of lines not sent to standard error (a worker cannot take a logger object). */
14
+ selfLog?: boolean;
15
+ }
16
+ /** What the transport needs besides its options: a test gives its own client. */
17
+ export interface PinoTransportDeps {
18
+ client?: () => WatchTower15;
19
+ selfLogger?: ClientLogger;
20
+ }
21
+ /** pino's level (a number, or a label) as the API's level: fatal critical, error error, warn warning, info info, debug and trace debug. */
22
+ export declare function levelOf(level: unknown): string;
23
+ /** One pino record as a line: `msg`, then the other fields but level, time, msg, pid and hostname as JSON, an `err` as its stack. */
24
+ export declare function toLine(record: Record<string, unknown>, stream: string | undefined): LogLineInput;
25
+ /**
26
+ * The pino transport (D20), built on `pino-abstract-transport`, running in pino's worker thread: it builds its own client from its options (or
27
+ * `WT15_LOGS_TOKEN`), ships each record through a `LogShipper`, and awaits the shipper's flush when it closes.
28
+ */
29
+ export declare function createPinoTransport(options?: WatchTower15PinoOptions, deps?: PinoTransportDeps): ReturnType<typeof build>;
30
+ export { createPinoTransport as default };
@@ -0,0 +1,30 @@
1
+ import build from "pino-abstract-transport";
2
+ import { ClientLogger, LogLineInput, WatchTower15 } from "@watchtower15/sdk";
3
+ /** What `pino.transport({ target: '@watchtower15/pino', options })` takes (D20): everything crosses into a worker thread, so every option is plain data. */
4
+ export interface WatchTower15PinoOptions {
5
+ /** A log source token, `wt15ls_…`; `WT15_LOGS_TOKEN` when absent. */
6
+ logsToken?: string;
7
+ /** The ingest base URL; `WT15_INGEST_URL` or the default when absent. */
8
+ ingestUrl?: string;
9
+ /** The stream name of every record; the record's `name` when absent. */
10
+ stream?: string;
11
+ /** Lines in a batch: 100 when absent. */
12
+ batchSize?: number;
13
+ /** Writes a report of lines not sent to standard error (a worker cannot take a logger object). */
14
+ selfLog?: boolean;
15
+ }
16
+ /** What the transport needs besides its options: a test gives its own client. */
17
+ export interface PinoTransportDeps {
18
+ client?: () => WatchTower15;
19
+ selfLogger?: ClientLogger;
20
+ }
21
+ /** pino's level (a number, or a label) as the API's level: fatal critical, error error, warn warning, info info, debug and trace debug. */
22
+ export declare function levelOf(level: unknown): string;
23
+ /** One pino record as a line: `msg`, then the other fields but level, time, msg, pid and hostname as JSON, an `err` as its stack. */
24
+ export declare function toLine(record: Record<string, unknown>, stream: string | undefined): LogLineInput;
25
+ /**
26
+ * The pino transport (D20), built on `pino-abstract-transport`, running in pino's worker thread: it builds its own client from its options (or
27
+ * `WT15_LOGS_TOKEN`), ships each record through a `LogShipper`, and awaits the shipper's flush when it closes.
28
+ */
29
+ export declare function createPinoTransport(options?: WatchTower15PinoOptions, deps?: PinoTransportDeps): ReturnType<typeof build>;
30
+ export { createPinoTransport as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,93 @@
1
+ import build from "pino-abstract-transport";
2
+ import { LogShipper, WatchTower15 } from "@watchtower15/sdk";
3
+ // src/index.ts
4
+ const LEVELS = {
5
+ fatal: "critical",
6
+ error: "error",
7
+ warn: "warning",
8
+ info: "info",
9
+ debug: "debug",
10
+ trace: "debug"
11
+ };
12
+ const NUMBERS = {
13
+ 10: "trace",
14
+ 20: "debug",
15
+ 30: "info",
16
+ 40: "warn",
17
+ 50: "error",
18
+ 60: "fatal"
19
+ };
20
+ const SKIPPED = /* @__PURE__ */ new Set([
21
+ "level",
22
+ "time",
23
+ "msg",
24
+ "pid",
25
+ "hostname"
26
+ ]);
27
+ /** pino's level (a number, or a label) as the API's level: fatal critical, error error, warn warning, info info, debug and trace debug. */
28
+ function levelOf(level) {
29
+ const label = typeof level === "number" ? NUMBERS[Math.round(level / 10) * 10] ?? (level >= 60 ? "fatal" : level >= 50 ? "error" : level >= 40 ? "warn" : level >= 30 ? "info" : level >= 20 ? "debug" : "trace") : String(level);
30
+ return LEVELS[label] ?? "info";
31
+ }
32
+ function timeOf(time) {
33
+ if (typeof time === "number" && Number.isFinite(time)) return new Date(time);
34
+ if (typeof time === "string") {
35
+ const at = new Date(time);
36
+ return Number.isNaN(at.getTime()) ? void 0 : at;
37
+ }
38
+ }
39
+ function stackOf(err) {
40
+ if (typeof err === "string") return err;
41
+ if (typeof err === "object" && err !== null) {
42
+ const { stack, message, type, name } = err;
43
+ if (typeof stack === "string" && stack !== "") return stack;
44
+ return [typeof type === "string" ? type : typeof name === "string" ? name : "Error", typeof message === "string" ? message : ""].filter((part) => part !== "").join(": ");
45
+ }
46
+ return null;
47
+ }
48
+ /** One pino record as a line: `msg`, then the other fields but level, time, msg, pid and hostname as JSON, an `err` as its stack. */
49
+ function toLine(record, stream) {
50
+ const { err, ...rest } = record;
51
+ const fields = {};
52
+ for (const [key, value] of Object.entries(rest)) if (!SKIPPED.has(key)) fields[key] = value;
53
+ let message = typeof record.msg === "string" ? record.msg : "";
54
+ if (Object.keys(fields).length > 0) message = `${message} ${JSON.stringify(fields)}`.trimStart();
55
+ const stack = err === void 0 ? null : stackOf(err);
56
+ if (stack !== null) message = `${message}\n${stack}`;
57
+ const line = {
58
+ message,
59
+ log_level: levelOf(record.level)
60
+ };
61
+ const at = timeOf(record.time);
62
+ if (at !== void 0) line.logged_at = at;
63
+ const name = stream ?? (typeof record.name === "string" ? record.name : void 0);
64
+ if (name !== void 0) line.stream_name = name;
65
+ if (record.wt15_report !== void 0) line.wt15_report = record.wt15_report;
66
+ return line;
67
+ }
68
+ /**
69
+ * The pino transport (D20), built on `pino-abstract-transport`, running in pino's worker thread: it builds its own client from its options (or
70
+ * `WT15_LOGS_TOKEN`), ships each record through a `LogShipper`, and awaits the shipper's flush when it closes.
71
+ */
72
+ function createPinoTransport(options = {}, deps = {}) {
73
+ const overrides = {};
74
+ if (options.logsToken !== void 0) overrides.logsToken = options.logsToken;
75
+ if (options.ingestUrl !== void 0) overrides.ingestUrl = options.ingestUrl;
76
+ const selfLogger = deps.selfLogger ?? (options.selfLog === true ? {
77
+ debug: () => void 0,
78
+ info: () => void 0,
79
+ error: () => void 0,
80
+ warn: (message) => void process.stderr.write(`${message}\n`)
81
+ } : null);
82
+ const shipper = new LogShipper({
83
+ client: deps.client ?? (() => WatchTower15.fromEnvironment(overrides)),
84
+ ...options.batchSize === void 0 ? {} : { batchSize: options.batchSize },
85
+ selfLogger
86
+ });
87
+ return build(async (source) => {
88
+ for await (const record of source) if (typeof record === "object" && record !== null) shipper.push(toLine(record, options.stream));
89
+ }, { async close() {
90
+ await shipper.close();
91
+ } });
92
+ }
93
+ export { createPinoTransport, createPinoTransport as default, levelOf, toLine };
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@watchtower15/pino",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "A pino transport that ships logs to WatchTower15.",
5
+ "keywords": [
6
+ "watchtower15",
7
+ "monitoring",
8
+ "observability",
9
+ "pino",
10
+ "logging",
11
+ "transport"
12
+ ],
13
+ "homepage": "https://developer.watchtower15.com/sdks/node/pino/",
14
+ "bugs": {
15
+ "url": "https://github.com/watchtower15/watchtower15-node/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/watchtower15/watchtower15-node.git",
20
+ "directory": "packages/pino"
21
+ },
22
+ "license": "MIT",
23
+ "author": "WatchTower15 <contact@watchtower15.com>",
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "engines": {
27
+ "node": ">=22.12"
28
+ },
29
+ "main": "./dist/index.cjs",
30
+ "types": "./dist/index.d.cts",
31
+ "exports": {
32
+ ".": {
33
+ "import": {
34
+ "types": "./dist/index.d.mts",
35
+ "default": "./dist/index.mjs"
36
+ },
37
+ "require": {
38
+ "types": "./dist/index.d.cts",
39
+ "default": "./dist/index.cjs"
40
+ }
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "README.md",
47
+ "LICENSE"
48
+ ],
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "test": "vitest run --root ../.. --project unit packages/pino"
52
+ },
53
+ "dependencies": {
54
+ "pino-abstract-transport": "^3.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "pino": "10.4.0"
58
+ },
59
+ "peerDependencies": {
60
+ "@watchtower15/sdk": "^1.0.0",
61
+ "pino": "^9.0.0 || ^10.0.0"
62
+ }
63
+ }