@abbacchio/transport 0.1.1 → 0.1.2

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,100 +1,100 @@
1
- import TransportStream from "winston-transport";
2
- import { AbbacchioClient, type AbbacchioClientOptions } from "../client.js";
3
-
4
- export interface WinstonTransportOptions extends AbbacchioClientOptions {
5
- /** Winston log level (optional) */
6
- level?: string;
7
- }
8
-
9
- /**
10
- * Winston transport for Abbacchio.
11
- * Extends winston-transport for proper integration.
12
- *
13
- * @example
14
- * ```typescript
15
- * import winston from "winston";
16
- * import { AbbacchioWinstonTransport } from "@abbacchio/client/transports/winston";
17
- *
18
- * const logger = winston.createLogger({
19
- * transports: [
20
- * new winston.transports.Console(),
21
- * new AbbacchioWinstonTransport({
22
- * url: "http://localhost:4000/api/logs",
23
- * channel: "my-app",
24
- * secretKey: "optional-encryption-key",
25
- * }),
26
- * ],
27
- * });
28
- *
29
- * logger.info("Hello from Winston!");
30
- * ```
31
- */
32
- export class AbbacchioWinstonTransport extends TransportStream {
33
- private client: AbbacchioClient;
34
-
35
- constructor(opts: WinstonTransportOptions = {}) {
36
- super({ level: opts.level });
37
- this.client = new AbbacchioClient(opts);
38
- }
39
-
40
- /**
41
- * Winston log method - called for each log entry
42
- */
43
- log(info: Record<string, unknown>, callback: () => void): void {
44
- setImmediate(() => {
45
- this.emit("logged", info);
46
- });
47
-
48
- // Transform Winston format to Abbacchio format
49
- const log = this.transformLog(info);
50
- this.client.add(log);
51
-
52
- callback();
53
- }
54
-
55
- /**
56
- * Transform Winston log format to a normalized format
57
- */
58
- private transformLog(info: Record<string, unknown>): Record<string, unknown> {
59
- const { level, message, timestamp, ...rest } = info;
60
-
61
- return {
62
- level: this.levelToNumber(level as string),
63
- msg: message,
64
- time: timestamp ? new Date(timestamp as string).getTime() : Date.now(),
65
- ...rest,
66
- };
67
- }
68
-
69
- /**
70
- * Convert Winston level string to Pino-style number
71
- */
72
- private levelToNumber(level: string): number {
73
- const levels: Record<string, number> = {
74
- error: 50,
75
- warn: 40,
76
- info: 30,
77
- http: 30,
78
- verbose: 20,
79
- debug: 20,
80
- silly: 10,
81
- };
82
- return levels[level] || 30;
83
- }
84
-
85
- /**
86
- * Close the transport
87
- */
88
- close(): void {
89
- this.client.close();
90
- }
91
- }
92
-
93
- /**
94
- * Factory function to create a Winston transport
95
- */
96
- export function winstonTransport(opts?: WinstonTransportOptions): AbbacchioWinstonTransport {
97
- return new AbbacchioWinstonTransport(opts);
98
- }
99
-
100
- export default winstonTransport;
1
+ import TransportStream from "winston-transport";
2
+ import { AbbacchioClient, type AbbacchioClientOptions } from "../client.js";
3
+
4
+ export interface WinstonTransportOptions extends AbbacchioClientOptions {
5
+ /** Winston log level (optional) */
6
+ level?: string;
7
+ }
8
+
9
+ /**
10
+ * Winston transport for Abbacchio.
11
+ * Extends winston-transport for proper integration.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import winston from "winston";
16
+ * import { AbbacchioWinstonTransport } from "@abbacchio/client/transports/winston";
17
+ *
18
+ * const logger = winston.createLogger({
19
+ * transports: [
20
+ * new winston.transports.Console(),
21
+ * new AbbacchioWinstonTransport({
22
+ * url: "http://localhost:4000/api/logs",
23
+ * channel: "my-app",
24
+ * secretKey: "optional-encryption-key",
25
+ * }),
26
+ * ],
27
+ * });
28
+ *
29
+ * logger.info("Hello from Winston!");
30
+ * ```
31
+ */
32
+ export class AbbacchioWinstonTransport extends TransportStream {
33
+ private client: AbbacchioClient;
34
+
35
+ constructor(opts: WinstonTransportOptions = {}) {
36
+ super({ level: opts.level });
37
+ this.client = new AbbacchioClient(opts);
38
+ }
39
+
40
+ /**
41
+ * Winston log method - called for each log entry
42
+ */
43
+ log(info: Record<string, unknown>, callback: () => void): void {
44
+ setImmediate(() => {
45
+ this.emit("logged", info);
46
+ });
47
+
48
+ // Transform Winston format to Abbacchio format
49
+ const log = this.transformLog(info);
50
+ this.client.add(log);
51
+
52
+ callback();
53
+ }
54
+
55
+ /**
56
+ * Transform Winston log format to a normalized format
57
+ */
58
+ private transformLog(info: Record<string, unknown>): Record<string, unknown> {
59
+ const { level, message, timestamp, ...rest } = info;
60
+
61
+ return {
62
+ level: this.levelToNumber(level as string),
63
+ msg: message,
64
+ time: timestamp ? new Date(timestamp as string).getTime() : Date.now(),
65
+ ...rest,
66
+ };
67
+ }
68
+
69
+ /**
70
+ * Convert Winston level string to Pino-style number
71
+ */
72
+ private levelToNumber(level: string): number {
73
+ const levels: Record<string, number> = {
74
+ error: 50,
75
+ warn: 40,
76
+ info: 30,
77
+ http: 30,
78
+ verbose: 20,
79
+ debug: 20,
80
+ silly: 10,
81
+ };
82
+ return levels[level] || 30;
83
+ }
84
+
85
+ /**
86
+ * Close the transport
87
+ */
88
+ close(): void {
89
+ this.client.close();
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Factory function to create a Winston transport
95
+ */
96
+ export function winstonTransport(opts?: WinstonTransportOptions): AbbacchioWinstonTransport {
97
+ return new AbbacchioWinstonTransport(opts);
98
+ }
99
+
100
+ export default winstonTransport;
package/tsconfig.json CHANGED
@@ -1,19 +1,19 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "lib": ["ES2022"],
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "declaration": true,
14
- "declarationMap": true,
15
- "sourceMap": true
16
- },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules", "dist"]
19
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }