@ddd-ts-kit/winston 0.114.1 → 0.116.0
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.fr.md +34 -21
- package/README.md +31 -20
- package/dist/create-winston-logger.d.ts +1 -1
- package/dist/create-winston-logger.d.ts.map +1 -1
- package/dist/formats/redact-credentials.d.ts +2 -2
- package/dist/formats/redact-credentials.d.ts.map +1 -1
- package/dist/formats/redact-credentials.js +8 -9
- package/dist/formats/redact-credentials.js.map +1 -1
- package/dist/handed-over.d.ts +9 -0
- package/dist/handed-over.d.ts.map +1 -0
- package/dist/handed-over.js +29 -0
- package/dist/handed-over.js.map +1 -0
- package/dist/winston-logger.d.ts +12 -4
- package/dist/winston-logger.d.ts.map +1 -1
- package/dist/winston-logger.js +15 -4
- package/dist/winston-logger.js.map +1 -1
- package/package.json +3 -3
package/README.fr.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[English](README.md) · **Français**
|
|
2
|
-
<!-- translation-of: README.md sha256:
|
|
2
|
+
<!-- translation-of: README.md sha256:d33e12d0a2bd9259 -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/winston
|
|
5
5
|
|
|
@@ -63,7 +63,7 @@ const app = createApplication({
|
|
|
63
63
|
process.once('SIGTERM', () => void shutdown());
|
|
64
64
|
|
|
65
65
|
async function shutdown(): Promise<void> {
|
|
66
|
-
await app.stop(); // vide le rapporteur d'erreurs, puis le logger, en dernier
|
|
66
|
+
await app.stop(); // vide le rapporteur d'erreurs, puis le logger, en dernier
|
|
67
67
|
await tracing.shutdown();
|
|
68
68
|
}
|
|
69
69
|
```
|
|
@@ -178,7 +178,7 @@ ligne, d'un enfant et de `fields` de la même façon. La valeur de ces clés est
|
|
|
178
178
|
`privateKey`
|
|
179
179
|
|
|
180
180
|
`redact: ['iban', 'ssn']` complète la liste. Les noms sont comparés quelle que soit leur casse
|
|
181
|
-
(`Authorization`, `X-Api-Key`),
|
|
181
|
+
(`Authorization`, `X-Api-Key`, `IBAN`), par `hiddenKeys` du noyau, et rien n'est cherché
|
|
182
182
|
plus profond qu'un niveau, ni dans une liste : journalisez la partie que vous visez, pas une
|
|
183
183
|
requête HTTP entière. Les objets que vous passez ne sont jamais modifiés : un objet imbriqué est
|
|
184
184
|
copié quand une clé doit être masquée.
|
|
@@ -246,7 +246,7 @@ Une ligne sous le seuil coûte une comparaison : l'adaptateur interroge d'abord
|
|
|
246
246
|
n'écartent la ligne. Le seuil d'une instance modifié en cours d'exécution
|
|
247
247
|
(`instance.level = 'debug'`) est suivi par l'adaptateur et par ses enfants. `isLevelEnabled(level)`
|
|
248
248
|
du port répond à la même question pour le niveau correspondant : interrogez-le avant de
|
|
249
|
-
construire des champs coûteux. Une fois le *logger*
|
|
249
|
+
construire des champs coûteux. Une fois le *logger* clos, il répond `false` pour chaque niveau.
|
|
250
250
|
|
|
251
251
|
`child(fields)` est un enfant winston : les champs sont liés une fois, et winston les fusionne
|
|
252
252
|
sous les champs de chaque ligne. Trois choses diffèrent de ce que fait winston appelé
|
|
@@ -259,25 +259,38 @@ l'emporte sur un champ du même nom sur une ligne ou dans un enfant, là où les
|
|
|
259
259
|
|
|
260
260
|
## Vidage
|
|
261
261
|
|
|
262
|
-
`flush(): Promise<void>`
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
`flush(): Promise<void>` se résout une fois que winston a confié à chacun de ses transports
|
|
263
|
+
chaque ligne journalisée jusque-là, par le *logger* ou un enfant : aucune n'attend dans le flux
|
|
264
|
+
du *logger* ni dans celui d'un transport. Il ne rejette jamais, et attend dix secondes au plus
|
|
265
|
+
un transport qui ne répond pas. `app.stop()` l'appelle,
|
|
266
|
+
en dernier, après l'arrêt des modules et le vidage du rapporteur d'erreurs : l'arrêt journalise
|
|
267
|
+
lui aussi. Sans l'application du *package* di, appelez-le vous-même à cet endroit.
|
|
268
|
+
|
|
269
|
+
Un vidage ne clôt rien, comme le dit le port et comme le fait `@ddd-ts-kit/pino` : une ligne
|
|
270
|
+
journalisée ensuite est écrite comme les autres, et un vidage ultérieur l'attend à son tour. Ce
|
|
271
|
+
qu'un transport fait d'une ligne qu'il a prise n'est pas attendu : le transport `File` de
|
|
272
|
+
winston a pris chaque ligne quand `flush()` se résout et écrit les dernières dans son fichier
|
|
273
|
+
pendant que le processus continue, et un transport sur un flux que vous avez ouvert vous-même
|
|
274
|
+
(une *socket*, un flux de fichier donné au transport `Stream`) a confié ses lignes à ce flux,
|
|
275
|
+
dont la fermeture vous revient.
|
|
276
|
+
|
|
277
|
+
`end(): Promise<void>`, sur le `WinstonLogger`, est l'autre verbe : il clôt le *logger* winston
|
|
278
|
+
et se résout une fois que chaque transport a terminé (leur événement `finish`), un fichier fermé
|
|
279
|
+
sur toutes ses lignes. Il est définitif, puisqu'un *logger* winston ne se rouvre pas : ce qui
|
|
280
|
+
est journalisé ensuite, par ce *logger* ou l'un de ses enfants, est écarté sans erreur,
|
|
281
|
+
`isLevelEnabled` répond `false`, et un second appel renvoie la même promesse. Appelez-le là où
|
|
282
|
+
le processus s'apprête à sortir de lui-même, après `app.stop()` :
|
|
267
283
|
|
|
268
|
-
|
|
284
|
+
```ts
|
|
285
|
+
await app.stop();
|
|
286
|
+
await logger.end(); // avant un process.exit() : le transport File a fermé son fichier
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
| Une fois résolu | `flush()` | `end()` |
|
|
269
290
|
|---|---|---|
|
|
270
|
-
| une ligne journalisée |
|
|
271
|
-
| `isLevelEnabled(level)` | `false` pour chaque niveau |
|
|
272
|
-
| un second
|
|
273
|
-
|
|
274
|
-
Le port appelle un vidage une fois, à l'arrêt, et ne précise pas ce qui est journalisé ensuite.
|
|
275
|
-
Ici le vidage est définitif : un *logger* winston ne se rouvre pas, donc ce qui est journalisé
|
|
276
|
-
ensuite, par ce *logger* ou l'un de ses enfants, est écarté sans erreur, et `isLevelEnabled`
|
|
277
|
-
répond `false`. Tout ce qui doit être journalisé à propos de l'arrêt l'est avant le retour de
|
|
278
|
-
`app.stop()`. Un transport sur un flux que vous avez ouvert vous-même (une *socket*, un flux de
|
|
279
|
-
fichier donné au transport `Stream`) a confié ses lignes à ce flux quand `flush()` se résout :
|
|
280
|
-
fermer ce flux vous revient.
|
|
291
|
+
| une ligne journalisée | écrite, comme avant | écartée, sans erreur |
|
|
292
|
+
| `isLevelEnabled(level)` | le seuil, comme avant | `false` pour chaque niveau |
|
|
293
|
+
| un second appel | un nouveau vidage | la même promesse |
|
|
281
294
|
|
|
282
295
|
## Performances
|
|
283
296
|
|
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ const app = createApplication({
|
|
|
60
60
|
process.once('SIGTERM', () => void shutdown());
|
|
61
61
|
|
|
62
62
|
async function shutdown(): Promise<void> {
|
|
63
|
-
await app.stop(); // flushes the error reporter, then the logger, last
|
|
63
|
+
await app.stop(); // flushes the error reporter, then the logger, last
|
|
64
64
|
await tracing.shutdown();
|
|
65
65
|
}
|
|
66
66
|
```
|
|
@@ -170,7 +170,7 @@ one level below (`headers.authorization`, `body.password`):
|
|
|
170
170
|
`privateKey`
|
|
171
171
|
|
|
172
172
|
`redact: ['iban', 'ssn']` adds to the list. Names are matched whatever their case
|
|
173
|
-
(`Authorization`, `X-Api-Key`),
|
|
173
|
+
(`Authorization`, `X-Api-Key`, `IBAN`), by `hiddenKeys` of the kernel, and nothing is looked
|
|
174
174
|
for deeper than one level, nor inside a list: log the part you mean, not a whole request. The
|
|
175
175
|
objects you pass are never written to: a nested one is copied when a key has to be hidden.
|
|
176
176
|
|
|
@@ -234,7 +234,7 @@ A line below the threshold costs one comparison: the adapter asks `isLevelEnable
|
|
|
234
234
|
because winston alone would run every format before its transports drop the line. The
|
|
235
235
|
threshold of an instance changed while running (`instance.level = 'debug'`) is followed by the
|
|
236
236
|
adapter and by its children. `isLevelEnabled(level)` of the port answers the same question for
|
|
237
|
-
the mapped level: ask it before building fields that cost. Once the logger was
|
|
237
|
+
the mapped level: ask it before building fields that cost. Once the logger was ended it
|
|
238
238
|
answers `false` for every level.
|
|
239
239
|
|
|
240
240
|
`child(fields)` is a winston child: the fields are bound once, and winston merges them under
|
|
@@ -248,25 +248,36 @@ the child win.
|
|
|
248
248
|
|
|
249
249
|
## Flush
|
|
250
250
|
|
|
251
|
-
`flush(): Promise<void>`
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
was flushed: stopping logs too. Without the
|
|
255
|
-
that place.
|
|
251
|
+
`flush(): Promise<void>` resolves once winston has handed each of its transports every line
|
|
252
|
+
logged so far, through the logger or a child: none waits in the stream of the logger or of a
|
|
253
|
+
transport. It never rejects, and waits ten seconds at most for a transport that does not answer. `app.stop()` calls it, last, after
|
|
254
|
+
the modules stopped and the error reporter was flushed: stopping logs too. Without the
|
|
255
|
+
application of the di package, call it yourself at that place.
|
|
256
|
+
|
|
257
|
+
A flush ends nothing, as the port says and as `@ddd-ts-kit/pino` does: a line logged after it
|
|
258
|
+
is written like the others, and a later flush waits for it in turn. What a transport does with
|
|
259
|
+
a line it took is not waited for: the `File` transport of winston has taken every line when
|
|
260
|
+
`flush()` resolves and writes the last of them to its file while the process runs on, and
|
|
261
|
+
a transport over a stream you opened yourself (a socket, a file stream given to the `Stream`
|
|
262
|
+
transport) has handed its lines to that stream, whose end is yours.
|
|
263
|
+
|
|
264
|
+
`end(): Promise<void>`, on the `WinstonLogger`, is the other verb: it ends the winston logger
|
|
265
|
+
and resolves once each transport has finished (their `finish` event), a file closed over all
|
|
266
|
+
its lines. It is final, since a winston logger does not reopen: what is logged afterwards,
|
|
267
|
+
through this logger or one of its children, is dropped without an error, `isLevelEnabled`
|
|
268
|
+
answers `false`, and a second call answers the same promise. Call it where the process is about
|
|
269
|
+
to leave by itself, after `app.stop()`:
|
|
256
270
|
|
|
257
|
-
|
|
271
|
+
```ts
|
|
272
|
+
await app.stop();
|
|
273
|
+
await logger.end(); // before a process.exit(): the File transport has closed its file
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
| After it resolved | `flush()` | `end()` |
|
|
258
277
|
|---|---|---|
|
|
259
|
-
| a line logged |
|
|
260
|
-
| `isLevelEnabled(level)` | `false` for every level |
|
|
261
|
-
| a second
|
|
262
|
-
|
|
263
|
-
The port calls a flush once, at shutdown, and leaves what is logged afterwards unspecified.
|
|
264
|
-
Here the flush is final: a winston logger does not reopen, so what is logged afterwards,
|
|
265
|
-
through this logger or one of its children, is dropped without an error, and `isLevelEnabled`
|
|
266
|
-
answers `false`. Whatever must be logged about the shutdown is logged before `app.stop()`
|
|
267
|
-
returns. A transport over a stream you opened yourself
|
|
268
|
-
(a socket, a file stream given to the `Stream` transport) has handed its lines to that stream
|
|
269
|
-
when `flush()` resolves: ending that stream is yours.
|
|
278
|
+
| a line logged | written, like before | dropped, without an error |
|
|
279
|
+
| `isLevelEnabled(level)` | the threshold, as before | `false` for every level |
|
|
280
|
+
| a second call | a new flush | the same promise |
|
|
270
281
|
|
|
271
282
|
## Performance
|
|
272
283
|
|
|
@@ -20,7 +20,7 @@ export interface CreateWinstonLoggerOptions extends Pick<WinstonLoggerOptions, '
|
|
|
20
20
|
* `traceLogFields` of the tracing package or `logFieldsOf` of the current execution context.
|
|
21
21
|
*/
|
|
22
22
|
readonly fields?: () => LogFields;
|
|
23
|
-
/** Field names hidden in addition to `CREDENTIAL_KEYS`, at the top of a line and one level below. */
|
|
23
|
+
/** Field names hidden in addition to `CREDENTIAL_KEYS`, at the top of a line and one level below, whatever their case. */
|
|
24
24
|
readonly redact?: readonly string[];
|
|
25
25
|
/** Where the lines go. Default: the console transport, on the standard output. */
|
|
26
26
|
readonly transports?: NonNullable<winston.LoggerOptions['transports']>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-winston-logger.d.ts","sourceRoot":"","sources":["../src/create-winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO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Q,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,SAAS,CAAC;IAClC,0HAA0H;IAC1H,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,kFAAkF;IAClF,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;CACxE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,GAAG,aAAa,CAW3F"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import winston from 'winston';
|
|
2
2
|
/**
|
|
3
3
|
* A winston format hiding the value of `CREDENTIAL_KEYS` and of the given keys at the top of a
|
|
4
|
-
* line and one level below. Names are matched without case, as `
|
|
5
|
-
*
|
|
4
|
+
* line and one level below. Names are matched without case, as `hiddenKeys` of the kernel
|
|
5
|
+
* matches them. Place it after the formats that add fields.
|
|
6
6
|
*/
|
|
7
7
|
export declare function redactCredentials(keys?: readonly string[]): winston.Logform.Format;
|
|
8
8
|
//# sourceMappingURL=redact-credentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redact-credentials.d.ts","sourceRoot":"","sources":["../../src/formats/redact-credentials.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"redact-credentials.d.ts","sourceRoot":"","sources":["../../src/formats/redact-credentials.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,SAAS,MAAM,EAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAcnG"}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { CREDENTIAL_KEYS, REDACTED,
|
|
1
|
+
import { CREDENTIAL_KEYS, REDACTED, hiddenKeys } from '@ddd-ts-kit/kernel';
|
|
2
2
|
import winston from 'winston';
|
|
3
3
|
/**
|
|
4
4
|
* A winston format hiding the value of `CREDENTIAL_KEYS` and of the given keys at the top of a
|
|
5
|
-
* line and one level below. Names are matched without case, as `
|
|
6
|
-
*
|
|
5
|
+
* line and one level below. Names are matched without case, as `hiddenKeys` of the kernel
|
|
6
|
+
* matches them. Place it after the formats that add fields.
|
|
7
7
|
*/
|
|
8
8
|
export function redactCredentials(keys = CREDENTIAL_KEYS) {
|
|
9
|
-
const
|
|
10
|
-
const hidden = (key) => isCredentialKey(key) || added.has(key.toLowerCase());
|
|
9
|
+
const isHidden = hiddenKeys(keys);
|
|
11
10
|
return winston.format((info) => {
|
|
12
11
|
for (const [key, value] of Object.entries(info)) {
|
|
13
|
-
if (
|
|
12
|
+
if (isHidden(key)) {
|
|
14
13
|
info[key] = REDACTED;
|
|
15
14
|
}
|
|
16
15
|
else if (isRecord(value)) {
|
|
17
|
-
info[key] = withoutCredentials(value,
|
|
16
|
+
info[key] = withoutCredentials(value, isHidden);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
return info;
|
|
@@ -24,8 +23,8 @@ function isRecord(value) {
|
|
|
24
23
|
return typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date);
|
|
25
24
|
}
|
|
26
25
|
/** A nested object belongs to the caller: it is copied when a key has to be hidden, never written to. */
|
|
27
|
-
function withoutCredentials(nested,
|
|
28
|
-
const credentials = Object.keys(nested).filter(
|
|
26
|
+
function withoutCredentials(nested, isHidden) {
|
|
27
|
+
const credentials = Object.keys(nested).filter(isHidden);
|
|
29
28
|
if (credentials.length === 0) {
|
|
30
29
|
return nested;
|
|
31
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redact-credentials.js","sourceRoot":"","sources":["../../src/formats/redact-credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,QAAQ,EA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CAAC;QAC7B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type winston from 'winston';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves once the logger has handed each of its transports every line it was given, and ends
|
|
4
|
+
* none of them: no line waits in the stream of the logger or of a transport. winston says when a
|
|
5
|
+
* stream has finished, never when it has caught up: the buffers are looked at again until they
|
|
6
|
+
* are empty, ten seconds at most.
|
|
7
|
+
*/
|
|
8
|
+
export declare function handedOver(logger: winston.Logger): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=handed-over.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handed-over.d.ts","sourceRoot":"","sources":["../src/handed-over.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAUnC;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAItE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** How long a flush waits before it looks at the buffers again. */
|
|
2
|
+
const LOOK_AGAIN_MS = 5;
|
|
3
|
+
/** The longest a flush waits: a transport that never answers does not hold a shutdown for ever. */
|
|
4
|
+
const LONGEST_WAIT_MS = 10_000;
|
|
5
|
+
/**
|
|
6
|
+
* Resolves once the logger has handed each of its transports every line it was given, and ends
|
|
7
|
+
* none of them: no line waits in the stream of the logger or of a transport. winston says when a
|
|
8
|
+
* stream has finished, never when it has caught up: the buffers are looked at again until they
|
|
9
|
+
* are empty, ten seconds at most.
|
|
10
|
+
*/
|
|
11
|
+
export async function handedOver(logger) {
|
|
12
|
+
for (let waited = 0; holdsLines(logger) && waited < LONGEST_WAIT_MS; waited += LOOK_AGAIN_MS) {
|
|
13
|
+
await pause(LOOK_AGAIN_MS);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Without a transport left to take them, the lines the logger holds wait for nothing. */
|
|
17
|
+
function holdsLines(logger) {
|
|
18
|
+
const transports = logger.transports.filter((transport) => !transport.destroyed);
|
|
19
|
+
return transports.length > 0 && (logger.readableLength > 0 || [logger, ...transports].some(isBehind));
|
|
20
|
+
}
|
|
21
|
+
function isBehind(stream) {
|
|
22
|
+
return stream.writableLength > 0;
|
|
23
|
+
}
|
|
24
|
+
function pause(milliseconds) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
setTimeout(resolve, milliseconds);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=handed-over.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handed-over.js","sourceRoot":"","sources":["../src/handed-over.ts"],"names":[],"mappings":"AAIA,mEAAmE;AACnE,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,mGAAmG;AACnG,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAsB;IACrD,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,eAAe,EAAE,MAAM,IAAI,aAAa,EAAE,CAAC;QAC7F,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,0FAA0F;AAC1F,SAAS,UAAU,CAAC,MAAsB;IACxC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAEjF,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxG,CAAC;AAED,SAAS,QAAQ,CAAC,MAAiB;IACjC,OAAO,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,KAAK,CAAC,YAAoB;IACjC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/winston-logger.d.ts
CHANGED
|
@@ -32,15 +32,23 @@ export declare class WinstonLogger implements Logger {
|
|
|
32
32
|
/**
|
|
33
33
|
* Whether winston would hand an entry of that level to a transport. winston filters by level
|
|
34
34
|
* in its transports, after the formats: asked here, a dropped entry costs nothing. `false`
|
|
35
|
-
* for every level once the logger was
|
|
35
|
+
* for every level once the logger was ended.
|
|
36
36
|
*/
|
|
37
37
|
isLevelEnabled(level: LogLevel): boolean;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Resolves once winston has handed its transports every line logged so far, through this
|
|
40
|
+
* logger or a child. Never rejects, and ends nothing: a line logged afterwards is written
|
|
41
|
+
* like the others. What a transport still holds of the lines it took, as the `File` transport
|
|
42
|
+
* holds the end of its file, is written by the time the logger has ended.
|
|
42
43
|
*/
|
|
43
44
|
flush(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Ends the winston logger and resolves once each of its transports has finished, a file
|
|
47
|
+
* closed over all its lines. Final: winston does not reopen, so what is logged afterwards,
|
|
48
|
+
* through this logger or a child, is dropped without a throw. A second call answers the same
|
|
49
|
+
* promise. Never rejects.
|
|
50
|
+
*/
|
|
51
|
+
end(): Promise<void>;
|
|
44
52
|
private nativeChild;
|
|
45
53
|
private write;
|
|
46
54
|
private nativeLevel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../src/winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../src/winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED;;;;GAIG;AACH,qBAAa,aAAc,YAAW,MAAM;IAKxC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,IAAI,CAAuB;IACnC,OAAO,CAAC,KAAK,CAA4B;IAEzC,YACmB,OAAO,EAAE,OAAO,CAAC,MAAM,EACvB,OAAO,GAAE,oBAAyB,EACjD;IAEJ,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAE/C;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAE9C;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAE9C;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAE/C;IAED,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa,CAMtC;IAED;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAEvC;IAED;;;;;OAKG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAErB;IAED;;;;;OAKG;IACH,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAInB;IAED,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,KAAK;IAcb,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,kBAAkB;CAO3B"}
|
package/dist/winston-logger.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UNWRITABLE_FIELDS, describeErrorFields } from '@ddd-ts-kit/kernel';
|
|
2
2
|
import { endOf } from './end-of.js';
|
|
3
|
+
import { handedOver } from './handed-over.js';
|
|
3
4
|
/**
|
|
4
5
|
* The `Logger` port on a winston logger: a child is a winston child, and the formats and the
|
|
5
6
|
* transports the instance was configured with apply to every line. `createWinstonLogger`
|
|
@@ -34,17 +35,27 @@ export class WinstonLogger {
|
|
|
34
35
|
/**
|
|
35
36
|
* Whether winston would hand an entry of that level to a transport. winston filters by level
|
|
36
37
|
* in its transports, after the formats: asked here, a dropped entry costs nothing. `false`
|
|
37
|
-
* for every level once the logger was
|
|
38
|
+
* for every level once the logger was ended.
|
|
38
39
|
*/
|
|
39
40
|
isLevelEnabled(level) {
|
|
40
41
|
return this.root.ended === undefined && this.winston.isLevelEnabled(this.nativeLevel(level));
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* Resolves once winston has handed its transports every line logged so far, through this
|
|
45
|
+
* logger or a child. Never rejects, and ends nothing: a line logged afterwards is written
|
|
46
|
+
* like the others. What a transport still holds of the lines it took, as the `File` transport
|
|
47
|
+
* holds the end of its file, is written by the time the logger has ended.
|
|
46
48
|
*/
|
|
47
49
|
flush() {
|
|
50
|
+
return this.root.ended ?? handedOver(this.root.winston);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Ends the winston logger and resolves once each of its transports has finished, a file
|
|
54
|
+
* closed over all its lines. Final: winston does not reopen, so what is logged afterwards,
|
|
55
|
+
* through this logger or a child, is dropped without a throw. A second call answers the same
|
|
56
|
+
* promise. Never rejects.
|
|
57
|
+
*/
|
|
58
|
+
end() {
|
|
48
59
|
this.root.ended ??= endOf(this.root.winston).catch(() => undefined);
|
|
49
60
|
return this.root.ended;
|
|
50
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston-logger.js","sourceRoot":"","sources":["../src/winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAA8C,MAAM,oBAAoB,CAAC;AAExH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"winston-logger.js","sourceRoot":"","sources":["../src/winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAA8C,MAAM,oBAAoB,CAAC;AAExH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAgB3C;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAKL,OAAO;IACP,OAAO;IALlB,IAAI,GAAkB,IAAI,CAAC;IAC3B,KAAK,CAA4B;IAEzC,YACmB,OAAuB,EACvB,OAAO,GAAyB,EAAE;uBADlC,OAAO;uBACP,OAAO;IACvB,CAAC;IAEJ,KAAK,CAAC,OAAe,EAAE,MAAkB;QACvC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,MAAkB;QACt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E,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACvE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,KAAe,EAAE,OAAe,EAAE,MAAM,GAAc,EAAE;QACpE,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAEvC,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7F,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAEO,WAAW,CAAC,KAAe;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;IAC/C,CAAC;IAEO,kBAAkB,CAAC,KAAa,EAAE,OAAe;QACvD,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,iBAAiB,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/winston",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.116.0",
|
|
4
4
|
"description": "Adapter of the kernel Logger port on winston, with trace and execution correlation on every line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ddd",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@ddd-ts-kit/kernel": "0.
|
|
43
|
+
"@ddd-ts-kit/kernel": "0.116.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@ddd-ts-kit/testing": "0.
|
|
46
|
+
"@ddd-ts-kit/testing": "0.116.0",
|
|
47
47
|
"winston": "^3.19.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|