@logtape/adaptor-winston 1.0.0-dev.257

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/dist/mod.d.cts ADDED
@@ -0,0 +1,300 @@
1
+ import { LogLevel, Sink } from "@logtape/logtape";
2
+ import { LeveledLogMethod } from "winston";
3
+
4
+ //#region mod.d.ts
5
+
6
+ /**
7
+ * Logger interface for Winston-compatible loggers.
8
+ * @since 1.0.0
9
+ */
10
+ interface Logger {
11
+ error: LeveledLogMethod;
12
+ warn: LeveledLogMethod;
13
+ info: LeveledLogMethod;
14
+ http: LeveledLogMethod;
15
+ verbose: LeveledLogMethod;
16
+ debug: LeveledLogMethod;
17
+ silly: LeveledLogMethod;
18
+ }
19
+ /**
20
+ * Configuration options for the winston sink.
21
+ *
22
+ * @example Basic usage with default options
23
+ * ```typescript
24
+ * const sink = getWinstonSink(winstonLogger);
25
+ * ```
26
+ *
27
+ * @example Custom level mapping
28
+ * ```typescript
29
+ * const sink = getWinstonSink(winstonLogger, {
30
+ * levelsMap: {
31
+ * "trace": "debug",
32
+ * "debug": "debug",
33
+ * "info": "info",
34
+ * "warning": "warn",
35
+ * "error": "error",
36
+ * "fatal": "error"
37
+ * }
38
+ * });
39
+ * ```
40
+ *
41
+ * @example Custom category formatting
42
+ * ```typescript
43
+ * const sink = getWinstonSink(winstonLogger, {
44
+ * category: {
45
+ * separator: ".",
46
+ * position: "start",
47
+ * decorator: "[]"
48
+ * }
49
+ * });
50
+ * ```
51
+ *
52
+ * @since 1.0.0
53
+ */
54
+ interface WinstonSinkOptions {
55
+ /**
56
+ * Mapping between LogTape log levels and winston log levels.
57
+ *
58
+ * By default, LogTape levels are mapped as follows:
59
+ *
60
+ * - `trace` → `silly`
61
+ * - `debug` → `debug`
62
+ * - `info` → `info`
63
+ * - `warning` → `warn`
64
+ * - `error` → `error`
65
+ * - `fatal` → `error`
66
+ */
67
+ readonly levelsMap?: Readonly<Record<LogLevel, keyof Logger>>;
68
+ /**
69
+ * Configuration for how LogTape categories are handled in winston logs.
70
+ *
71
+ * - `false` or `undefined`: Categories are not included in the log message
72
+ * - `true`: Categories are included with default formatting (":" decorator at start)
73
+ * - `CategoryOptions`: Custom category formatting configuration
74
+ *
75
+ * @default undefined
76
+ */
77
+ readonly category?: boolean | CategoryOptions;
78
+ /**
79
+ * Custom formatter for interpolated values in log messages.
80
+ *
81
+ * This function is used to convert values that are interpolated into
82
+ * log messages (e.g., the `name` in
83
+ * `logger.info("Hello, {name}!", { name: "world" })`).
84
+ *
85
+ * @param value The value to format
86
+ * @returns A string representation of the value
87
+ * @default `inspect` (from `node:util` module)
88
+ */
89
+ readonly valueFormatter?: (value: unknown) => string;
90
+ }
91
+ /**
92
+ * Configuration options for formatting LogTape categories in winston log messages.
93
+ *
94
+ * Categories in LogTape represent a hierarchical namespace for loggers
95
+ * (e.g., ["myapp", "database", "connection"]). This interface controls
96
+ * how these categories are formatted when included in winston log messages.
97
+ *
98
+ * @example Default formatting
99
+ * ```typescript
100
+ * // With category ["myapp", "db"] and default options:
101
+ * // Output: "myapp·db: User logged in"
102
+ * const options: CategoryOptions = {};
103
+ * ```
104
+ *
105
+ * @example Custom separator and decorator
106
+ * ```typescript
107
+ * // With category ["myapp", "db"] and custom options:
108
+ * // Output: "[myapp.db] User logged in"
109
+ * const options: CategoryOptions = {
110
+ * separator: ".",
111
+ * decorator: "[]"
112
+ * };
113
+ * ```
114
+ *
115
+ * @example Category at end
116
+ * ```typescript
117
+ * // With category ["myapp", "db"] and position at end:
118
+ * // Output: "User logged in: myapp·db"
119
+ * const options: CategoryOptions = {
120
+ * position: "end"
121
+ * };
122
+ * ```
123
+ *
124
+ * @since 1.0.0
125
+ */
126
+ interface CategoryOptions {
127
+ /**
128
+ * The separator used to join category parts when multiple categories exist.
129
+ * @default "·"
130
+ */
131
+ readonly separator?: string;
132
+ /**
133
+ * Where to position the category in the log message.
134
+ * - `"start"`: Category appears at the beginning of the message
135
+ * - `"end"`: Category appears at the end of the message
136
+ * @default "start"
137
+ */
138
+ readonly position?: "start" | "end";
139
+ /**
140
+ * The decorator used to format the category in the log message.
141
+ * - `"[]"`: [category] format
142
+ * - `"()"`: (category) format
143
+ * - `"<>"`: <category> format
144
+ * - `"{}"`: {category} format
145
+ * - `":"`: category: format
146
+ * - `"-"`: category - format
147
+ * - `"|"`: category | format
148
+ * - `"/"`: category / format
149
+ * - `""`: category format (no decoration)
150
+ * @default ":"
151
+ */
152
+ readonly decorator?: "[]" | "()" | "<>" | "{}" | ":" | "-" | "|" | "/" | "";
153
+ }
154
+ /**
155
+ * Creates a LogTape sink that forwards log records to a winston logger.
156
+ *
157
+ * This function creates a sink function that can be used with LogTape's
158
+ * configuration system. The sink will format LogTape log records and
159
+ * forward them to the provided winston logger instance.
160
+ *
161
+ * @example Basic usage
162
+ * ```typescript
163
+ * import winston from "winston";
164
+ * import { configure } from "@logtape/logtape";
165
+ * import { getWinstonSink } from "@logtape/adaptor-winston";
166
+ *
167
+ * const winstonLogger = winston.createLogger({
168
+ * level: "info",
169
+ * format: winston.format.combine(
170
+ * winston.format.timestamp(),
171
+ * winston.format.json()
172
+ * ),
173
+ * transports: [new winston.transports.Console()]
174
+ * });
175
+ *
176
+ * await configure({
177
+ * sinks: {
178
+ * winston: getWinstonSink(winstonLogger)
179
+ * },
180
+ * loggers: [
181
+ * { category: ["myapp"], sinks: ["winston"] }
182
+ * ]
183
+ * });
184
+ * ```
185
+ *
186
+ * @example With custom options
187
+ * ```typescript
188
+ * const sink = getWinstonSink(winstonLogger, {
189
+ * category: {
190
+ * separator: ".",
191
+ * position: "start",
192
+ * decorator: "[]"
193
+ * },
194
+ * levelsMap: {
195
+ * "trace": "debug", // Map trace to debug instead of silly
196
+ * "debug": "debug",
197
+ * "info": "info",
198
+ * "warning": "warn",
199
+ * "error": "error",
200
+ * "fatal": "error"
201
+ * }
202
+ * });
203
+ * ```
204
+ *
205
+ * @param logger The winston logger instance to forward logs to. Must implement
206
+ * the Logger interface with error, warn, info, http, verbose,
207
+ * debug, and silly methods.
208
+ * @param options Configuration options for the sink behavior.
209
+ * @returns A sink function that can be used with LogTape's configure() function.
210
+ * @since 1.0.0
211
+ */
212
+ declare function getWinstonSink(logger: Logger, options?: WinstonSinkOptions): Sink;
213
+ /**
214
+ * Automatically configures LogTape to route all logs to a winston logger.
215
+ *
216
+ * This is a convenience function that automatically sets up LogTape to forward
217
+ * all log records to a winston logger instance. By default, it uses winston's
218
+ * default logger, but you can provide a custom logger as the first parameter.
219
+ *
220
+ * @param logger The winston logger instance to use.
221
+ * @param options Configuration options for the winston sink behavior.
222
+ *
223
+ * @example Basic auto-configuration with default logger
224
+ * ```typescript
225
+ * import { install } from "@logtape/adaptor-winston";
226
+ *
227
+ * // Automatically route all LogTape logs to winston's default logger
228
+ * install();
229
+ *
230
+ * // Now any LogTape-enabled library will log through winston
231
+ * import { getLogger } from "@logtape/logtape";
232
+ * const logger = getLogger("my-app");
233
+ * logger.info("This will be logged through winston");
234
+ * ```
235
+ *
236
+ * @example Auto-configuration with custom winston logger
237
+ * ```typescript
238
+ * import winston from "winston";
239
+ * import { install } from "@logtape/adaptor-winston";
240
+ *
241
+ * const customLogger = winston.createLogger({
242
+ * level: "info",
243
+ * format: winston.format.combine(
244
+ * winston.format.timestamp(),
245
+ * winston.format.json()
246
+ * ),
247
+ * transports: [
248
+ * new winston.transports.Console(),
249
+ * new winston.transports.File({ filename: "app.log" })
250
+ * ]
251
+ * });
252
+ *
253
+ * // Install with custom logger
254
+ * install(customLogger);
255
+ * ```
256
+ *
257
+ * @example Auto-configuration with custom options
258
+ * ```typescript
259
+ * import { install } from "@logtape/adaptor-winston";
260
+ *
261
+ * install(undefined, {
262
+ * category: {
263
+ * position: "start",
264
+ * decorator: "[]",
265
+ * separator: "."
266
+ * },
267
+ * levelsMap: {
268
+ * "trace": "debug" // Map LogTape trace to winston debug
269
+ * }
270
+ * });
271
+ * ```
272
+ *
273
+ * @example Custom logger with custom options
274
+ * ```typescript
275
+ * import winston from "winston";
276
+ * import { install } from "@logtape/adaptor-winston";
277
+ *
278
+ * const customLogger = winston.createLogger({
279
+ * transports: [new winston.transports.Console()]
280
+ * });
281
+ *
282
+ * install(customLogger, {
283
+ * category: { position: "start", decorator: "[]" }
284
+ * });
285
+ * ```
286
+ *
287
+ * @since 1.0.0
288
+ */
289
+ declare function install(logger: Logger, options?: WinstonSinkOptions): void;
290
+ /**
291
+ * Configures LogTape to route all logs to winston's default logger.
292
+ *
293
+ * @param options Optional configuration for the winston sink behavior.
294
+ * @since 1.0.0
295
+ */
296
+ declare function install(options?: WinstonSinkOptions): void;
297
+ //# sourceMappingURL=mod.d.ts.map
298
+ //#endregion
299
+ export { CategoryOptions, Logger, WinstonSinkOptions, getWinstonSink, install };
300
+ //# sourceMappingURL=mod.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.cts","names":[],"sources":["../mod.ts"],"sourcesContent":[],"mappings":";;;;;AAoaA;;;;UAvXiB,MAAA;SACR;QACD;QACA;QACA;WACG;SACF;SACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAsCQ,kBAAA;;;;;;;;;;;;;uBAaM,SAAS,OAAO,gBAAgB;;;;;;;;;;gCAWvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAmDf,eAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkGD,cAAA,SACN,kBACC,qBACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+Ia,OAAA,SACN,kBACE;;;;;;;iBASI,OAAA,WACJ"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,300 @@
1
+ import { LogLevel, Sink } from "@logtape/logtape";
2
+ import { LeveledLogMethod } from "winston";
3
+
4
+ //#region mod.d.ts
5
+
6
+ /**
7
+ * Logger interface for Winston-compatible loggers.
8
+ * @since 1.0.0
9
+ */
10
+ interface Logger {
11
+ error: LeveledLogMethod;
12
+ warn: LeveledLogMethod;
13
+ info: LeveledLogMethod;
14
+ http: LeveledLogMethod;
15
+ verbose: LeveledLogMethod;
16
+ debug: LeveledLogMethod;
17
+ silly: LeveledLogMethod;
18
+ }
19
+ /**
20
+ * Configuration options for the winston sink.
21
+ *
22
+ * @example Basic usage with default options
23
+ * ```typescript
24
+ * const sink = getWinstonSink(winstonLogger);
25
+ * ```
26
+ *
27
+ * @example Custom level mapping
28
+ * ```typescript
29
+ * const sink = getWinstonSink(winstonLogger, {
30
+ * levelsMap: {
31
+ * "trace": "debug",
32
+ * "debug": "debug",
33
+ * "info": "info",
34
+ * "warning": "warn",
35
+ * "error": "error",
36
+ * "fatal": "error"
37
+ * }
38
+ * });
39
+ * ```
40
+ *
41
+ * @example Custom category formatting
42
+ * ```typescript
43
+ * const sink = getWinstonSink(winstonLogger, {
44
+ * category: {
45
+ * separator: ".",
46
+ * position: "start",
47
+ * decorator: "[]"
48
+ * }
49
+ * });
50
+ * ```
51
+ *
52
+ * @since 1.0.0
53
+ */
54
+ interface WinstonSinkOptions {
55
+ /**
56
+ * Mapping between LogTape log levels and winston log levels.
57
+ *
58
+ * By default, LogTape levels are mapped as follows:
59
+ *
60
+ * - `trace` → `silly`
61
+ * - `debug` → `debug`
62
+ * - `info` → `info`
63
+ * - `warning` → `warn`
64
+ * - `error` → `error`
65
+ * - `fatal` → `error`
66
+ */
67
+ readonly levelsMap?: Readonly<Record<LogLevel, keyof Logger>>;
68
+ /**
69
+ * Configuration for how LogTape categories are handled in winston logs.
70
+ *
71
+ * - `false` or `undefined`: Categories are not included in the log message
72
+ * - `true`: Categories are included with default formatting (":" decorator at start)
73
+ * - `CategoryOptions`: Custom category formatting configuration
74
+ *
75
+ * @default undefined
76
+ */
77
+ readonly category?: boolean | CategoryOptions;
78
+ /**
79
+ * Custom formatter for interpolated values in log messages.
80
+ *
81
+ * This function is used to convert values that are interpolated into
82
+ * log messages (e.g., the `name` in
83
+ * `logger.info("Hello, {name}!", { name: "world" })`).
84
+ *
85
+ * @param value The value to format
86
+ * @returns A string representation of the value
87
+ * @default `inspect` (from `node:util` module)
88
+ */
89
+ readonly valueFormatter?: (value: unknown) => string;
90
+ }
91
+ /**
92
+ * Configuration options for formatting LogTape categories in winston log messages.
93
+ *
94
+ * Categories in LogTape represent a hierarchical namespace for loggers
95
+ * (e.g., ["myapp", "database", "connection"]). This interface controls
96
+ * how these categories are formatted when included in winston log messages.
97
+ *
98
+ * @example Default formatting
99
+ * ```typescript
100
+ * // With category ["myapp", "db"] and default options:
101
+ * // Output: "myapp·db: User logged in"
102
+ * const options: CategoryOptions = {};
103
+ * ```
104
+ *
105
+ * @example Custom separator and decorator
106
+ * ```typescript
107
+ * // With category ["myapp", "db"] and custom options:
108
+ * // Output: "[myapp.db] User logged in"
109
+ * const options: CategoryOptions = {
110
+ * separator: ".",
111
+ * decorator: "[]"
112
+ * };
113
+ * ```
114
+ *
115
+ * @example Category at end
116
+ * ```typescript
117
+ * // With category ["myapp", "db"] and position at end:
118
+ * // Output: "User logged in: myapp·db"
119
+ * const options: CategoryOptions = {
120
+ * position: "end"
121
+ * };
122
+ * ```
123
+ *
124
+ * @since 1.0.0
125
+ */
126
+ interface CategoryOptions {
127
+ /**
128
+ * The separator used to join category parts when multiple categories exist.
129
+ * @default "·"
130
+ */
131
+ readonly separator?: string;
132
+ /**
133
+ * Where to position the category in the log message.
134
+ * - `"start"`: Category appears at the beginning of the message
135
+ * - `"end"`: Category appears at the end of the message
136
+ * @default "start"
137
+ */
138
+ readonly position?: "start" | "end";
139
+ /**
140
+ * The decorator used to format the category in the log message.
141
+ * - `"[]"`: [category] format
142
+ * - `"()"`: (category) format
143
+ * - `"<>"`: <category> format
144
+ * - `"{}"`: {category} format
145
+ * - `":"`: category: format
146
+ * - `"-"`: category - format
147
+ * - `"|"`: category | format
148
+ * - `"/"`: category / format
149
+ * - `""`: category format (no decoration)
150
+ * @default ":"
151
+ */
152
+ readonly decorator?: "[]" | "()" | "<>" | "{}" | ":" | "-" | "|" | "/" | "";
153
+ }
154
+ /**
155
+ * Creates a LogTape sink that forwards log records to a winston logger.
156
+ *
157
+ * This function creates a sink function that can be used with LogTape's
158
+ * configuration system. The sink will format LogTape log records and
159
+ * forward them to the provided winston logger instance.
160
+ *
161
+ * @example Basic usage
162
+ * ```typescript
163
+ * import winston from "winston";
164
+ * import { configure } from "@logtape/logtape";
165
+ * import { getWinstonSink } from "@logtape/adaptor-winston";
166
+ *
167
+ * const winstonLogger = winston.createLogger({
168
+ * level: "info",
169
+ * format: winston.format.combine(
170
+ * winston.format.timestamp(),
171
+ * winston.format.json()
172
+ * ),
173
+ * transports: [new winston.transports.Console()]
174
+ * });
175
+ *
176
+ * await configure({
177
+ * sinks: {
178
+ * winston: getWinstonSink(winstonLogger)
179
+ * },
180
+ * loggers: [
181
+ * { category: ["myapp"], sinks: ["winston"] }
182
+ * ]
183
+ * });
184
+ * ```
185
+ *
186
+ * @example With custom options
187
+ * ```typescript
188
+ * const sink = getWinstonSink(winstonLogger, {
189
+ * category: {
190
+ * separator: ".",
191
+ * position: "start",
192
+ * decorator: "[]"
193
+ * },
194
+ * levelsMap: {
195
+ * "trace": "debug", // Map trace to debug instead of silly
196
+ * "debug": "debug",
197
+ * "info": "info",
198
+ * "warning": "warn",
199
+ * "error": "error",
200
+ * "fatal": "error"
201
+ * }
202
+ * });
203
+ * ```
204
+ *
205
+ * @param logger The winston logger instance to forward logs to. Must implement
206
+ * the Logger interface with error, warn, info, http, verbose,
207
+ * debug, and silly methods.
208
+ * @param options Configuration options for the sink behavior.
209
+ * @returns A sink function that can be used with LogTape's configure() function.
210
+ * @since 1.0.0
211
+ */
212
+ declare function getWinstonSink(logger: Logger, options?: WinstonSinkOptions): Sink;
213
+ /**
214
+ * Automatically configures LogTape to route all logs to a winston logger.
215
+ *
216
+ * This is a convenience function that automatically sets up LogTape to forward
217
+ * all log records to a winston logger instance. By default, it uses winston's
218
+ * default logger, but you can provide a custom logger as the first parameter.
219
+ *
220
+ * @param logger The winston logger instance to use.
221
+ * @param options Configuration options for the winston sink behavior.
222
+ *
223
+ * @example Basic auto-configuration with default logger
224
+ * ```typescript
225
+ * import { install } from "@logtape/adaptor-winston";
226
+ *
227
+ * // Automatically route all LogTape logs to winston's default logger
228
+ * install();
229
+ *
230
+ * // Now any LogTape-enabled library will log through winston
231
+ * import { getLogger } from "@logtape/logtape";
232
+ * const logger = getLogger("my-app");
233
+ * logger.info("This will be logged through winston");
234
+ * ```
235
+ *
236
+ * @example Auto-configuration with custom winston logger
237
+ * ```typescript
238
+ * import winston from "winston";
239
+ * import { install } from "@logtape/adaptor-winston";
240
+ *
241
+ * const customLogger = winston.createLogger({
242
+ * level: "info",
243
+ * format: winston.format.combine(
244
+ * winston.format.timestamp(),
245
+ * winston.format.json()
246
+ * ),
247
+ * transports: [
248
+ * new winston.transports.Console(),
249
+ * new winston.transports.File({ filename: "app.log" })
250
+ * ]
251
+ * });
252
+ *
253
+ * // Install with custom logger
254
+ * install(customLogger);
255
+ * ```
256
+ *
257
+ * @example Auto-configuration with custom options
258
+ * ```typescript
259
+ * import { install } from "@logtape/adaptor-winston";
260
+ *
261
+ * install(undefined, {
262
+ * category: {
263
+ * position: "start",
264
+ * decorator: "[]",
265
+ * separator: "."
266
+ * },
267
+ * levelsMap: {
268
+ * "trace": "debug" // Map LogTape trace to winston debug
269
+ * }
270
+ * });
271
+ * ```
272
+ *
273
+ * @example Custom logger with custom options
274
+ * ```typescript
275
+ * import winston from "winston";
276
+ * import { install } from "@logtape/adaptor-winston";
277
+ *
278
+ * const customLogger = winston.createLogger({
279
+ * transports: [new winston.transports.Console()]
280
+ * });
281
+ *
282
+ * install(customLogger, {
283
+ * category: { position: "start", decorator: "[]" }
284
+ * });
285
+ * ```
286
+ *
287
+ * @since 1.0.0
288
+ */
289
+ declare function install(logger: Logger, options?: WinstonSinkOptions): void;
290
+ /**
291
+ * Configures LogTape to route all logs to winston's default logger.
292
+ *
293
+ * @param options Optional configuration for the winston sink behavior.
294
+ * @since 1.0.0
295
+ */
296
+ declare function install(options?: WinstonSinkOptions): void;
297
+ //# sourceMappingURL=mod.d.ts.map
298
+ //#endregion
299
+ export { CategoryOptions, Logger, WinstonSinkOptions, getWinstonSink, install };
300
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","names":[],"sources":["../mod.ts"],"sourcesContent":[],"mappings":";;;;;AAoaA;;;;UAvXiB,MAAA;SACR;QACD;QACA;QACA;WACG;SACF;SACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAsCQ,kBAAA;;;;;;;;;;;;;uBAaM,SAAS,OAAO,gBAAgB;;;;;;;;;;gCAWvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAmDf,eAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkGD,cAAA,SACN,kBACC,qBACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+Ia,OAAA,SACN,kBACE;;;;;;;iBASI,OAAA,WACJ"}