@logtape/adaptor-winston 1.4.0-dev.408 → 1.4.0-dev.413
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/package.json +5 -2
- package/deno.json +0 -40
- package/src/install.ts +0 -87
- package/src/mod.test.ts +0 -415
- package/src/mod.ts +0 -458
- package/tsdown.config.ts +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logtape/adaptor-winston",
|
|
3
|
-
"version": "1.4.0-dev.
|
|
3
|
+
"version": "1.4.0-dev.413+1097da33",
|
|
4
4
|
"description": "winston adapter for LogTape logging library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logging",
|
|
@@ -55,9 +55,12 @@
|
|
|
55
55
|
"sideEffects": [
|
|
56
56
|
"./dist/install.*"
|
|
57
57
|
],
|
|
58
|
+
"files": [
|
|
59
|
+
"dist/"
|
|
60
|
+
],
|
|
58
61
|
"peerDependencies": {
|
|
59
62
|
"winston": "^3.17.0",
|
|
60
|
-
"@logtape/logtape": "^1.4.0-dev.
|
|
63
|
+
"@logtape/logtape": "^1.4.0-dev.413+1097da33"
|
|
61
64
|
},
|
|
62
65
|
"devDependencies": {
|
|
63
66
|
"@alinea/suite": "^0.6.3",
|
package/deno.json
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@logtape/adaptor-winston",
|
|
3
|
-
"version": "1.4.0-dev.408+3fd750bb",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": "./src/mod.ts",
|
|
7
|
-
"./install": "./src/install.ts"
|
|
8
|
-
},
|
|
9
|
-
"imports": {
|
|
10
|
-
"winston": "npm:winston@^3.17.0"
|
|
11
|
-
},
|
|
12
|
-
"exclude": [
|
|
13
|
-
"coverage/",
|
|
14
|
-
"npm/",
|
|
15
|
-
".dnt-import-map.json"
|
|
16
|
-
],
|
|
17
|
-
"tasks": {
|
|
18
|
-
"build": "pnpm build",
|
|
19
|
-
"test": "deno test --allow-env",
|
|
20
|
-
"test:node": {
|
|
21
|
-
"dependencies": [
|
|
22
|
-
"build"
|
|
23
|
-
],
|
|
24
|
-
"command": "node --experimental-transform-types --test"
|
|
25
|
-
},
|
|
26
|
-
"test:bun": {
|
|
27
|
-
"dependencies": [
|
|
28
|
-
"build"
|
|
29
|
-
],
|
|
30
|
-
"command": "bun test"
|
|
31
|
-
},
|
|
32
|
-
"test-all": {
|
|
33
|
-
"dependencies": [
|
|
34
|
-
"test",
|
|
35
|
-
"test:node",
|
|
36
|
-
"test:bun"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/install.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-installation module for @logtape/adaptor-winston.
|
|
3
|
-
*
|
|
4
|
-
* This module automatically configures LogTape to route all log records
|
|
5
|
-
* to winston's default logger when imported. This provides the simplest
|
|
6
|
-
* possible integration - just import this module and all LogTape-enabled
|
|
7
|
-
* libraries will immediately start logging through winston.
|
|
8
|
-
*
|
|
9
|
-
* @example Automatic installation via import
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // Simply import this module to automatically set up winston adapter
|
|
12
|
-
* import "@logtape/adaptor-winston/install";
|
|
13
|
-
*
|
|
14
|
-
* // Now all LogTape logs will be routed to winston's default logger
|
|
15
|
-
* import { getLogger } from "@logtape/logtape";
|
|
16
|
-
* const logger = getLogger("my-app");
|
|
17
|
-
* logger.info("This will be logged through winston");
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @example Usage in package.json scripts
|
|
21
|
-
* ```json
|
|
22
|
-
* {
|
|
23
|
-
* "scripts": {
|
|
24
|
-
* "start": "node -r @logtape/adaptor-winston/install app.js"
|
|
25
|
-
* }
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example Usage with module bundlers
|
|
30
|
-
* ```typescript
|
|
31
|
-
* // webpack.config.js or similar
|
|
32
|
-
* module.exports = {
|
|
33
|
-
* entry: [
|
|
34
|
-
* '@logtape/adaptor-winston/install',
|
|
35
|
-
* './src/index.js'
|
|
36
|
-
* ]
|
|
37
|
-
* };
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* > [!NOTE]
|
|
41
|
-
* > This module uses winston's default logger with default configuration.
|
|
42
|
-
* > If you need a custom winston logger or configuration options (category
|
|
43
|
-
* > formatting, level mapping, etc.), use the `install()` function from the
|
|
44
|
-
* > main module instead:
|
|
45
|
-
*
|
|
46
|
-
* @example Custom winston logger
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import winston from "winston";
|
|
49
|
-
* import { install } from "@logtape/adaptor-winston";
|
|
50
|
-
*
|
|
51
|
-
* const customLogger = winston.createLogger({
|
|
52
|
-
* transports: [new winston.transports.File({ filename: "app.log" })]
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* install(customLogger);
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example Custom configuration options
|
|
59
|
-
* ```typescript
|
|
60
|
-
* import { install } from "@logtape/adaptor-winston";
|
|
61
|
-
*
|
|
62
|
-
* install({
|
|
63
|
-
* category: { position: "start", decorator: "[]" }
|
|
64
|
-
* });
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* @example Custom logger with custom options
|
|
68
|
-
* ```typescript
|
|
69
|
-
* import winston from "winston";
|
|
70
|
-
* import { install } from "@logtape/adaptor-winston";
|
|
71
|
-
*
|
|
72
|
-
* const customLogger = winston.createLogger({
|
|
73
|
-
* transports: [new winston.transports.Console()]
|
|
74
|
-
* });
|
|
75
|
-
*
|
|
76
|
-
* install(customLogger, {
|
|
77
|
-
* category: { position: "start", decorator: "[]" }
|
|
78
|
-
* });
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @module
|
|
82
|
-
* @since 1.0.0
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
import { install } from "./mod.ts";
|
|
86
|
-
|
|
87
|
-
install();
|
package/src/mod.test.ts
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import { suite } from "@alinea/suite";
|
|
2
|
-
import { assertEquals } from "@std/assert/equals";
|
|
3
|
-
import winston from "winston";
|
|
4
|
-
import WinstonTransport from "winston-transport";
|
|
5
|
-
import { getWinstonSink, type Logger } from "./mod.ts";
|
|
6
|
-
|
|
7
|
-
const test = suite(import.meta);
|
|
8
|
-
|
|
9
|
-
interface LogEvent extends Record<string, unknown> {
|
|
10
|
-
level: keyof Logger;
|
|
11
|
-
message: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class BufferTransport extends WinstonTransport {
|
|
15
|
-
readonly logs: LogEvent[];
|
|
16
|
-
|
|
17
|
-
// deno-lint-ignore no-explicit-any
|
|
18
|
-
constructor(ops?: any) {
|
|
19
|
-
super(ops);
|
|
20
|
-
this.logs = [];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
override log(info: LogEvent, callback: () => void) {
|
|
24
|
-
this.logs.push(info);
|
|
25
|
-
if (callback) callback();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
test("getWinstonSink(): basic scenario", () => {
|
|
30
|
-
const buffer = new BufferTransport({});
|
|
31
|
-
const logger = winston.createLogger({
|
|
32
|
-
level: "silly",
|
|
33
|
-
transports: [buffer],
|
|
34
|
-
});
|
|
35
|
-
const sink = getWinstonSink(logger);
|
|
36
|
-
sink({
|
|
37
|
-
category: ["test", "category"],
|
|
38
|
-
level: "info",
|
|
39
|
-
message: ["Test log: ", { foo: 123 }, ""],
|
|
40
|
-
properties: { value: { foo: 123 } },
|
|
41
|
-
rawMessage: "Test log: {value}",
|
|
42
|
-
timestamp: Date.now(),
|
|
43
|
-
});
|
|
44
|
-
assertEquals(buffer.logs.length, 1);
|
|
45
|
-
const log = buffer.logs[0];
|
|
46
|
-
assertEquals(log.level, "info");
|
|
47
|
-
assertEquals(log.message, "Test log: { foo: 123 }");
|
|
48
|
-
assertEquals(log.value, { foo: 123 });
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("getWinstonSink(): default level mapping", () => {
|
|
52
|
-
const buffer = new BufferTransport({});
|
|
53
|
-
const logger = winston.createLogger({
|
|
54
|
-
level: "silly",
|
|
55
|
-
transports: [buffer],
|
|
56
|
-
});
|
|
57
|
-
const sink = getWinstonSink(logger);
|
|
58
|
-
|
|
59
|
-
const testCases = [
|
|
60
|
-
{ logTapeLevel: "trace", expectedWinstonLevel: "silly" },
|
|
61
|
-
{ logTapeLevel: "debug", expectedWinstonLevel: "debug" },
|
|
62
|
-
{ logTapeLevel: "info", expectedWinstonLevel: "info" },
|
|
63
|
-
{ logTapeLevel: "warning", expectedWinstonLevel: "warn" },
|
|
64
|
-
{ logTapeLevel: "error", expectedWinstonLevel: "error" },
|
|
65
|
-
{ logTapeLevel: "fatal", expectedWinstonLevel: "error" },
|
|
66
|
-
] as const;
|
|
67
|
-
|
|
68
|
-
for (const { logTapeLevel, expectedWinstonLevel } of testCases) {
|
|
69
|
-
buffer.logs.length = 0; // Clear buffer
|
|
70
|
-
sink({
|
|
71
|
-
category: [],
|
|
72
|
-
level: logTapeLevel,
|
|
73
|
-
message: [`${logTapeLevel} message`],
|
|
74
|
-
properties: {},
|
|
75
|
-
rawMessage: `${logTapeLevel} message`,
|
|
76
|
-
timestamp: Date.now(),
|
|
77
|
-
});
|
|
78
|
-
assertEquals(buffer.logs.length, 1);
|
|
79
|
-
assertEquals(buffer.logs[0].level, expectedWinstonLevel);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("getWinstonSink(): custom level mapping", () => {
|
|
84
|
-
const buffer = new BufferTransport({});
|
|
85
|
-
const logger = winston.createLogger({
|
|
86
|
-
level: "silly",
|
|
87
|
-
transports: [buffer],
|
|
88
|
-
});
|
|
89
|
-
const sink = getWinstonSink(logger, {
|
|
90
|
-
levelsMap: {
|
|
91
|
-
"trace": "debug",
|
|
92
|
-
"debug": "debug",
|
|
93
|
-
"info": "info",
|
|
94
|
-
"warning": "warn",
|
|
95
|
-
"error": "error",
|
|
96
|
-
"fatal": "error",
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
sink({
|
|
101
|
-
category: [],
|
|
102
|
-
level: "trace",
|
|
103
|
-
message: ["trace message"],
|
|
104
|
-
properties: {},
|
|
105
|
-
rawMessage: "trace message",
|
|
106
|
-
timestamp: Date.now(),
|
|
107
|
-
});
|
|
108
|
-
assertEquals(buffer.logs.length, 1);
|
|
109
|
-
assertEquals(buffer.logs[0].level, "debug");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("getWinstonSink(): category disabled", () => {
|
|
113
|
-
const buffer = new BufferTransport({});
|
|
114
|
-
const logger = winston.createLogger({
|
|
115
|
-
transports: [buffer],
|
|
116
|
-
});
|
|
117
|
-
const sink = getWinstonSink(logger, {
|
|
118
|
-
category: false,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
sink({
|
|
122
|
-
category: ["app", "database"],
|
|
123
|
-
level: "info",
|
|
124
|
-
message: ["Database connected"],
|
|
125
|
-
properties: {},
|
|
126
|
-
rawMessage: "Database connected",
|
|
127
|
-
timestamp: Date.now(),
|
|
128
|
-
});
|
|
129
|
-
assertEquals(buffer.logs.length, 1);
|
|
130
|
-
assertEquals(buffer.logs[0].message, "Database connected");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("getWinstonSink(): category with default formatting", () => {
|
|
134
|
-
const buffer = new BufferTransport({});
|
|
135
|
-
const logger = winston.createLogger({
|
|
136
|
-
transports: [buffer],
|
|
137
|
-
});
|
|
138
|
-
const sink = getWinstonSink(logger, {
|
|
139
|
-
category: true,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
sink({
|
|
143
|
-
category: ["app", "database"],
|
|
144
|
-
level: "info",
|
|
145
|
-
message: ["Database connected"],
|
|
146
|
-
properties: {},
|
|
147
|
-
rawMessage: "Database connected",
|
|
148
|
-
timestamp: Date.now(),
|
|
149
|
-
});
|
|
150
|
-
assertEquals(buffer.logs.length, 1);
|
|
151
|
-
assertEquals(buffer.logs[0].message, "app·database: Database connected");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("getWinstonSink(): category with custom separator", () => {
|
|
155
|
-
const buffer = new BufferTransport({});
|
|
156
|
-
const logger = winston.createLogger({
|
|
157
|
-
transports: [buffer],
|
|
158
|
-
});
|
|
159
|
-
const sink = getWinstonSink(logger, {
|
|
160
|
-
category: {
|
|
161
|
-
separator: ".",
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
sink({
|
|
166
|
-
category: ["app", "database", "connection"],
|
|
167
|
-
level: "info",
|
|
168
|
-
message: ["Database connected"],
|
|
169
|
-
properties: {},
|
|
170
|
-
rawMessage: "Database connected",
|
|
171
|
-
timestamp: Date.now(),
|
|
172
|
-
});
|
|
173
|
-
assertEquals(buffer.logs.length, 1);
|
|
174
|
-
assertEquals(
|
|
175
|
-
buffer.logs[0].message,
|
|
176
|
-
"app.database.connection: Database connected",
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("getWinstonSink(): category with different decorators", () => {
|
|
181
|
-
const buffer = new BufferTransport({});
|
|
182
|
-
const logger = winston.createLogger({
|
|
183
|
-
transports: [buffer],
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
const decorators = [
|
|
187
|
-
{ decorator: "[]", expected: "[app·db] Message" },
|
|
188
|
-
{ decorator: "()", expected: "(app·db) Message" },
|
|
189
|
-
{ decorator: "<>", expected: "<app·db> Message" },
|
|
190
|
-
{ decorator: "{}", expected: "{app·db} Message" },
|
|
191
|
-
{ decorator: ":", expected: "app·db: Message" },
|
|
192
|
-
{ decorator: "-", expected: "app·db - Message" },
|
|
193
|
-
{ decorator: "|", expected: "app·db | Message" },
|
|
194
|
-
{ decorator: "/", expected: "app·db / Message" },
|
|
195
|
-
{ decorator: "", expected: "app·db Message" },
|
|
196
|
-
] as const;
|
|
197
|
-
|
|
198
|
-
for (const { decorator, expected } of decorators) {
|
|
199
|
-
buffer.logs.length = 0; // Clear buffer
|
|
200
|
-
const sink = getWinstonSink(logger, {
|
|
201
|
-
category: { decorator },
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
sink({
|
|
205
|
-
category: ["app", "db"],
|
|
206
|
-
level: "info",
|
|
207
|
-
message: ["Message"],
|
|
208
|
-
properties: {},
|
|
209
|
-
rawMessage: "Message",
|
|
210
|
-
timestamp: Date.now(),
|
|
211
|
-
});
|
|
212
|
-
assertEquals(buffer.logs.length, 1);
|
|
213
|
-
assertEquals(buffer.logs[0].message, expected);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test("getWinstonSink(): category at end position", () => {
|
|
218
|
-
const buffer = new BufferTransport({});
|
|
219
|
-
const logger = winston.createLogger({
|
|
220
|
-
transports: [buffer],
|
|
221
|
-
});
|
|
222
|
-
const sink = getWinstonSink(logger, {
|
|
223
|
-
category: {
|
|
224
|
-
position: "end",
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
sink({
|
|
229
|
-
category: ["app", "db"],
|
|
230
|
-
level: "info",
|
|
231
|
-
message: ["Database connected"],
|
|
232
|
-
properties: {},
|
|
233
|
-
rawMessage: "Database connected",
|
|
234
|
-
timestamp: Date.now(),
|
|
235
|
-
});
|
|
236
|
-
assertEquals(buffer.logs.length, 1);
|
|
237
|
-
assertEquals(buffer.logs[0].message, "Database connected: app·db");
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
test("getWinstonSink(): category at end with different decorators", () => {
|
|
241
|
-
const buffer = new BufferTransport({});
|
|
242
|
-
const logger = winston.createLogger({
|
|
243
|
-
transports: [buffer],
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
const decorators = [
|
|
247
|
-
{ decorator: "[]", expected: "Message [app·db]" },
|
|
248
|
-
{ decorator: "()", expected: "Message (app·db)" },
|
|
249
|
-
{ decorator: "<>", expected: "Message <app·db>" },
|
|
250
|
-
{ decorator: "{}", expected: "Message {app·db}" },
|
|
251
|
-
{ decorator: ":", expected: "Message: app·db" },
|
|
252
|
-
{ decorator: "-", expected: "Message - app·db" },
|
|
253
|
-
{ decorator: "|", expected: "Message | app·db" },
|
|
254
|
-
{ decorator: "/", expected: "Message / app·db" },
|
|
255
|
-
{ decorator: "", expected: "Message app·db" },
|
|
256
|
-
] as const;
|
|
257
|
-
|
|
258
|
-
for (const { decorator, expected } of decorators) {
|
|
259
|
-
buffer.logs.length = 0; // Clear buffer
|
|
260
|
-
const sink = getWinstonSink(logger, {
|
|
261
|
-
category: {
|
|
262
|
-
position: "end",
|
|
263
|
-
decorator,
|
|
264
|
-
},
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
sink({
|
|
268
|
-
category: ["app", "db"],
|
|
269
|
-
level: "info",
|
|
270
|
-
message: ["Message"],
|
|
271
|
-
properties: {},
|
|
272
|
-
rawMessage: "Message",
|
|
273
|
-
timestamp: Date.now(),
|
|
274
|
-
});
|
|
275
|
-
assertEquals(buffer.logs.length, 1);
|
|
276
|
-
assertEquals(buffer.logs[0].message, expected);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test("getWinstonSink(): empty category", () => {
|
|
281
|
-
const buffer = new BufferTransport({});
|
|
282
|
-
const logger = winston.createLogger({
|
|
283
|
-
transports: [buffer],
|
|
284
|
-
});
|
|
285
|
-
const sink = getWinstonSink(logger, {
|
|
286
|
-
category: true,
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
sink({
|
|
290
|
-
category: [],
|
|
291
|
-
level: "info",
|
|
292
|
-
message: ["Message without category"],
|
|
293
|
-
properties: {},
|
|
294
|
-
rawMessage: "Message without category",
|
|
295
|
-
timestamp: Date.now(),
|
|
296
|
-
});
|
|
297
|
-
assertEquals(buffer.logs.length, 1);
|
|
298
|
-
assertEquals(buffer.logs[0].message, "Message without category");
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
test("getWinstonSink(): custom value formatter", () => {
|
|
302
|
-
const buffer = new BufferTransport({});
|
|
303
|
-
const logger = winston.createLogger({
|
|
304
|
-
transports: [buffer],
|
|
305
|
-
});
|
|
306
|
-
const sink = getWinstonSink(logger, {
|
|
307
|
-
valueFormatter: (value) => `CUSTOM:${JSON.stringify(value)}`,
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
sink({
|
|
311
|
-
category: [],
|
|
312
|
-
level: "info",
|
|
313
|
-
message: ["User: ", { name: "John", age: 30 }, ""],
|
|
314
|
-
properties: { user: { name: "John", age: 30 } },
|
|
315
|
-
rawMessage: "User: {user}",
|
|
316
|
-
timestamp: Date.now(),
|
|
317
|
-
});
|
|
318
|
-
assertEquals(buffer.logs.length, 1);
|
|
319
|
-
assertEquals(buffer.logs[0].message, 'User: CUSTOM:{"name":"John","age":30}');
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
test("getWinstonSink(): message interpolation", () => {
|
|
323
|
-
const buffer = new BufferTransport({});
|
|
324
|
-
const logger = winston.createLogger({
|
|
325
|
-
transports: [buffer],
|
|
326
|
-
});
|
|
327
|
-
const sink = getWinstonSink(logger);
|
|
328
|
-
|
|
329
|
-
sink({
|
|
330
|
-
category: [],
|
|
331
|
-
level: "info",
|
|
332
|
-
message: ["Hello ", "world", ", count: ", 42, "!"],
|
|
333
|
-
properties: { name: "world", count: 42 },
|
|
334
|
-
rawMessage: "Hello {name}, count: {count}!",
|
|
335
|
-
timestamp: Date.now(),
|
|
336
|
-
});
|
|
337
|
-
assertEquals(buffer.logs.length, 1);
|
|
338
|
-
assertEquals(buffer.logs[0].message, "Hello 'world', count: 42!");
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
test("getWinstonSink(): properties are passed to winston", () => {
|
|
342
|
-
const buffer = new BufferTransport({});
|
|
343
|
-
const logger = winston.createLogger({
|
|
344
|
-
transports: [buffer],
|
|
345
|
-
});
|
|
346
|
-
const sink = getWinstonSink(logger);
|
|
347
|
-
|
|
348
|
-
const properties = {
|
|
349
|
-
userId: 123,
|
|
350
|
-
requestId: "abc-def-ghi",
|
|
351
|
-
metadata: { version: "1.0.0" },
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
sink({
|
|
355
|
-
category: [],
|
|
356
|
-
level: "info",
|
|
357
|
-
message: ["User action performed"],
|
|
358
|
-
properties,
|
|
359
|
-
rawMessage: "User action performed",
|
|
360
|
-
timestamp: Date.now(),
|
|
361
|
-
});
|
|
362
|
-
assertEquals(buffer.logs.length, 1);
|
|
363
|
-
assertEquals(buffer.logs[0].userId, 123);
|
|
364
|
-
assertEquals(buffer.logs[0].requestId, "abc-def-ghi");
|
|
365
|
-
assertEquals(buffer.logs[0].metadata, { version: "1.0.0" });
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
test("getWinstonSink(): single category", () => {
|
|
369
|
-
const buffer = new BufferTransport({});
|
|
370
|
-
const logger = winston.createLogger({
|
|
371
|
-
transports: [buffer],
|
|
372
|
-
});
|
|
373
|
-
const sink = getWinstonSink(logger, {
|
|
374
|
-
category: true,
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
sink({
|
|
378
|
-
category: ["app"],
|
|
379
|
-
level: "info",
|
|
380
|
-
message: ["Single category message"],
|
|
381
|
-
properties: {},
|
|
382
|
-
rawMessage: "Single category message",
|
|
383
|
-
timestamp: Date.now(),
|
|
384
|
-
});
|
|
385
|
-
assertEquals(buffer.logs.length, 1);
|
|
386
|
-
assertEquals(buffer.logs[0].message, "app: Single category message");
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
test("getWinstonSink(): complex category with custom options", () => {
|
|
390
|
-
const buffer = new BufferTransport({});
|
|
391
|
-
const logger = winston.createLogger({
|
|
392
|
-
transports: [buffer],
|
|
393
|
-
});
|
|
394
|
-
const sink = getWinstonSink(logger, {
|
|
395
|
-
category: {
|
|
396
|
-
separator: "/",
|
|
397
|
-
position: "end",
|
|
398
|
-
decorator: "[]",
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
sink({
|
|
403
|
-
category: ["myapp", "api", "auth", "login"],
|
|
404
|
-
level: "info",
|
|
405
|
-
message: ["User logged in successfully"],
|
|
406
|
-
properties: {},
|
|
407
|
-
rawMessage: "User logged in successfully",
|
|
408
|
-
timestamp: Date.now(),
|
|
409
|
-
});
|
|
410
|
-
assertEquals(buffer.logs.length, 1);
|
|
411
|
-
assertEquals(
|
|
412
|
-
buffer.logs[0].message,
|
|
413
|
-
"User logged in successfully [myapp/api/auth/login]",
|
|
414
|
-
);
|
|
415
|
-
});
|
package/src/mod.ts
DELETED
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A winston adapter for LogTape logging library.
|
|
3
|
-
*
|
|
4
|
-
* This module provides functionality to integrate LogTape with winston,
|
|
5
|
-
* allowing LogTape logs to be forwarded to winston loggers while maintaining
|
|
6
|
-
* structured logging capabilities and category information.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { configure } from "@logtape/logtape";
|
|
11
|
-
* import winston from "winston";
|
|
12
|
-
* import { getWinstonSink } from "@logtape/adaptor-winston";
|
|
13
|
-
*
|
|
14
|
-
* const winstonLogger = winston.createLogger({
|
|
15
|
-
* level: "info",
|
|
16
|
-
* format: winston.format.json(),
|
|
17
|
-
* transports: [new winston.transports.Console()]
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* await configure({
|
|
21
|
-
* sinks: {
|
|
22
|
-
* winston: getWinstonSink(winstonLogger)
|
|
23
|
-
* },
|
|
24
|
-
* loggers: [
|
|
25
|
-
* { category: "myapp", sinks: ["winston"] }
|
|
26
|
-
* ]
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @module
|
|
31
|
-
* @since 1.0.0
|
|
32
|
-
*/
|
|
33
|
-
import {
|
|
34
|
-
configureSync,
|
|
35
|
-
type LogLevel,
|
|
36
|
-
type LogRecord,
|
|
37
|
-
type Sink,
|
|
38
|
-
} from "@logtape/logtape";
|
|
39
|
-
import winston, { type LeveledLogMethod } from "winston";
|
|
40
|
-
import { inspect } from "node:util";
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Logger interface for Winston-compatible loggers.
|
|
44
|
-
* @since 1.0.0
|
|
45
|
-
*/
|
|
46
|
-
export interface Logger {
|
|
47
|
-
error: LeveledLogMethod;
|
|
48
|
-
warn: LeveledLogMethod;
|
|
49
|
-
info: LeveledLogMethod;
|
|
50
|
-
http: LeveledLogMethod;
|
|
51
|
-
verbose: LeveledLogMethod;
|
|
52
|
-
debug: LeveledLogMethod;
|
|
53
|
-
silly: LeveledLogMethod;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Configuration options for the winston sink.
|
|
58
|
-
*
|
|
59
|
-
* @example Basic usage with default options
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const sink = getWinstonSink(winstonLogger);
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @example Custom level mapping
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const sink = getWinstonSink(winstonLogger, {
|
|
67
|
-
* levelsMap: {
|
|
68
|
-
* "trace": "debug",
|
|
69
|
-
* "debug": "debug",
|
|
70
|
-
* "info": "info",
|
|
71
|
-
* "warning": "warn",
|
|
72
|
-
* "error": "error",
|
|
73
|
-
* "fatal": "error"
|
|
74
|
-
* }
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @example Custom category formatting
|
|
79
|
-
* ```typescript
|
|
80
|
-
* const sink = getWinstonSink(winstonLogger, {
|
|
81
|
-
* category: {
|
|
82
|
-
* separator: ".",
|
|
83
|
-
* position: "start",
|
|
84
|
-
* decorator: "[]"
|
|
85
|
-
* }
|
|
86
|
-
* });
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* @since 1.0.0
|
|
90
|
-
*/
|
|
91
|
-
export interface WinstonSinkOptions {
|
|
92
|
-
/**
|
|
93
|
-
* Mapping between LogTape log levels and winston log levels.
|
|
94
|
-
*
|
|
95
|
-
* By default, LogTape levels are mapped as follows:
|
|
96
|
-
*
|
|
97
|
-
* - `trace` → `silly`
|
|
98
|
-
* - `debug` → `debug`
|
|
99
|
-
* - `info` → `info`
|
|
100
|
-
* - `warning` → `warn`
|
|
101
|
-
* - `error` → `error`
|
|
102
|
-
* - `fatal` → `error`
|
|
103
|
-
*/
|
|
104
|
-
readonly levelsMap?: Readonly<Record<LogLevel, keyof Logger>>;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Configuration for how LogTape categories are handled in winston logs.
|
|
108
|
-
*
|
|
109
|
-
* - `false` or `undefined`: Categories are not included in the log message
|
|
110
|
-
* - `true`: Categories are included with default formatting (":" decorator at start)
|
|
111
|
-
* - `CategoryOptions`: Custom category formatting configuration
|
|
112
|
-
*
|
|
113
|
-
* @default undefined
|
|
114
|
-
*/
|
|
115
|
-
readonly category?: boolean | CategoryOptions;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Custom formatter for interpolated values in log messages.
|
|
119
|
-
*
|
|
120
|
-
* This function is used to convert values that are interpolated into
|
|
121
|
-
* log messages (e.g., the `name` in
|
|
122
|
-
* `logger.info("Hello, {name}!", { name: "world" })`).
|
|
123
|
-
*
|
|
124
|
-
* @param value The value to format
|
|
125
|
-
* @returns A string representation of the value
|
|
126
|
-
* @default `inspect` (from `node:util` module)
|
|
127
|
-
*/
|
|
128
|
-
readonly valueFormatter?: (value: unknown) => string;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Configuration options for formatting LogTape categories in winston log messages.
|
|
133
|
-
*
|
|
134
|
-
* Categories in LogTape represent a hierarchical namespace for loggers
|
|
135
|
-
* (e.g., ["myapp", "database", "connection"]). This interface controls
|
|
136
|
-
* how these categories are formatted when included in winston log messages.
|
|
137
|
-
*
|
|
138
|
-
* @example Default formatting
|
|
139
|
-
* ```typescript
|
|
140
|
-
* // With category ["myapp", "db"] and default options:
|
|
141
|
-
* // Output: "myapp·db: User logged in"
|
|
142
|
-
* const options: CategoryOptions = {};
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
|
-
* @example Custom separator and decorator
|
|
146
|
-
* ```typescript
|
|
147
|
-
* // With category ["myapp", "db"] and custom options:
|
|
148
|
-
* // Output: "[myapp.db] User logged in"
|
|
149
|
-
* const options: CategoryOptions = {
|
|
150
|
-
* separator: ".",
|
|
151
|
-
* decorator: "[]"
|
|
152
|
-
* };
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* @example Category at end
|
|
156
|
-
* ```typescript
|
|
157
|
-
* // With category ["myapp", "db"] and position at end:
|
|
158
|
-
* // Output: "User logged in: myapp·db"
|
|
159
|
-
* const options: CategoryOptions = {
|
|
160
|
-
* position: "end"
|
|
161
|
-
* };
|
|
162
|
-
* ```
|
|
163
|
-
*
|
|
164
|
-
* @since 1.0.0
|
|
165
|
-
*/
|
|
166
|
-
export interface CategoryOptions {
|
|
167
|
-
/**
|
|
168
|
-
* The separator used to join category parts when multiple categories exist.
|
|
169
|
-
* @default "·"
|
|
170
|
-
*/
|
|
171
|
-
readonly separator?: string;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Where to position the category in the log message.
|
|
175
|
-
* - `"start"`: Category appears at the beginning of the message
|
|
176
|
-
* - `"end"`: Category appears at the end of the message
|
|
177
|
-
* @default "start"
|
|
178
|
-
*/
|
|
179
|
-
readonly position?: "start" | "end";
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* The decorator used to format the category in the log message.
|
|
183
|
-
* - `"[]"`: [category] format
|
|
184
|
-
* - `"()"`: (category) format
|
|
185
|
-
* - `"<>"`: <category> format
|
|
186
|
-
* - `"{}"`: {category} format
|
|
187
|
-
* - `":"`: category: format
|
|
188
|
-
* - `"-"`: category - format
|
|
189
|
-
* - `"|"`: category | format
|
|
190
|
-
* - `"/"`: category / format
|
|
191
|
-
* - `""`: category format (no decoration)
|
|
192
|
-
* @default ":"
|
|
193
|
-
*/
|
|
194
|
-
readonly decorator?: "[]" | "()" | "<>" | "{}" | ":" | "-" | "|" | "/" | "";
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const DEFAULT_LEVELS_MAP: Readonly<Record<LogLevel, keyof Logger>> = {
|
|
198
|
-
"trace": "silly",
|
|
199
|
-
"debug": "debug",
|
|
200
|
-
"info": "info",
|
|
201
|
-
"warning": "warn",
|
|
202
|
-
"error": "error",
|
|
203
|
-
"fatal": "error",
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Creates a LogTape sink that forwards log records to a winston logger.
|
|
208
|
-
*
|
|
209
|
-
* This function creates a sink function that can be used with LogTape's
|
|
210
|
-
* configuration system. The sink will format LogTape log records and
|
|
211
|
-
* forward them to the provided winston logger instance.
|
|
212
|
-
*
|
|
213
|
-
* @example Basic usage
|
|
214
|
-
* ```typescript
|
|
215
|
-
* import winston from "winston";
|
|
216
|
-
* import { configure } from "@logtape/logtape";
|
|
217
|
-
* import { getWinstonSink } from "@logtape/adaptor-winston";
|
|
218
|
-
*
|
|
219
|
-
* const winstonLogger = winston.createLogger({
|
|
220
|
-
* level: "info",
|
|
221
|
-
* format: winston.format.combine(
|
|
222
|
-
* winston.format.timestamp(),
|
|
223
|
-
* winston.format.json()
|
|
224
|
-
* ),
|
|
225
|
-
* transports: [new winston.transports.Console()]
|
|
226
|
-
* });
|
|
227
|
-
*
|
|
228
|
-
* await configure({
|
|
229
|
-
* sinks: {
|
|
230
|
-
* winston: getWinstonSink(winstonLogger)
|
|
231
|
-
* },
|
|
232
|
-
* loggers: [
|
|
233
|
-
* { category: ["myapp"], sinks: ["winston"] }
|
|
234
|
-
* ]
|
|
235
|
-
* });
|
|
236
|
-
* ```
|
|
237
|
-
*
|
|
238
|
-
* @example With custom options
|
|
239
|
-
* ```typescript
|
|
240
|
-
* const sink = getWinstonSink(winstonLogger, {
|
|
241
|
-
* category: {
|
|
242
|
-
* separator: ".",
|
|
243
|
-
* position: "start",
|
|
244
|
-
* decorator: "[]"
|
|
245
|
-
* },
|
|
246
|
-
* levelsMap: {
|
|
247
|
-
* "trace": "debug", // Map trace to debug instead of silly
|
|
248
|
-
* "debug": "debug",
|
|
249
|
-
* "info": "info",
|
|
250
|
-
* "warning": "warn",
|
|
251
|
-
* "error": "error",
|
|
252
|
-
* "fatal": "error"
|
|
253
|
-
* }
|
|
254
|
-
* });
|
|
255
|
-
* ```
|
|
256
|
-
*
|
|
257
|
-
* @param logger The winston logger instance to forward logs to. Must implement
|
|
258
|
-
* the Logger interface with error, warn, info, http, verbose,
|
|
259
|
-
* debug, and silly methods.
|
|
260
|
-
* @param options Configuration options for the sink behavior.
|
|
261
|
-
* @returns A sink function that can be used with LogTape's configure() function.
|
|
262
|
-
* @since 1.0.0
|
|
263
|
-
*/
|
|
264
|
-
export function getWinstonSink(
|
|
265
|
-
logger: Logger,
|
|
266
|
-
options: WinstonSinkOptions = {},
|
|
267
|
-
): Sink {
|
|
268
|
-
const { levelsMap = DEFAULT_LEVELS_MAP, valueFormatter = inspect } = options;
|
|
269
|
-
const categoryOptions = !options.category
|
|
270
|
-
? undefined
|
|
271
|
-
: typeof options.category === "object"
|
|
272
|
-
? options.category
|
|
273
|
-
: {};
|
|
274
|
-
const category: Required<CategoryOptions> | undefined =
|
|
275
|
-
categoryOptions == null ? undefined : {
|
|
276
|
-
separator: categoryOptions.separator ?? "·",
|
|
277
|
-
position: categoryOptions.position ?? "start",
|
|
278
|
-
decorator: categoryOptions.decorator ?? ":",
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
return (record: LogRecord) => {
|
|
282
|
-
const level = levelsMap[record.level];
|
|
283
|
-
let message = "";
|
|
284
|
-
if (category?.position === "start" && record.category.length > 0) {
|
|
285
|
-
const joinedCategory = record.category.join(category.separator);
|
|
286
|
-
message += category.decorator === "[]"
|
|
287
|
-
? `[${joinedCategory}] `
|
|
288
|
-
: category.decorator === "()"
|
|
289
|
-
? `(${joinedCategory}) `
|
|
290
|
-
: category.decorator === "<>"
|
|
291
|
-
? `<${joinedCategory}> `
|
|
292
|
-
: category.decorator === "{}"
|
|
293
|
-
? `{${joinedCategory}} `
|
|
294
|
-
: category.decorator === ":"
|
|
295
|
-
? `${joinedCategory}: `
|
|
296
|
-
: category.decorator === "-"
|
|
297
|
-
? `${joinedCategory} - `
|
|
298
|
-
: category.decorator === "|"
|
|
299
|
-
? `${joinedCategory} | `
|
|
300
|
-
: category.decorator === "/"
|
|
301
|
-
? `${joinedCategory} / `
|
|
302
|
-
: `${joinedCategory} `;
|
|
303
|
-
}
|
|
304
|
-
for (let i = 0; i < record.message.length; i += 2) {
|
|
305
|
-
message += record.message[i];
|
|
306
|
-
if (i + 1 < record.message.length) {
|
|
307
|
-
message += valueFormatter(record.message[i + 1]);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
if (category?.position === "end" && record.category.length > 0) {
|
|
311
|
-
const joinedCategory = record.category.join(category.separator);
|
|
312
|
-
message += category.decorator === "[]"
|
|
313
|
-
? ` [${joinedCategory}]`
|
|
314
|
-
: category.decorator === "()"
|
|
315
|
-
? ` (${joinedCategory})`
|
|
316
|
-
: category.decorator === "<>"
|
|
317
|
-
? ` <${joinedCategory}>`
|
|
318
|
-
: category.decorator === "{}"
|
|
319
|
-
? ` {${joinedCategory}}`
|
|
320
|
-
: category.decorator === ":"
|
|
321
|
-
? `: ${joinedCategory}`
|
|
322
|
-
: category.decorator === "-"
|
|
323
|
-
? ` - ${joinedCategory}`
|
|
324
|
-
: category.decorator === "|"
|
|
325
|
-
? ` | ${joinedCategory}`
|
|
326
|
-
: category.decorator === "/"
|
|
327
|
-
? ` / ${joinedCategory}`
|
|
328
|
-
: ` ${joinedCategory}`;
|
|
329
|
-
}
|
|
330
|
-
logger[level](message, record.properties);
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Automatically configures LogTape to route all logs to a winston logger.
|
|
336
|
-
*
|
|
337
|
-
* This is a convenience function that automatically sets up LogTape to forward
|
|
338
|
-
* all log records to a winston logger instance. By default, it uses winston's
|
|
339
|
-
* default logger, but you can provide a custom logger as the first parameter.
|
|
340
|
-
*
|
|
341
|
-
* @param logger The winston logger instance to use.
|
|
342
|
-
* @param options Configuration options for the winston sink behavior.
|
|
343
|
-
*
|
|
344
|
-
* @example Basic auto-configuration with default logger
|
|
345
|
-
* ```typescript
|
|
346
|
-
* import { install } from "@logtape/adaptor-winston";
|
|
347
|
-
*
|
|
348
|
-
* // Automatically route all LogTape logs to winston's default logger
|
|
349
|
-
* install();
|
|
350
|
-
*
|
|
351
|
-
* // Now any LogTape-enabled library will log through winston
|
|
352
|
-
* import { getLogger } from "@logtape/logtape";
|
|
353
|
-
* const logger = getLogger("my-app");
|
|
354
|
-
* logger.info("This will be logged through winston");
|
|
355
|
-
* ```
|
|
356
|
-
*
|
|
357
|
-
* @example Auto-configuration with custom winston logger
|
|
358
|
-
* ```typescript
|
|
359
|
-
* import winston from "winston";
|
|
360
|
-
* import { install } from "@logtape/adaptor-winston";
|
|
361
|
-
*
|
|
362
|
-
* const customLogger = winston.createLogger({
|
|
363
|
-
* level: "info",
|
|
364
|
-
* format: winston.format.combine(
|
|
365
|
-
* winston.format.timestamp(),
|
|
366
|
-
* winston.format.json()
|
|
367
|
-
* ),
|
|
368
|
-
* transports: [
|
|
369
|
-
* new winston.transports.Console(),
|
|
370
|
-
* new winston.transports.File({ filename: "app.log" })
|
|
371
|
-
* ]
|
|
372
|
-
* });
|
|
373
|
-
*
|
|
374
|
-
* // Install with custom logger
|
|
375
|
-
* install(customLogger);
|
|
376
|
-
* ```
|
|
377
|
-
*
|
|
378
|
-
* @example Auto-configuration with custom options
|
|
379
|
-
* ```typescript
|
|
380
|
-
* import { install } from "@logtape/adaptor-winston";
|
|
381
|
-
*
|
|
382
|
-
* install(undefined, {
|
|
383
|
-
* category: {
|
|
384
|
-
* position: "start",
|
|
385
|
-
* decorator: "[]",
|
|
386
|
-
* separator: "."
|
|
387
|
-
* },
|
|
388
|
-
* levelsMap: {
|
|
389
|
-
* "trace": "debug" // Map LogTape trace to winston debug
|
|
390
|
-
* }
|
|
391
|
-
* });
|
|
392
|
-
* ```
|
|
393
|
-
*
|
|
394
|
-
* @example Custom logger with custom options
|
|
395
|
-
* ```typescript
|
|
396
|
-
* import winston from "winston";
|
|
397
|
-
* import { install } from "@logtape/adaptor-winston";
|
|
398
|
-
*
|
|
399
|
-
* const customLogger = winston.createLogger({
|
|
400
|
-
* transports: [new winston.transports.Console()]
|
|
401
|
-
* });
|
|
402
|
-
*
|
|
403
|
-
* install(customLogger, {
|
|
404
|
-
* category: { position: "start", decorator: "[]" }
|
|
405
|
-
* });
|
|
406
|
-
* ```
|
|
407
|
-
*
|
|
408
|
-
* @since 1.0.0
|
|
409
|
-
*/
|
|
410
|
-
export function install(
|
|
411
|
-
logger: Logger,
|
|
412
|
-
options?: WinstonSinkOptions,
|
|
413
|
-
): void;
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Configures LogTape to route all logs to winston's default logger.
|
|
417
|
-
*
|
|
418
|
-
* @param options Optional configuration for the winston sink behavior.
|
|
419
|
-
* @since 1.0.0
|
|
420
|
-
*/
|
|
421
|
-
export function install(
|
|
422
|
-
options?: WinstonSinkOptions,
|
|
423
|
-
): void;
|
|
424
|
-
|
|
425
|
-
export function install(
|
|
426
|
-
loggerOrOptions?: Logger | WinstonSinkOptions,
|
|
427
|
-
options: WinstonSinkOptions = {},
|
|
428
|
-
): void {
|
|
429
|
-
let logger: Logger;
|
|
430
|
-
let sinkOptions: WinstonSinkOptions;
|
|
431
|
-
|
|
432
|
-
// Handle overloaded parameters
|
|
433
|
-
if (
|
|
434
|
-
loggerOrOptions && ("error" in loggerOrOptions || "info" in loggerOrOptions)
|
|
435
|
-
) {
|
|
436
|
-
// First parameter is a Logger
|
|
437
|
-
logger = loggerOrOptions as Logger;
|
|
438
|
-
sinkOptions = options;
|
|
439
|
-
} else {
|
|
440
|
-
// First parameter is WinstonSinkOptions or undefined
|
|
441
|
-
logger = winston;
|
|
442
|
-
sinkOptions = (loggerOrOptions as WinstonSinkOptions) || {};
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
configureSync({
|
|
446
|
-
sinks: {
|
|
447
|
-
winston: getWinstonSink(logger, sinkOptions),
|
|
448
|
-
},
|
|
449
|
-
loggers: [
|
|
450
|
-
{
|
|
451
|
-
category: ["logtape", "meta"],
|
|
452
|
-
sinks: ["winston"],
|
|
453
|
-
lowestLevel: "warning",
|
|
454
|
-
},
|
|
455
|
-
{ category: [], sinks: ["winston"] },
|
|
456
|
-
],
|
|
457
|
-
});
|
|
458
|
-
}
|