@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.
- package/README.md +154 -0
- package/dist/client.d.ts +35 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +62 -3
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/transports/bunyan.d.ts +28 -0
- package/dist/transports/bunyan.d.ts.map +1 -1
- package/dist/transports/bunyan.js +42 -0
- package/dist/transports/bunyan.js.map +1 -1
- package/dist/transports/index.d.ts +2 -2
- package/dist/transports/index.d.ts.map +1 -1
- package/dist/transports/index.js +2 -2
- package/dist/transports/index.js.map +1 -1
- package/dist/transports/pino.d.ts +46 -1
- package/dist/transports/pino.d.ts.map +1 -1
- package/dist/transports/pino.js +70 -0
- package/dist/transports/pino.js.map +1 -1
- package/dist/transports/winston.d.ts +28 -0
- package/dist/transports/winston.d.ts.map +1 -1
- package/dist/transports/winston.js +42 -0
- package/dist/transports/winston.js.map +1 -1
- package/package.json +20 -6
- package/pino-transport.cjs +30 -0
- package/src/client.ts +72 -3
- package/src/index.ts +2 -2
- package/src/transports/bunyan.ts +49 -0
- package/src/transports/index.ts +3 -3
- package/src/transports/pino.ts +99 -0
- package/src/transports/winston.ts +49 -0
- package/dist/transports/console.d.ts +0 -21
- package/dist/transports/console.d.ts.map +0 -1
- package/dist/transports/console.js +0 -119
- package/dist/transports/console.js.map +0 -1
- package/src/transports/console.ts +0 -147
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AbbacchioClient, type AbbacchioClientOptions } from "../client.js";
|
|
2
|
-
export interface ConsoleInterceptorOptions extends AbbacchioClientOptions {
|
|
3
|
-
/** Which console methods to intercept. Defaults to all. */
|
|
4
|
-
methods?: ("log" | "info" | "warn" | "error" | "debug")[];
|
|
5
|
-
/** Whether to still output to original console. Defaults to true. */
|
|
6
|
-
passthrough?: boolean;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Start intercepting console calls
|
|
10
|
-
*/
|
|
11
|
-
export declare function interceptConsole(opts?: ConsoleInterceptorOptions): void;
|
|
12
|
-
/**
|
|
13
|
-
* Stop intercepting console calls and restore original behavior
|
|
14
|
-
*/
|
|
15
|
-
export declare function restoreConsole(): void;
|
|
16
|
-
/**
|
|
17
|
-
* Get the active client (for testing)
|
|
18
|
-
*/
|
|
19
|
-
export declare function getActiveClient(): AbbacchioClient | null;
|
|
20
|
-
export default interceptConsole;
|
|
21
|
-
//# sourceMappingURL=console.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/transports/console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE5E,MAAM,WAAW,yBAA0B,SAAQ,sBAAsB;IACvE,2DAA2D;IAC3D,OAAO,CAAC,EAAE,CAAC,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC;IAC1D,qEAAqE;IACrE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AA0FD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,yBAA8B,GAAG,IAAI,CAoB3E;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAYrC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,eAAe,GAAG,IAAI,CAExD;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { AbbacchioClient } from "../client.js";
|
|
2
|
-
const methodToLevel = {
|
|
3
|
-
debug: 20,
|
|
4
|
-
log: 30,
|
|
5
|
-
info: 30,
|
|
6
|
-
warn: 40,
|
|
7
|
-
error: 50,
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Console interceptor for Abbacchio.
|
|
11
|
-
* Intercepts console.log/info/warn/error/debug calls and sends them to Abbacchio.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { interceptConsole, restoreConsole } from "@abbacchio/client/transports/console";
|
|
16
|
-
*
|
|
17
|
-
* // Start intercepting console calls
|
|
18
|
-
* interceptConsole({
|
|
19
|
-
* url: "http://localhost:4000/api/logs",
|
|
20
|
-
* channel: "my-app",
|
|
21
|
-
* secretKey: "optional-encryption-key",
|
|
22
|
-
* passthrough: true, // Still log to console
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* console.log("This will be sent to Abbacchio!");
|
|
26
|
-
* console.error("Errors too!");
|
|
27
|
-
*
|
|
28
|
-
* // Stop intercepting when done
|
|
29
|
-
* restoreConsole();
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
// Store original console methods
|
|
33
|
-
const originalConsole = {
|
|
34
|
-
log: console.log.bind(console),
|
|
35
|
-
info: console.info.bind(console),
|
|
36
|
-
warn: console.warn.bind(console),
|
|
37
|
-
error: console.error.bind(console),
|
|
38
|
-
debug: console.debug.bind(console),
|
|
39
|
-
};
|
|
40
|
-
let activeClient = null;
|
|
41
|
-
let activeOptions = null;
|
|
42
|
-
/**
|
|
43
|
-
* Format console arguments into a message string
|
|
44
|
-
*/
|
|
45
|
-
function formatArgs(args) {
|
|
46
|
-
return args
|
|
47
|
-
.map((arg) => {
|
|
48
|
-
if (typeof arg === "string")
|
|
49
|
-
return arg;
|
|
50
|
-
if (arg instanceof Error)
|
|
51
|
-
return `${arg.name}: ${arg.message}\n${arg.stack}`;
|
|
52
|
-
try {
|
|
53
|
-
return JSON.stringify(arg);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return String(arg);
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
.join(" ");
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create an intercepted console method
|
|
63
|
-
*/
|
|
64
|
-
function createInterceptedMethod(method, client, passthrough) {
|
|
65
|
-
return (...args) => {
|
|
66
|
-
// Send to Abbacchio
|
|
67
|
-
const log = {
|
|
68
|
-
level: methodToLevel[method],
|
|
69
|
-
msg: formatArgs(args),
|
|
70
|
-
time: Date.now(),
|
|
71
|
-
method,
|
|
72
|
-
};
|
|
73
|
-
client.add(log);
|
|
74
|
-
// Optionally pass through to original console
|
|
75
|
-
if (passthrough) {
|
|
76
|
-
originalConsole[method](...args);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Start intercepting console calls
|
|
82
|
-
*/
|
|
83
|
-
export function interceptConsole(opts = {}) {
|
|
84
|
-
// Restore any existing interception first
|
|
85
|
-
if (activeClient) {
|
|
86
|
-
restoreConsole();
|
|
87
|
-
}
|
|
88
|
-
const methods = opts.methods || ["log", "info", "warn", "error", "debug"];
|
|
89
|
-
const passthrough = opts.passthrough !== false;
|
|
90
|
-
activeClient = new AbbacchioClient(opts);
|
|
91
|
-
activeOptions = opts;
|
|
92
|
-
// Replace console methods
|
|
93
|
-
for (const method of methods) {
|
|
94
|
-
console[method] = createInterceptedMethod(method, activeClient, passthrough);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Stop intercepting console calls and restore original behavior
|
|
99
|
-
*/
|
|
100
|
-
export function restoreConsole() {
|
|
101
|
-
// Restore original console methods
|
|
102
|
-
for (const method of Object.keys(originalConsole)) {
|
|
103
|
-
console[method] = originalConsole[method];
|
|
104
|
-
}
|
|
105
|
-
// Flush and close client
|
|
106
|
-
if (activeClient) {
|
|
107
|
-
activeClient.close();
|
|
108
|
-
activeClient = null;
|
|
109
|
-
activeOptions = null;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get the active client (for testing)
|
|
114
|
-
*/
|
|
115
|
-
export function getActiveClient() {
|
|
116
|
-
return activeClient;
|
|
117
|
-
}
|
|
118
|
-
export default interceptConsole;
|
|
119
|
-
//# sourceMappingURL=console.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/transports/console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA+B,MAAM,cAAc,CAAC;AAW5E,MAAM,aAAa,GAAkC;IACnD,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;CACV,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,iCAAiC;AACjC,MAAM,eAAe,GAAwD;IAC3E,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;IAC9B,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAChC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;CACnC,CAAC;AAEF,IAAI,YAAY,GAA2B,IAAI,CAAC;AAChD,IAAI,aAAa,GAAqC,IAAI,CAAC;AAE3D;;GAEG;AACH,SAAS,UAAU,CAAC,IAAe;IACjC,OAAO,IAAI;SACR,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACX,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAC;QACxC,IAAI,GAAG,YAAY,KAAK;YAAE,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC;QAC7E,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAA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J,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,mCAAmC;IACnC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAoB,EAAE,CAAC;QACpE,OAA8C,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACpF,CAAC;IAED,yBAAyB;IACzB,IAAI,YAAY,EAAE,CAAC;QACjB,YAAY,CAAC,KAAK,EAAE,CAAC;QACrB,YAAY,GAAG,IAAI,CAAC;QACpB,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { AbbacchioClient, type AbbacchioClientOptions } from "../client.js";
|
|
2
|
-
|
|
3
|
-
export interface ConsoleInterceptorOptions extends AbbacchioClientOptions {
|
|
4
|
-
/** Which console methods to intercept. Defaults to all. */
|
|
5
|
-
methods?: ("log" | "info" | "warn" | "error" | "debug")[];
|
|
6
|
-
/** Whether to still output to original console. Defaults to true. */
|
|
7
|
-
passthrough?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
type ConsoleMethod = "log" | "info" | "warn" | "error" | "debug";
|
|
11
|
-
|
|
12
|
-
const methodToLevel: Record<ConsoleMethod, number> = {
|
|
13
|
-
debug: 20,
|
|
14
|
-
log: 30,
|
|
15
|
-
info: 30,
|
|
16
|
-
warn: 40,
|
|
17
|
-
error: 50,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Console interceptor for Abbacchio.
|
|
22
|
-
* Intercepts console.log/info/warn/error/debug calls and sends them to Abbacchio.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* import { interceptConsole, restoreConsole } from "@abbacchio/client/transports/console";
|
|
27
|
-
*
|
|
28
|
-
* // Start intercepting console calls
|
|
29
|
-
* interceptConsole({
|
|
30
|
-
* url: "http://localhost:4000/api/logs",
|
|
31
|
-
* channel: "my-app",
|
|
32
|
-
* secretKey: "optional-encryption-key",
|
|
33
|
-
* passthrough: true, // Still log to console
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* console.log("This will be sent to Abbacchio!");
|
|
37
|
-
* console.error("Errors too!");
|
|
38
|
-
*
|
|
39
|
-
* // Stop intercepting when done
|
|
40
|
-
* restoreConsole();
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
// Store original console methods
|
|
45
|
-
const originalConsole: Record<ConsoleMethod, (...args: unknown[]) => void> = {
|
|
46
|
-
log: console.log.bind(console),
|
|
47
|
-
info: console.info.bind(console),
|
|
48
|
-
warn: console.warn.bind(console),
|
|
49
|
-
error: console.error.bind(console),
|
|
50
|
-
debug: console.debug.bind(console),
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
let activeClient: AbbacchioClient | null = null;
|
|
54
|
-
let activeOptions: ConsoleInterceptorOptions | null = null;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Format console arguments into a message string
|
|
58
|
-
*/
|
|
59
|
-
function formatArgs(args: unknown[]): string {
|
|
60
|
-
return args
|
|
61
|
-
.map((arg) => {
|
|
62
|
-
if (typeof arg === "string") return arg;
|
|
63
|
-
if (arg instanceof Error) return `${arg.name}: ${arg.message}\n${arg.stack}`;
|
|
64
|
-
try {
|
|
65
|
-
return JSON.stringify(arg);
|
|
66
|
-
} catch {
|
|
67
|
-
return String(arg);
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
.join(" ");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Create an intercepted console method
|
|
75
|
-
*/
|
|
76
|
-
function createInterceptedMethod(
|
|
77
|
-
method: ConsoleMethod,
|
|
78
|
-
client: AbbacchioClient,
|
|
79
|
-
passthrough: boolean
|
|
80
|
-
): (...args: unknown[]) => void {
|
|
81
|
-
return (...args: unknown[]) => {
|
|
82
|
-
// Send to Abbacchio
|
|
83
|
-
const log = {
|
|
84
|
-
level: methodToLevel[method],
|
|
85
|
-
msg: formatArgs(args),
|
|
86
|
-
time: Date.now(),
|
|
87
|
-
method,
|
|
88
|
-
};
|
|
89
|
-
client.add(log);
|
|
90
|
-
|
|
91
|
-
// Optionally pass through to original console
|
|
92
|
-
if (passthrough) {
|
|
93
|
-
originalConsole[method](...args);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Start intercepting console calls
|
|
100
|
-
*/
|
|
101
|
-
export function interceptConsole(opts: ConsoleInterceptorOptions = {}): void {
|
|
102
|
-
// Restore any existing interception first
|
|
103
|
-
if (activeClient) {
|
|
104
|
-
restoreConsole();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const methods = opts.methods || ["log", "info", "warn", "error", "debug"];
|
|
108
|
-
const passthrough = opts.passthrough !== false;
|
|
109
|
-
|
|
110
|
-
activeClient = new AbbacchioClient(opts);
|
|
111
|
-
activeOptions = opts;
|
|
112
|
-
|
|
113
|
-
// Replace console methods
|
|
114
|
-
for (const method of methods) {
|
|
115
|
-
(console as unknown as Record<string, unknown>)[method] = createInterceptedMethod(
|
|
116
|
-
method,
|
|
117
|
-
activeClient,
|
|
118
|
-
passthrough
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Stop intercepting console calls and restore original behavior
|
|
125
|
-
*/
|
|
126
|
-
export function restoreConsole(): void {
|
|
127
|
-
// Restore original console methods
|
|
128
|
-
for (const method of Object.keys(originalConsole) as ConsoleMethod[]) {
|
|
129
|
-
(console as unknown as Record<string, unknown>)[method] = originalConsole[method];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Flush and close client
|
|
133
|
-
if (activeClient) {
|
|
134
|
-
activeClient.close();
|
|
135
|
-
activeClient = null;
|
|
136
|
-
activeOptions = null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Get the active client (for testing)
|
|
142
|
-
*/
|
|
143
|
-
export function getActiveClient(): AbbacchioClient | null {
|
|
144
|
-
return activeClient;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export default interceptConsole;
|