@abbacchio/transport 0.1.2 → 0.1.4

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,5 +1,6 @@
1
1
  import build from "pino-abstract-transport";
2
2
  import { AbbacchioClient } from "../client.js";
3
+ import { Transform } from "stream";
3
4
  /**
4
5
  * Pino transport for Abbacchio.
5
6
  *
@@ -13,6 +14,7 @@ import { AbbacchioClient } from "../client.js";
13
14
  * options: {
14
15
  * url: "http://localhost:4000/api/logs",
15
16
  * channel: "my-app",
17
+ * namespace: "auth-service",
16
18
  * secretKey: "optional-encryption-key",
17
19
  * },
18
20
  * },
@@ -39,4 +41,72 @@ export default async function pinoTransport(opts = {}) {
39
41
  * Named export for programmatic usage
40
42
  */
41
43
  export { pinoTransport };
44
+ /**
45
+ * Create a Pino destination stream with direct access to the client.
46
+ * Use this when you need to change the channel dynamically.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import pino from "pino";
51
+ * import { createPinoStream } from "@abbacchio/transport/transports/pino";
52
+ *
53
+ * const stream = createPinoStream({
54
+ * url: "http://localhost:4000/api/logs",
55
+ * channel: "initial-channel",
56
+ * });
57
+ *
58
+ * const logger = pino(stream);
59
+ *
60
+ * logger.info("Log to initial channel");
61
+ *
62
+ * // Change channel dynamically
63
+ * stream.setChannel("new-channel");
64
+ *
65
+ * logger.info("Log to new channel");
66
+ * ```
67
+ */
68
+ export function createPinoStream(opts = {}) {
69
+ const client = new AbbacchioClient(opts);
70
+ const stream = new Transform({
71
+ objectMode: true,
72
+ transform(chunk, _encoding, callback) {
73
+ try {
74
+ const log = typeof chunk === "string" ? JSON.parse(chunk) : chunk;
75
+ client.add(log);
76
+ callback();
77
+ }
78
+ catch (err) {
79
+ callback(err);
80
+ }
81
+ },
82
+ flush(callback) {
83
+ client.flush().then(() => callback()).catch(callback);
84
+ },
85
+ });
86
+ stream.setChannel = (channel) => {
87
+ client.setChannel(channel);
88
+ };
89
+ stream.getChannel = () => {
90
+ return client.getChannel();
91
+ };
92
+ stream.setNamespace = (namespace) => {
93
+ client.setNamespace(namespace);
94
+ };
95
+ stream.getNamespace = () => {
96
+ return client.getNamespace();
97
+ };
98
+ stream.enable = () => {
99
+ client.enable();
100
+ };
101
+ stream.disable = () => {
102
+ client.disable();
103
+ };
104
+ stream.isEnabled = () => {
105
+ return client.isEnabled();
106
+ };
107
+ stream.close = async () => {
108
+ await client.close();
109
+ };
110
+ return stream;
111
+ }
42
112
  //# sourceMappingURL=pino.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pino.js","sourceRoot":"","sources":["../../src/transports/pino.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAA+B,MAAM,cAAc,CAAC;AAI5E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B,EAAE;IACzE,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IAEzC,OAAO,KAAK,CACV,KAAK,WAAW,MAAM;QACpB,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QACD,2BAA2B;QAC3B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC,EACD;QACE,KAAK,CAAC,KAAK;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;KACF,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"pino.js","sourceRoot":"","sources":["../../src/transports/pino.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAA+B,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,SAAS,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IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACxD,CAAC;KACF,CAAwB,CAAC;IAE1B,MAAM,CAAC,UAAU,GAAG,CAAC,OAA2B,EAAE,EAAE;QAClD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,MAAM,CAAC,UAAU,GAAG,GAAG,EAAE;QACvB,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC,CAAC;IAEF,MAAM,CAAC,YAAY,GAAG,CAAC,SAA6B,EAAE,EAAE;QACtD,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,MAAM,CAAC,YAAY,GAAG,GAAG,EAAE;QACzB,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC;IAC/B,CAAC,CAAC;IAEF,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;QACnB,MAAM,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC,CAAC;IAEF,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;QACpB,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,CAAC,SAAS,GAAG,GAAG,EAAE;QACtB,OAAO,MAAM,CAAC,SAAS,EAAE,CAAC;IAC5B,CAAC,CAAC;IAEF,MAAM,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE;QACxB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -42,6 +42,34 @@ export declare class AbbacchioWinstonTransport extends TransportStream {
42
42
  * Convert Winston level string to Pino-style number
43
43
  */
44
44
  private levelToNumber;
45
+ /**
46
+ * Change the channel dynamically
47
+ */
48
+ setChannel(channel: string | undefined): void;
49
+ /**
50
+ * Get the current channel
51
+ */
52
+ getChannel(): string | undefined;
53
+ /**
54
+ * Change the namespace dynamically
55
+ */
56
+ setNamespace(namespace: string | undefined): void;
57
+ /**
58
+ * Get the current namespace
59
+ */
60
+ getNamespace(): string | undefined;
61
+ /**
62
+ * Enable sending logs to the server
63
+ */
64
+ enable(): void;
65
+ /**
66
+ * Disable sending logs to the server
67
+ */
68
+ disable(): void;
69
+ /**
70
+ * Check if the client is currently enabled
71
+ */
72
+ isEnabled(): boolean;
45
73
  /**
46
74
  * Close the transport
47
75
  */
@@ -1 +1 @@
1
- {"version":3,"file":"winston.d.ts","sourceRoot":"","sources":["../../src/transports/winston.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE5E,MAAM,WAAW,uBAAwB,SAAQ,sBAAsB;IACrE,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,yBAA0B,SAAQ,eAAe;IAC5D,OAAO,CAAC,MAAM,CAAkB;gBAEpB,IAAI,GAAE,uBAA4B;IAK9C;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAY9D;;OAEG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,uBAAuB,GAAG,yBAAyB,CAE1F;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"winston.d.ts","sourceRoot":"","sources":["../../src/transports/winston.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE5E,MAAM,WAAW,uBAAwB,SAAQ,sBAAsB;IACrE,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,yBAA0B,SAAQ,eAAe;IAC5D,OAAO,CAAC,MAAM,CAAkB;gBAEpB,IAAI,GAAE,uBAA4B;IAK9C;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAY9D;;OAEG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAI7C;;OAEG;IACH,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAIjD;;OAEG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,IAAI,IAAI;IAIf;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,uBAAuB,GAAG,yBAAyB,CAE1F;AAED,eAAe,gBAAgB,CAAC"}
@@ -68,6 +68,48 @@ export class AbbacchioWinstonTransport extends TransportStream {
68
68
  };
69
69
  return levels[level] || 30;
70
70
  }
71
+ /**
72
+ * Change the channel dynamically
73
+ */
74
+ setChannel(channel) {
75
+ this.client.setChannel(channel);
76
+ }
77
+ /**
78
+ * Get the current channel
79
+ */
80
+ getChannel() {
81
+ return this.client.getChannel();
82
+ }
83
+ /**
84
+ * Change the namespace dynamically
85
+ */
86
+ setNamespace(namespace) {
87
+ this.client.setNamespace(namespace);
88
+ }
89
+ /**
90
+ * Get the current namespace
91
+ */
92
+ getNamespace() {
93
+ return this.client.getNamespace();
94
+ }
95
+ /**
96
+ * Enable sending logs to the server
97
+ */
98
+ enable() {
99
+ this.client.enable();
100
+ }
101
+ /**
102
+ * Disable sending logs to the server
103
+ */
104
+ disable() {
105
+ this.client.disable();
106
+ }
107
+ /**
108
+ * Check if the client is currently enabled
109
+ */
110
+ isEnabled() {
111
+ return this.client.isEnabled();
112
+ }
71
113
  /**
72
114
  * Close the transport
73
115
  */
@@ -1 +1 @@
1
- {"version":3,"file":"winston.js","sourceRoot":"","sources":["../../src/transports/winston.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAA+B,MAAM,cAAc,CAAC;AAO5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,yBAA0B,SAAQ,eAAe;IACpD,MAAM,CAAkB;IAEhC,YAAY,OAAgC,EAAE;QAC5C,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,IAA6B,EAAE,QAAoB;QACrD,YAAY,CAAC,GAAG,EAAE;YAChB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,+CAA+C;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAErB,QAAQ,EAAE,CAAC;IACb,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,IAA6B;QAChD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,E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CAAC;IAClC,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,SAA6B;QACxC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAA8B;IAC7D,OAAO,IAAI,yBAAyB,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC;AAED,eAAe,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abbacchio/transport",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Node.js log transports for Pino, Winston, and Bunyan - send logs to Abbacchio",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,8 +10,9 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "default": "./dist/index.js"
12
12
  },
13
- "./transports/pino": {
13
+ "./pino": {
14
14
  "types": "./dist/transports/pino.d.ts",
15
+ "require": "./pino-transport.cjs",
15
16
  "default": "./dist/transports/pino.js"
16
17
  },
17
18
  "./transports/winston": {
@@ -27,6 +28,10 @@
27
28
  "default": "./dist/transports/console.js"
28
29
  }
29
30
  },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "dev": "tsc --watch"
34
+ },
30
35
  "keywords": [
31
36
  "pino",
32
37
  "winston",
@@ -42,15 +47,24 @@
42
47
  "pino-abstract-transport": "^3.0.0",
43
48
  "winston-transport": "^4.9.0"
44
49
  },
50
+ "peerDependencies": {
51
+ "pino": "^8.0.0 || ^9.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "pino": {
55
+ "optional": true
56
+ }
57
+ },
45
58
  "devDependencies": {
46
59
  "@types/node": "^22.10.5",
60
+ "pino": "^9.0.0",
47
61
  "typescript": "^5.7.2"
48
62
  },
49
63
  "engines": {
50
64
  "node": ">=18"
51
65
  },
52
- "scripts": {
53
- "build": "tsc",
54
- "dev": "tsc --watch"
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "https://github.com/mood-agency/abbacchio"
55
69
  }
56
- }
70
+ }
@@ -0,0 +1,30 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * CommonJS wrapper for the Pino transport.
5
+ *
6
+ * Pino runs transports in worker threads using require(), which doesn't
7
+ * work well with ESM subpath exports. This CJS wrapper allows users to
8
+ * simply use: target: '@abbacchio/transport'
9
+ *
10
+ * @example
11
+ * ```javascript
12
+ * const pino = require('pino');
13
+ *
14
+ * const logger = pino({
15
+ * transport: {
16
+ * target: '@abbacchio/transport',
17
+ * options: {
18
+ * url: 'http://localhost:4000/api/logs',
19
+ * channel: 'my-app',
20
+ * },
21
+ * },
22
+ * });
23
+ * ```
24
+ */
25
+
26
+ // Dynamic import the ESM module
27
+ module.exports = async function(opts) {
28
+ const { default: pinoTransport } = await import('./dist/transports/pino.js');
29
+ return pinoTransport(opts);
30
+ };
package/src/client.ts CHANGED
@@ -7,12 +7,16 @@ export interface AbbacchioClientOptions {
7
7
  secretKey?: string;
8
8
  /** Channel/app name for multi-app support. Defaults to 'default' */
9
9
  channel?: string;
10
+ /** Default namespace for all logs. Per-log namespace/name fields take precedence */
11
+ namespace?: string;
10
12
  /** Number of logs to batch before sending. Defaults to 10 */
11
13
  batchSize?: number;
12
14
  /** Interval in ms between flushes. Defaults to 1000 */
13
15
  interval?: number;
14
16
  /** Additional headers to send with requests */
15
17
  headers?: Record<string, string>;
18
+ /** Whether to send logs to the server. Defaults to true */
19
+ enabled?: boolean;
16
20
  }
17
21
 
18
22
  /**
@@ -23,9 +27,11 @@ export class AbbacchioClient {
23
27
  private url: string;
24
28
  private secretKey?: string;
25
29
  private channel?: string;
30
+ private namespace?: string;
26
31
  private batchSize: number;
27
32
  private interval: number;
28
33
  private headers: Record<string, string>;
34
+ private enabled: boolean;
29
35
 
30
36
  private buffer: unknown[] = [];
31
37
  private timer: ReturnType<typeof setTimeout> | null = null;
@@ -34,25 +40,86 @@ export class AbbacchioClient {
34
40
  this.url = options.url || "http://localhost:4000/api/logs";
35
41
  this.secretKey = options.secretKey;
36
42
  this.channel = options.channel;
43
+ this.namespace = options.namespace;
37
44
  this.batchSize = options.batchSize || 10;
38
45
  this.interval = options.interval || 1000;
39
46
  this.headers = options.headers || {};
47
+ this.enabled = options.enabled ?? true;
40
48
  }
41
49
 
42
50
  /**
43
- * Process a log entry (encrypt if secretKey is provided)
51
+ * Change the channel dynamically after initialization
52
+ */
53
+ setChannel(channel: string | undefined): void {
54
+ this.channel = channel;
55
+ }
56
+
57
+ /**
58
+ * Get the current channel
59
+ */
60
+ getChannel(): string | undefined {
61
+ return this.channel;
62
+ }
63
+
64
+ /**
65
+ * Change the namespace dynamically after initialization
66
+ */
67
+ setNamespace(namespace: string | undefined): void {
68
+ this.namespace = namespace;
69
+ }
70
+
71
+ /**
72
+ * Get the current namespace
73
+ */
74
+ getNamespace(): string | undefined {
75
+ return this.namespace;
76
+ }
77
+
78
+ /**
79
+ * Enable sending logs to the server
80
+ */
81
+ enable(): void {
82
+ this.enabled = true;
83
+ }
84
+
85
+ /**
86
+ * Disable sending logs to the server. Logs will be silently dropped.
87
+ */
88
+ disable(): void {
89
+ this.enabled = false;
90
+ }
91
+
92
+ /**
93
+ * Check if the client is currently enabled
94
+ */
95
+ isEnabled(): boolean {
96
+ return this.enabled;
97
+ }
98
+
99
+ /**
100
+ * Process a log entry: inject default namespace, then encrypt if needed
44
101
  */
45
102
  private processLog(log: unknown): unknown {
103
+ let processed = log;
104
+
105
+ if (this.namespace && typeof processed === 'object' && processed !== null) {
106
+ const obj = processed as Record<string, unknown>;
107
+ if (!obj.namespace && !obj.name) {
108
+ processed = { ...obj, namespace: this.namespace };
109
+ }
110
+ }
111
+
46
112
  if (this.secretKey) {
47
- return { encrypted: encrypt(JSON.stringify(log), this.secretKey) };
113
+ return { encrypted: encrypt(JSON.stringify(processed), this.secretKey) };
48
114
  }
49
- return log;
115
+ return processed;
50
116
  }
51
117
 
52
118
  /**
53
119
  * Add a log to the buffer and trigger send if needed
54
120
  */
55
121
  add(log: unknown): void {
122
+ if (!this.enabled) return;
56
123
  this.buffer.push(this.processLog(log));
57
124
 
58
125
  if (this.buffer.length >= this.batchSize) {
@@ -66,6 +133,7 @@ export class AbbacchioClient {
66
133
  * Add multiple logs at once
67
134
  */
68
135
  addBatch(logs: unknown[]): void {
136
+ if (!this.enabled) return;
69
137
  for (const log of logs) {
70
138
  this.buffer.push(this.processLog(log));
71
139
  }
@@ -81,6 +149,7 @@ export class AbbacchioClient {
81
149
  * Send logs immediately without batching
82
150
  */
83
151
  async send(logs: unknown[]): Promise<void> {
152
+ if (!this.enabled) return;
84
153
  const processedLogs = logs.map(log => this.processLog(log));
85
154
  await this.sendToServer(processedLogs);
86
155
  }
package/src/index.ts CHANGED
@@ -15,5 +15,5 @@ export type { WinstonTransportOptions } from "./transports/winston.js";
15
15
  export { bunyanStream, AbbacchioBunyanStream } from "./transports/bunyan.js";
16
16
  export type { BunyanStreamOptions } from "./transports/bunyan.js";
17
17
 
18
- export { interceptConsole, restoreConsole, getActiveClient } from "./transports/console.js";
19
- export type { ConsoleInterceptorOptions } from "./transports/console.js";
18
+ export { createPinoStream } from "./transports/pino.js";
19
+ export type { AbbacchioPinoStream } from "./transports/pino.js";
@@ -75,6 +75,55 @@ export class AbbacchioBunyanStream extends Writable {
75
75
  };
76
76
  }
77
77
 
78
+ /**
79
+ * Change the channel dynamically
80
+ */
81
+ setChannel(channel: string | undefined): void {
82
+ this.client.setChannel(channel);
83
+ }
84
+
85
+ /**
86
+ * Get the current channel
87
+ */
88
+ getChannel(): string | undefined {
89
+ return this.client.getChannel();
90
+ }
91
+
92
+ /**
93
+ * Change the namespace dynamically
94
+ */
95
+ setNamespace(namespace: string | undefined): void {
96
+ this.client.setNamespace(namespace);
97
+ }
98
+
99
+ /**
100
+ * Get the current namespace
101
+ */
102
+ getNamespace(): string | undefined {
103
+ return this.client.getNamespace();
104
+ }
105
+
106
+ /**
107
+ * Enable sending logs to the server
108
+ */
109
+ enable(): void {
110
+ this.client.enable();
111
+ }
112
+
113
+ /**
114
+ * Disable sending logs to the server
115
+ */
116
+ disable(): void {
117
+ this.client.disable();
118
+ }
119
+
120
+ /**
121
+ * Check if the client is currently enabled
122
+ */
123
+ isEnabled(): boolean {
124
+ return this.client.isEnabled();
125
+ }
126
+
78
127
  /**
79
128
  * Close the stream
80
129
  */
@@ -10,6 +10,6 @@ export type { WinstonTransportOptions } from "./winston.js";
10
10
  export { bunyanStream, AbbacchioBunyanStream } from "./bunyan.js";
11
11
  export type { BunyanStreamOptions } from "./bunyan.js";
12
12
 
13
- // Console interceptor
14
- export { interceptConsole, restoreConsole, getActiveClient } from "./console.js";
15
- export type { ConsoleInterceptorOptions } from "./console.js";
13
+ // Pino stream with dynamic channel support
14
+ export { createPinoStream } from "./pino.js";
15
+ export type { AbbacchioPinoStream } from "./pino.js";
@@ -1,8 +1,28 @@
1
1
  import build from "pino-abstract-transport";
2
2
  import { AbbacchioClient, type AbbacchioClientOptions } from "../client.js";
3
+ import { Transform } from "stream";
3
4
 
4
5
  export interface PinoTransportOptions extends AbbacchioClientOptions {}
5
6
 
7
+ export interface AbbacchioPinoStream extends Transform {
8
+ /** Change the channel dynamically */
9
+ setChannel(channel: string | undefined): void;
10
+ /** Get the current channel */
11
+ getChannel(): string | undefined;
12
+ /** Change the namespace dynamically */
13
+ setNamespace(namespace: string | undefined): void;
14
+ /** Get the current namespace */
15
+ getNamespace(): string | undefined;
16
+ /** Enable sending logs to the server */
17
+ enable(): void;
18
+ /** Disable sending logs to the server */
19
+ disable(): void;
20
+ /** Check if the client is currently enabled */
21
+ isEnabled(): boolean;
22
+ /** Flush pending logs and close the client */
23
+ close(): Promise<void>;
24
+ }
25
+
6
26
  /**
7
27
  * Pino transport for Abbacchio.
8
28
  *
@@ -16,6 +36,7 @@ export interface PinoTransportOptions extends AbbacchioClientOptions {}
16
36
  * options: {
17
37
  * url: "http://localhost:4000/api/logs",
18
38
  * channel: "my-app",
39
+ * namespace: "auth-service",
19
40
  * secretKey: "optional-encryption-key",
20
41
  * },
21
42
  * },
@@ -47,3 +68,81 @@ export default async function pinoTransport(opts: PinoTransportOptions = {}) {
47
68
  * Named export for programmatic usage
48
69
  */
49
70
  export { pinoTransport };
71
+
72
+ /**
73
+ * Create a Pino destination stream with direct access to the client.
74
+ * Use this when you need to change the channel dynamically.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import pino from "pino";
79
+ * import { createPinoStream } from "@abbacchio/transport/transports/pino";
80
+ *
81
+ * const stream = createPinoStream({
82
+ * url: "http://localhost:4000/api/logs",
83
+ * channel: "initial-channel",
84
+ * });
85
+ *
86
+ * const logger = pino(stream);
87
+ *
88
+ * logger.info("Log to initial channel");
89
+ *
90
+ * // Change channel dynamically
91
+ * stream.setChannel("new-channel");
92
+ *
93
+ * logger.info("Log to new channel");
94
+ * ```
95
+ */
96
+ export function createPinoStream(opts: PinoTransportOptions = {}): AbbacchioPinoStream {
97
+ const client = new AbbacchioClient(opts);
98
+
99
+ const stream = new Transform({
100
+ objectMode: true,
101
+ transform(chunk, _encoding, callback) {
102
+ try {
103
+ const log = typeof chunk === "string" ? JSON.parse(chunk) : chunk;
104
+ client.add(log);
105
+ callback();
106
+ } catch (err) {
107
+ callback(err as Error);
108
+ }
109
+ },
110
+ flush(callback) {
111
+ client.flush().then(() => callback()).catch(callback);
112
+ },
113
+ }) as AbbacchioPinoStream;
114
+
115
+ stream.setChannel = (channel: string | undefined) => {
116
+ client.setChannel(channel);
117
+ };
118
+
119
+ stream.getChannel = () => {
120
+ return client.getChannel();
121
+ };
122
+
123
+ stream.setNamespace = (namespace: string | undefined) => {
124
+ client.setNamespace(namespace);
125
+ };
126
+
127
+ stream.getNamespace = () => {
128
+ return client.getNamespace();
129
+ };
130
+
131
+ stream.enable = () => {
132
+ client.enable();
133
+ };
134
+
135
+ stream.disable = () => {
136
+ client.disable();
137
+ };
138
+
139
+ stream.isEnabled = () => {
140
+ return client.isEnabled();
141
+ };
142
+
143
+ stream.close = async () => {
144
+ await client.close();
145
+ };
146
+
147
+ return stream;
148
+ }
@@ -82,6 +82,55 @@ export class AbbacchioWinstonTransport extends TransportStream {
82
82
  return levels[level] || 30;
83
83
  }
84
84
 
85
+ /**
86
+ * Change the channel dynamically
87
+ */
88
+ setChannel(channel: string | undefined): void {
89
+ this.client.setChannel(channel);
90
+ }
91
+
92
+ /**
93
+ * Get the current channel
94
+ */
95
+ getChannel(): string | undefined {
96
+ return this.client.getChannel();
97
+ }
98
+
99
+ /**
100
+ * Change the namespace dynamically
101
+ */
102
+ setNamespace(namespace: string | undefined): void {
103
+ this.client.setNamespace(namespace);
104
+ }
105
+
106
+ /**
107
+ * Get the current namespace
108
+ */
109
+ getNamespace(): string | undefined {
110
+ return this.client.getNamespace();
111
+ }
112
+
113
+ /**
114
+ * Enable sending logs to the server
115
+ */
116
+ enable(): void {
117
+ this.client.enable();
118
+ }
119
+
120
+ /**
121
+ * Disable sending logs to the server
122
+ */
123
+ disable(): void {
124
+ this.client.disable();
125
+ }
126
+
127
+ /**
128
+ * Check if the client is currently enabled
129
+ */
130
+ isEnabled(): boolean {
131
+ return this.client.isEnabled();
132
+ }
133
+
85
134
  /**
86
135
  * Close the transport
87
136
  */