@lakutata/logger 0.0.0-stage → 3.0.0-beta.1
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/LICENSE +23 -0
- package/README.md +137 -2
- package/THIRD_PARTY_NOTICES.md +158 -0
- package/dist/cjs/Logger.d.ts +291 -0
- package/dist/cjs/Logger.js +185 -0
- package/dist/cjs/exports/Logger.d.ts +2 -0
- package/dist/cjs/exports/Logger.js +20 -0
- package/dist/cjs/lib/Colors.d.ts +8 -0
- package/dist/cjs/lib/Colors.js +48 -0
- package/dist/cjs/lib/Destination.d.ts +38 -0
- package/dist/cjs/lib/Destination.js +103 -0
- package/dist/cjs/lib/Format.d.ts +7 -0
- package/dist/cjs/lib/Format.js +106 -0
- package/dist/cjs/lib/Pretty.d.ts +9 -0
- package/dist/cjs/lib/Pretty.js +265 -0
- package/dist/cjs/lib/Record.d.ts +25 -0
- package/dist/cjs/lib/Record.js +139 -0
- package/dist/cjs/lib/Serializers.d.ts +26 -0
- package/dist/cjs/lib/Serializers.js +150 -0
- package/dist/cjs/lib/Stringify.d.ts +5 -0
- package/dist/cjs/lib/Stringify.js +110 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/Logger.js +182 -0
- package/dist/esm/exports/Logger.js +1 -0
- package/dist/esm/lib/Colors.js +45 -0
- package/dist/esm/lib/Destination.js +99 -0
- package/dist/esm/lib/Format.js +103 -0
- package/dist/esm/lib/Pretty.js +262 -0
- package/dist/esm/lib/Record.js +134 -0
- package/dist/esm/lib/Serializers.js +143 -0
- package/dist/esm/lib/Stringify.js +107 -0
- package/dist/types/Logger.d.ts +291 -0
- package/dist/types/exports/Logger.d.ts +2 -0
- package/dist/types/lib/Colors.d.ts +8 -0
- package/dist/types/lib/Destination.d.ts +38 -0
- package/dist/types/lib/Format.d.ts +7 -0
- package/dist/types/lib/Pretty.d.ts +9 -0
- package/dist/types/lib/Record.d.ts +25 -0
- package/dist/types/lib/Serializers.d.ts +26 -0
- package/dist/types/lib/Stringify.d.ts +5 -0
- package/package.json +43 -4
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { Component } from '@lakutata/core';
|
|
2
|
+
import type { ILogger } from '@lakutata/core/com/logger';
|
|
3
|
+
/**
|
|
4
|
+
* The logger component of the applications built with `lakutata`: the package presets it as the `log` component (and
|
|
5
|
+
* creates it first), so the framework and the application log through it. It writes the pino log format: one JSON
|
|
6
|
+
* object per line, with `level` (10 trace, 20 debug, 30 info, 40 warn, 50 error, 60 fatal), `time` (milliseconds since the epoch),
|
|
7
|
+
* `pid`, `hostname`, `name` (the application's name), the properties of the logged object and `msg`; with `pretty` on
|
|
8
|
+
* (the default), it writes readable lines instead: `[HH:MM:ss.SSS] LEVEL (name/pid): message`, then one indented line
|
|
9
|
+
* per property, in the local time zone.
|
|
10
|
+
*
|
|
11
|
+
* Configure it through the `log` entry of the application's `components` (no `class` needed:
|
|
12
|
+
* `log: {level: 'info', pretty: false}`), and get it with `@Inject('log')` or `getObject('log')`; it is a singleton.
|
|
13
|
+
* The lines are buffered and written at the next turn of the event loop (or once 16 KB are pending), and the pending
|
|
14
|
+
* lines are written synchronously when the process exits or the component is destroyed; `sync: true` writes each line
|
|
15
|
+
* at once instead. A stream with a file descriptor (stdout, stderr, an opened file) is written synchronously through
|
|
16
|
+
* it, so the lines keep their order.
|
|
17
|
+
*
|
|
18
|
+
* An HTTP request or response logged as the object of a line is written under `req` or `res` with the values of its
|
|
19
|
+
* credential headers (`Authorization`, `Cookie`, `Set-Cookie`, `Proxy-Authorization`) replaced by `[Redacted]` (see
|
|
20
|
+
* the `redactedHeaders` option). Nothing else is redacted and there are no child loggers: the other properties are
|
|
21
|
+
* written as is, so log the fields you need rather than secrets or whole objects holding them.
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import {Application, Component} from 'lakutata'
|
|
25
|
+
* import {Inject} from 'lakutata/decorator/di'
|
|
26
|
+
* import {Logger} from 'lakutata/com/logger'
|
|
27
|
+
*
|
|
28
|
+
* class Orders extends Component {
|
|
29
|
+
* @Inject('log')
|
|
30
|
+
* protected readonly log: Logger
|
|
31
|
+
*
|
|
32
|
+
* public pay(orderId: number, amount: number): void {
|
|
33
|
+
* //{"level":30,...,"orderId":42,"msg":"order 42 paid: 9.90"}
|
|
34
|
+
* this.log.info({orderId: orderId}, 'order %d paid: %s', orderId, amount.toFixed(2))
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* public fail(error: Error): void {
|
|
38
|
+
* //The error serialized under "err", its message as the message unless one is given
|
|
39
|
+
* this.log.error(error, 'payment failed')
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* Application.run(() => ({
|
|
44
|
+
* id: 'shop.app',
|
|
45
|
+
* name: 'Shop',
|
|
46
|
+
* components: {
|
|
47
|
+
* //The preset logger: JSON lines from the info level in production
|
|
48
|
+
* log: {level: 'info', pretty: process.env.NODE_ENV !== 'production'},
|
|
49
|
+
* orders: {class: Orders}
|
|
50
|
+
* }
|
|
51
|
+
* }))
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare class Logger extends Component implements ILogger {
|
|
55
|
+
#private;
|
|
56
|
+
/**
|
|
57
|
+
* Write readable lines (`[HH:MM:ss.SSS] LEVEL (name/pid): message`, then the properties) when `true`, the JSON lines
|
|
58
|
+
* of pino when `false` (for a log collector).
|
|
59
|
+
* @default true
|
|
60
|
+
* @protected
|
|
61
|
+
*/
|
|
62
|
+
protected readonly pretty: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The lowest level written: `'trace'`, `'debug'`, `'info'`, `'warn'`, `'error'`, `'fatal'` (only the lines of
|
|
65
|
+
* {@link Logger.fatal}) or `'silent'` (nothing); the lines of lower levels are dropped.
|
|
66
|
+
* @default 'trace'
|
|
67
|
+
* @protected
|
|
68
|
+
*/
|
|
69
|
+
protected readonly level: string;
|
|
70
|
+
/**
|
|
71
|
+
* Color the readable lines written to `process.stdout` (the level, the message, the properties); the other
|
|
72
|
+
* destinations and the JSON lines are never colored.
|
|
73
|
+
* @default true
|
|
74
|
+
* @protected
|
|
75
|
+
*/
|
|
76
|
+
protected readonly colorize: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Write each line at once when `true`; when `false`, the lines are buffered and written at the next turn of the
|
|
79
|
+
* event loop (or once 16 KB are pending), which costs less per line. The pending lines are written synchronously when
|
|
80
|
+
* the process exits either way.
|
|
81
|
+
* @default false
|
|
82
|
+
* @protected
|
|
83
|
+
*/
|
|
84
|
+
protected readonly sync: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* The streams the lines are written to, each receiving every line: `process.stdout`, `process.stderr`, a file
|
|
87
|
+
* (`fs.createWriteStream(path, {flags: 'a'})`) or any writable stream. The streams are not closed by the logger.
|
|
88
|
+
* @default [process.stdout]
|
|
89
|
+
* @protected
|
|
90
|
+
*/
|
|
91
|
+
protected readonly destinations: NodeJS.WritableStream[];
|
|
92
|
+
/**
|
|
93
|
+
* The headers whose values are written as `[Redacted]` when an HTTP request or response (of `node:http`, Express,
|
|
94
|
+
* Fastify) is logged as the object of a line, by name (case-insensitive). The list replaces the default one: to
|
|
95
|
+
* redact another header, list the default ones with it; `[]` writes every header as is. The headers of the request
|
|
96
|
+
* or response are not changed.
|
|
97
|
+
* @default ['authorization', 'cookie', 'set-cookie', 'proxy-authorization']
|
|
98
|
+
* @protected
|
|
99
|
+
*/
|
|
100
|
+
protected readonly redactedHeaders: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Set up the destinations and the level, and register the logger to flush its pending lines when the process exits.
|
|
103
|
+
* @protected
|
|
104
|
+
*/
|
|
105
|
+
protected init(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Write the pending lines and stop flushing at the process exit.
|
|
108
|
+
* @protected
|
|
109
|
+
*/
|
|
110
|
+
protected destroy(): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Build a log line and write it to every destination, unless its level is below the configured `level`.
|
|
113
|
+
* @param level The numeric level of the line: 10 trace, 20 debug, 30 info, 40 warn, 50 error, 60 fatal.
|
|
114
|
+
* @param args The arguments of the log method: `[obj, msg, ...args]` or `[msg, ...args]`.
|
|
115
|
+
* @protected
|
|
116
|
+
*/
|
|
117
|
+
protected write(level: number, args: unknown[]): void;
|
|
118
|
+
/**
|
|
119
|
+
* Write the buffered lines now, synchronously for the streams with a file descriptor (before a `process.exit()`
|
|
120
|
+
* in a signal handler, for instance). Does nothing with `sync: true`.
|
|
121
|
+
*/
|
|
122
|
+
flush(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Log a fatal error (a failure the application cannot continue after, logged before it exits) at the `fatal`
|
|
125
|
+
* level (60), unless the configured `level` is `'silent'`. The line and the pending ones are written at once, as
|
|
126
|
+
* by {@link Logger.flush}.
|
|
127
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
128
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
129
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
130
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
131
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
132
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
133
|
+
*/
|
|
134
|
+
fatal<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
135
|
+
/**
|
|
136
|
+
* Log a fatal error (a failure the application cannot continue after, logged before it exits) at the `fatal`
|
|
137
|
+
* level (60), unless the configured `level` is `'silent'`. The line and the pending ones are written at once, as
|
|
138
|
+
* by {@link Logger.flush}.
|
|
139
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
140
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
141
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
142
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
143
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
144
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
145
|
+
*/
|
|
146
|
+
fatal(obj: unknown, msg?: string, ...args: any[]): void;
|
|
147
|
+
/**
|
|
148
|
+
* Log a fatal error (a failure the application cannot continue after, logged before it exits) at the `fatal`
|
|
149
|
+
* level (60), unless the configured `level` is `'silent'`. The line and the pending ones are written at once, as
|
|
150
|
+
* by {@link Logger.flush}.
|
|
151
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
152
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
153
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
154
|
+
*/
|
|
155
|
+
fatal(msg: string, ...args: any[]): void;
|
|
156
|
+
/**
|
|
157
|
+
* Log an error (a failure the application needs to act on) at the `error` level (50), unless the configured `level` is higher.
|
|
158
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
159
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
160
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
161
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
162
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
163
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
164
|
+
*/
|
|
165
|
+
error<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
166
|
+
/**
|
|
167
|
+
* Log an error (a failure the application needs to act on) at the `error` level (50), unless the configured `level` is higher.
|
|
168
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
169
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
170
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
171
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
172
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
173
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
174
|
+
*/
|
|
175
|
+
error(obj: unknown, msg?: string, ...args: any[]): void;
|
|
176
|
+
/**
|
|
177
|
+
* Log an error (a failure the application needs to act on) at the `error` level (50), unless the configured `level` is higher.
|
|
178
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
179
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
180
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
181
|
+
*/
|
|
182
|
+
error(msg: string, ...args: any[]): void;
|
|
183
|
+
/**
|
|
184
|
+
* Log a warning (an unexpected event the application recovers from) at the `warn` level (40), unless the configured `level` is higher.
|
|
185
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
186
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
187
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
188
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
189
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
190
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
191
|
+
*/
|
|
192
|
+
warn<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
193
|
+
/**
|
|
194
|
+
* Log a warning (an unexpected event the application recovers from) at the `warn` level (40), unless the configured `level` is higher.
|
|
195
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
196
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
197
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
198
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
199
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
200
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
201
|
+
*/
|
|
202
|
+
warn(obj: unknown, msg?: string, ...args: any[]): void;
|
|
203
|
+
/**
|
|
204
|
+
* Log a warning (an unexpected event the application recovers from) at the `warn` level (40), unless the configured `level` is higher.
|
|
205
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
206
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
207
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
208
|
+
*/
|
|
209
|
+
warn(msg: string, ...args: any[]): void;
|
|
210
|
+
/**
|
|
211
|
+
* Log an information (the normal course of the application) at the `info` level (30), unless the configured `level` is higher.
|
|
212
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
213
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
214
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
215
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
216
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
217
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
218
|
+
*/
|
|
219
|
+
info<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
220
|
+
/**
|
|
221
|
+
* Log an information (the normal course of the application) at the `info` level (30), unless the configured `level` is higher.
|
|
222
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
223
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
224
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
225
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
226
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
227
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
228
|
+
*/
|
|
229
|
+
info(obj: unknown, msg?: string, ...args: any[]): void;
|
|
230
|
+
/**
|
|
231
|
+
* Log an information (the normal course of the application) at the `info` level (30), unless the configured `level` is higher.
|
|
232
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
233
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
234
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
235
|
+
*/
|
|
236
|
+
info(msg: string, ...args: any[]): void;
|
|
237
|
+
/**
|
|
238
|
+
* Log a debugging detail at the `debug` level (20), unless the configured `level` is higher.
|
|
239
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
240
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
241
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
242
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
243
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
244
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
245
|
+
*/
|
|
246
|
+
debug<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
247
|
+
/**
|
|
248
|
+
* Log a debugging detail at the `debug` level (20), unless the configured `level` is higher.
|
|
249
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
250
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
251
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
252
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
253
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
254
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
255
|
+
*/
|
|
256
|
+
debug(obj: unknown, msg?: string, ...args: any[]): void;
|
|
257
|
+
/**
|
|
258
|
+
* Log a debugging detail at the `debug` level (20), unless the configured `level` is higher.
|
|
259
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
260
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
261
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
262
|
+
*/
|
|
263
|
+
debug(msg: string, ...args: any[]): void;
|
|
264
|
+
/**
|
|
265
|
+
* Log a tracing detail, finer than debug at the `trace` level (10), unless the configured `level` is higher.
|
|
266
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
267
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
268
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
269
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
270
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
271
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
272
|
+
*/
|
|
273
|
+
trace<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
274
|
+
/**
|
|
275
|
+
* Log a tracing detail, finer than debug at the `trace` level (10), unless the configured `level` is higher.
|
|
276
|
+
* @param obj The properties added to the line (`{orderId: 42}`). An `Error` is written under `err` (its type,
|
|
277
|
+
* message, stack, causes and own properties), its message becoming the message when `msg` is omitted; an HTTP
|
|
278
|
+
* request or response of `node:http` is written under `req` or `res`, its credential headers redacted.
|
|
279
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
280
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
281
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
282
|
+
*/
|
|
283
|
+
trace(obj: unknown, msg?: string, ...args: any[]): void;
|
|
284
|
+
/**
|
|
285
|
+
* Log a tracing detail, finer than debug at the `trace` level (10), unless the configured `level` is higher.
|
|
286
|
+
* @param msg The message, with printf-style placeholders replaced by `args`: `%s` (string), `%d` and `%f` (number),
|
|
287
|
+
* `%i` (integer), `%o`, `%O` and `%j` (JSON), `%%` (a percent sign).
|
|
288
|
+
* @param args The values of the placeholders of `msg`, in order; the values without a placeholder are dropped.
|
|
289
|
+
*/
|
|
290
|
+
trace(msg: string, ...args: any[]): void;
|
|
291
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A destination of the log lines, buffered unless synchronous
|
|
3
|
+
* The buffered lines are written in the next event loop iteration, and synchronously when the process exits
|
|
4
|
+
* The streams with a file descriptor (stdout, stderr, files) are written through it, so the lines stay in order
|
|
5
|
+
*/
|
|
6
|
+
export declare class Destination {
|
|
7
|
+
#private;
|
|
8
|
+
protected readonly stream: NodeJS.WritableStream;
|
|
9
|
+
protected readonly sync: boolean;
|
|
10
|
+
constructor(stream: NodeJS.WritableStream, sync: boolean);
|
|
11
|
+
/**
|
|
12
|
+
* The file descriptor of the stream, if it has one
|
|
13
|
+
* @protected
|
|
14
|
+
*/
|
|
15
|
+
protected get fd(): number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Write a text to the file descriptor, retrying when the descriptor is busy
|
|
18
|
+
* @param fd
|
|
19
|
+
* @param text
|
|
20
|
+
* @protected
|
|
21
|
+
*/
|
|
22
|
+
protected writeFd(fd: number, text: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Write a text
|
|
25
|
+
* @param text
|
|
26
|
+
*/
|
|
27
|
+
write(text: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Write a text to the stream, through its file descriptor if it has one
|
|
30
|
+
* @param text
|
|
31
|
+
* @protected
|
|
32
|
+
*/
|
|
33
|
+
protected output(text: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Write the buffered text
|
|
36
|
+
*/
|
|
37
|
+
flush(): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Palette } from './Colors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Format a JSON log line for humans:
|
|
4
|
+
* [time] LEVEL (name/pid): message, then the properties on their own lines
|
|
5
|
+
* @param line the JSON log line, without its line terminator
|
|
6
|
+
* @param palette
|
|
7
|
+
* @param parsed the parsed line, if it is known (the log is changed)
|
|
8
|
+
*/
|
|
9
|
+
export declare function pretty(line: string, palette: Palette, parsed?: Record<string, unknown>): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const LEVELS: Record<string, number>;
|
|
2
|
+
export type LogBindings = {
|
|
3
|
+
json: string;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export type LogRecord = {
|
|
7
|
+
line: string;
|
|
8
|
+
log?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The bindings of the log lines of an application: pid, hostname and name
|
|
12
|
+
* @param name
|
|
13
|
+
*/
|
|
14
|
+
export declare function logBindings(name: string): LogBindings;
|
|
15
|
+
/**
|
|
16
|
+
* Build a JSON log line from the arguments of a log method:
|
|
17
|
+
* an object (or error, HTTP request or response) with an optional message and its format arguments,
|
|
18
|
+
* or a message with its format arguments
|
|
19
|
+
* @param level
|
|
20
|
+
* @param bindings
|
|
21
|
+
* @param args
|
|
22
|
+
* @param parse whether to also build the parsed line
|
|
23
|
+
* @param redacted the lower-case names of the headers of an HTTP request or response written as [Redacted]
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildRecord(level: number, bindings: LogBindings, args: unknown[], parse?: boolean, redacted?: ReadonlySet<string>): LogRecord;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a value looks like an error
|
|
3
|
+
* @param value
|
|
4
|
+
*/
|
|
5
|
+
export declare function isErrorLike(value: any): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Serialize an error: type, message and stack (with the causes), aggregated errors and the other enumerable properties
|
|
8
|
+
* @param error
|
|
9
|
+
*/
|
|
10
|
+
export declare function serializeError(error: any): any;
|
|
11
|
+
/**
|
|
12
|
+
* The headers written as [Redacted] by default: the credentials of the requests and of the responses
|
|
13
|
+
*/
|
|
14
|
+
export declare const REDACTED_HEADERS: readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Serialize an HTTP request
|
|
17
|
+
* @param request
|
|
18
|
+
* @param redacted the lower-case names of the headers written as [Redacted]
|
|
19
|
+
*/
|
|
20
|
+
export declare function serializeRequest(request: any, redacted?: ReadonlySet<string>): Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Serialize an HTTP response
|
|
23
|
+
* @param response
|
|
24
|
+
* @param redacted the lower-case names of the headers written as [Redacted]
|
|
25
|
+
*/
|
|
26
|
+
export declare function serializeResponse(response: any, redacted?: ReadonlySet<string>): Record<string, unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/logger",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
|
+
"description": "The logger component of the lakutata framework.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/exports/Logger.js",
|
|
7
|
+
"types": "./dist/cjs/exports/Logger.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/types/exports/Logger.d.ts",
|
|
12
|
+
"default": "./dist/esm/exports/Logger.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/cjs/exports/Logger.d.ts",
|
|
16
|
+
"default": "./dist/cjs/exports/Logger.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', {recursive: true, force: true})\"",
|
|
23
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
24
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
25
|
+
"build:cjs-pkg": "node ../../scripts/package-build/cjs-package.mjs",
|
|
26
|
+
"build:js": "npm run build:cjs && npm run build:esm && npm run build:cjs-pkg",
|
|
27
|
+
"rebuild": "npm run clean && npm run build:js",
|
|
28
|
+
"compile": "npm run rebuild",
|
|
29
|
+
"test:unit": "npm run compile && node --test \"dist/esm/tests/*.spec.js\""
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@lakutata/core": "3.0.0-beta.1"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"!dist/*/tests",
|
|
40
|
+
"*.md",
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"package.json",
|
|
43
|
+
"THIRD_PARTY_NOTICES.md"
|
|
44
|
+
]
|
|
45
|
+
}
|