@decaf-ts/logging 0.10.4 → 0.10.6
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.md +1 -1
- package/dist/logging.cjs +1 -1
- package/dist/logging.cjs.map +1 -1
- package/dist/logging.js +1 -1
- package/dist/logging.js.map +1 -1
- package/lib/constants.cjs +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/logging.d.ts +40 -22
- package/lib/esm/logging.js +88 -41
- package/lib/esm/logging.js.map +1 -1
- package/lib/esm/pino/pino.d.ts +3 -3
- package/lib/esm/pino/pino.js +7 -9
- package/lib/esm/pino/pino.js.map +1 -1
- package/lib/esm/types.d.ts +10 -8
- package/lib/esm/winston/winston.d.ts +2 -2
- package/lib/esm/winston/winston.js +2 -2
- package/lib/esm/winston/winston.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/logging.cjs +88 -41
- package/lib/logging.d.ts +40 -22
- package/lib/logging.js.map +1 -1
- package/lib/pino/pino.cjs +7 -9
- package/lib/pino/pino.d.ts +3 -3
- package/lib/pino/pino.js.map +1 -1
- package/lib/types.d.ts +10 -8
- package/lib/winston/winston.cjs +2 -2
- package/lib/winston/winston.d.ts +2 -2
- package/lib/winston/winston.js.map +1 -1
- package/package.json +1 -1
package/lib/esm/types.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { LoggingMode, LogLevel } from "./constants";
|
|
|
9
9
|
export type StringLike = string | {
|
|
10
10
|
toString: () => string;
|
|
11
11
|
};
|
|
12
|
+
export type LogMeta = Record<string, unknown>;
|
|
12
13
|
/**
|
|
13
14
|
* @description A generic function signature for loosely typed callbacks.
|
|
14
15
|
* @summary This type covers variadic functions where the arguments and return types are not constrained, which enables the logging layer to accept any callable.
|
|
@@ -69,21 +70,21 @@ export interface Logger extends Impersonatable<Logger, [
|
|
|
69
70
|
* @param {StringLike} msg - Message or payload to emit.
|
|
70
71
|
* @return {void}
|
|
71
72
|
*/
|
|
72
|
-
benchmark(msg: StringLike): void;
|
|
73
|
+
benchmark(msg: StringLike, meta?: LogMeta): void;
|
|
73
74
|
/**
|
|
74
75
|
* @description Logs a `way too verbose` or a silly message.
|
|
75
76
|
* @summary Emits playful or extremely verbose details at the `silly` log level.
|
|
76
77
|
* @param {StringLike} msg - Message or payload to emit.
|
|
77
78
|
* @return {void}
|
|
78
79
|
*/
|
|
79
|
-
silly(msg: StringLike): void;
|
|
80
|
+
silly(msg: StringLike, verbosity?: number | LogMeta, meta?: LogMeta): void;
|
|
80
81
|
/**
|
|
81
82
|
* @description Logs developer trace messages.
|
|
82
83
|
* @summary Emits playful or extremely verbose details at the `silly` log level.
|
|
83
84
|
* @param {StringLike} msg - Message or payload to emit.
|
|
84
85
|
* @return {void}
|
|
85
86
|
*/
|
|
86
|
-
trace(msg: StringLike): void;
|
|
87
|
+
trace(msg: StringLike, meta?: LogMeta): void;
|
|
87
88
|
/**
|
|
88
89
|
* @description Logs a verbose message.
|
|
89
90
|
* @summary Writes diagnostic output governed by the configured verbosity threshold.
|
|
@@ -91,14 +92,14 @@ export interface Logger extends Impersonatable<Logger, [
|
|
|
91
92
|
* @param {number} [verbosity] - Verbosity level required for the message to pass through.
|
|
92
93
|
* @return {void}
|
|
93
94
|
*/
|
|
94
|
-
verbose(msg: StringLike,
|
|
95
|
+
verbose(msg: StringLike, verbosityOrMeta?: number | LogMeta, meta?: LogMeta): void;
|
|
95
96
|
/**
|
|
96
97
|
* @description Logs an info message.
|
|
97
98
|
* @summary Emits general informational events that describe application progress.
|
|
98
99
|
* @param {StringLike} msg - Message or payload to emit.
|
|
99
100
|
* @return {void}
|
|
100
101
|
*/
|
|
101
|
-
info(msg: StringLike): void;
|
|
102
|
+
info(msg: StringLike, meta?: LogMeta): void;
|
|
102
103
|
/**
|
|
103
104
|
* @description Logs an error message.
|
|
104
105
|
* @summary Records errors and exceptions, including optional stack traces.
|
|
@@ -106,21 +107,21 @@ export interface Logger extends Impersonatable<Logger, [
|
|
|
106
107
|
* @param {Error} [e] - Optional secondary error or cause.
|
|
107
108
|
* @return {void}
|
|
108
109
|
*/
|
|
109
|
-
error(msg: StringLike | Error,
|
|
110
|
+
error(msg: StringLike | Error, error?: Error | LogMeta, meta?: LogMeta): void;
|
|
110
111
|
/**
|
|
111
112
|
* @description Logs a debug message.
|
|
112
113
|
* @summary Emits fine-grained diagnostic details useful during development and troubleshooting.
|
|
113
114
|
* @param {StringLike} msg - Message or payload to emit.
|
|
114
115
|
* @return {void}
|
|
115
116
|
*/
|
|
116
|
-
debug(msg: StringLike): void;
|
|
117
|
+
debug(msg: StringLike, meta?: LogMeta): void;
|
|
117
118
|
/**
|
|
118
119
|
* @description Logs a debug message.
|
|
119
120
|
* @summary Emits fine-grained diagnostic details useful during development and troubleshooting.
|
|
120
121
|
* @param {StringLike} msg - Message or payload to emit.
|
|
121
122
|
* @return {void}
|
|
122
123
|
*/
|
|
123
|
-
warn(msg: StringLike): void;
|
|
124
|
+
warn(msg: StringLike, meta?: LogMeta): void;
|
|
124
125
|
/**
|
|
125
126
|
* @description Creates a new logger for a specific method or context.
|
|
126
127
|
* @summary Produces a scoped logger that formats entries using the derived context and overrides supplied configuration.
|
|
@@ -206,6 +207,7 @@ export type LoggingConfig<TRANSPORT = object> = {
|
|
|
206
207
|
timestamp?: boolean;
|
|
207
208
|
timestampFormat?: string;
|
|
208
209
|
context?: boolean;
|
|
210
|
+
meta?: boolean;
|
|
209
211
|
theme?: Theme;
|
|
210
212
|
format: LoggingMode;
|
|
211
213
|
pattern: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import winston from "winston";
|
|
2
|
-
import { Logger, LoggerFactory, LoggingConfig, StringLike } from "../types";
|
|
2
|
+
import { Logger, LoggerFactory, LogMeta, LoggingConfig, StringLike } from "../types";
|
|
3
3
|
import { MiniLogger } from "../logging";
|
|
4
4
|
import { LogLevel } from "../constants";
|
|
5
5
|
/**
|
|
@@ -32,7 +32,7 @@ export declare class WinstonLogger extends MiniLogger implements Logger {
|
|
|
32
32
|
* @param {Error} [error] - An optional stack trace to include in the log.
|
|
33
33
|
* @return {void}
|
|
34
34
|
*/
|
|
35
|
-
protected log(level: LogLevel, msg: StringLike | Error, error?: Error): void;
|
|
35
|
+
protected log(level: LogLevel, msg: StringLike | Error, error?: Error, meta?: LogMeta): void;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* @description A factory function for creating Winston loggers.
|
|
@@ -44,10 +44,10 @@ export class WinstonLogger extends MiniLogger {
|
|
|
44
44
|
* @param {Error} [error] - An optional stack trace to include in the log.
|
|
45
45
|
* @return {void}
|
|
46
46
|
*/
|
|
47
|
-
log(level, msg, error) {
|
|
47
|
+
log(level, msg, error, meta) {
|
|
48
48
|
const logData = {
|
|
49
49
|
level: level,
|
|
50
|
-
message: this.createLog(level, msg, error),
|
|
50
|
+
message: this.createLog(level, msg, error, meta),
|
|
51
51
|
};
|
|
52
52
|
if (this.config("correlationId"))
|
|
53
53
|
logData["correlationId"] = this.config("correlationId");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.js","sourceRoot":"","sources":["../../../src/winston/winston.ts"],"names":[],"mappings":"AAAA,OAAO,OAAoC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"winston.js","sourceRoot":"","sources":["../../../src/winston/winston.ts"],"names":[],"mappings":"AAAA,OAAO,OAAoC,MAAM,SAAS,CAAC;AAS3D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,wBAAmB;AAGjD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAG3C,YAAY,IAAa,EAAE,IAA6B;QACtD,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B,EAAE,EACF,OAAO,CAAC,SAAS,EAAE,EACnB,IAAI,CAAC,IAAI,IAAI,EAAE,CACY,CAAC;QAE9B,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,CACtC,MAAM,CAAC,UAAsC,IAAI,SAAS,CAC5D,CAAC;QACF,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACxD,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAChE,CAAC;QAEF,MAAM,aAAa,GAAkB;YACnC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,UAAU;YACV,MAAM,EAAE,WAAW;SACpB,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;IAEO,iBAAiB,CAAC,UAAwB;QAChD,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM;YAAE,OAAO,UAAU,CAAC;QACvD,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACgB,GAAG,CACpB,KAAe,EACf,GAAuB,EACvB,KAAa,EACb,IAAc;QAEd,MAAM,OAAO,GAAa;YACxB,KAAK,EAAE,KAAK;YACZ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC;SACjD,CAAC;QACF,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC9B,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkB,CAC3C,OAAgB,EAChB,IAA6B;AAC7B,6DAA6D;AAC7D,GAAG,KAAY,EACA,EAAE,CAAC,IAAI,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC"}
|
package/lib/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ __exportStar(require("styled-string-builder"), exports);
|
|
|
39
39
|
* @type {string}
|
|
40
40
|
* @memberOf module:Logging
|
|
41
41
|
*/
|
|
42
|
-
exports.VERSION = "0.10.
|
|
42
|
+
exports.VERSION = "0.10.5";
|
|
43
43
|
/**
|
|
44
44
|
* @description Current package version string.
|
|
45
45
|
* @summary Stores the package version for diagnostics and compatibility checks.
|
package/lib/logging.cjs
CHANGED
|
@@ -145,7 +145,7 @@ class MiniLogger {
|
|
|
145
145
|
* @param {Error} [error] - Optional error to extract stack trace to include in the log.
|
|
146
146
|
* @return {string} A formatted log string with all components.
|
|
147
147
|
*/
|
|
148
|
-
createLog(level, message, error) {
|
|
148
|
+
createLog(level, message, error, meta) {
|
|
149
149
|
const log = {};
|
|
150
150
|
const style = this.config("style");
|
|
151
151
|
const separator = this.config("separator");
|
|
@@ -193,6 +193,12 @@ class MiniLogger {
|
|
|
193
193
|
? message
|
|
194
194
|
: message.message;
|
|
195
195
|
log.message = msg;
|
|
196
|
+
const showMeta = Boolean(this.config("meta"));
|
|
197
|
+
const metaPayload = showMeta && meta ? meta : undefined;
|
|
198
|
+
const metaString = metaPayload ? this.formatMeta(metaPayload) : undefined;
|
|
199
|
+
if (metaPayload) {
|
|
200
|
+
log.meta = metaPayload;
|
|
201
|
+
}
|
|
196
202
|
if (error || message instanceof Error) {
|
|
197
203
|
const stack = style
|
|
198
204
|
? Logging.theme((error?.stack || message.stack), "stack", level)
|
|
@@ -202,8 +208,8 @@ class MiniLogger {
|
|
|
202
208
|
switch (this.config("format")) {
|
|
203
209
|
case "json":
|
|
204
210
|
return JSON.stringify(log);
|
|
205
|
-
case "raw":
|
|
206
|
-
|
|
211
|
+
case "raw": {
|
|
212
|
+
const generated = this.config("pattern")
|
|
207
213
|
.split(" ")
|
|
208
214
|
.map((s) => {
|
|
209
215
|
if (!s.match(/\{.*?}/g))
|
|
@@ -215,10 +221,21 @@ class MiniLogger {
|
|
|
215
221
|
})
|
|
216
222
|
.filter((s) => s)
|
|
217
223
|
.join(" ");
|
|
224
|
+
return metaString ? `${generated} ${metaString}` : generated;
|
|
225
|
+
}
|
|
218
226
|
default:
|
|
219
227
|
throw new Error(`Unsupported logging format: ${this.config("format")}`);
|
|
220
228
|
}
|
|
221
229
|
}
|
|
230
|
+
formatMeta(meta) {
|
|
231
|
+
try {
|
|
232
|
+
return JSON.stringify(meta);
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
return String(meta);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
222
239
|
/**
|
|
223
240
|
* @description Logs a message with the specified log level.
|
|
224
241
|
* @summary Checks if the message should be logged based on the current log level, then uses the appropriate console method to output the formatted log.
|
|
@@ -227,7 +244,7 @@ class MiniLogger {
|
|
|
227
244
|
* @param {Error} [error] - Optional stack trace to include in the log.
|
|
228
245
|
* @return {void}
|
|
229
246
|
*/
|
|
230
|
-
log(level, msg, error) {
|
|
247
|
+
log(level, msg, error, meta) {
|
|
231
248
|
const confLvl = this.config("level");
|
|
232
249
|
if (constants_1.NumericLogLevels[confLvl] < constants_1.NumericLogLevels[level])
|
|
233
250
|
return;
|
|
@@ -237,9 +254,9 @@ class MiniLogger {
|
|
|
237
254
|
method = console.log;
|
|
238
255
|
break;
|
|
239
256
|
case constants_1.LogLevel.info:
|
|
257
|
+
case constants_1.LogLevel.verbose:
|
|
240
258
|
method = console.log;
|
|
241
259
|
break;
|
|
242
|
-
case constants_1.LogLevel.verbose:
|
|
243
260
|
case constants_1.LogLevel.debug:
|
|
244
261
|
method = console.debug;
|
|
245
262
|
break;
|
|
@@ -258,84 +275,105 @@ class MiniLogger {
|
|
|
258
275
|
default:
|
|
259
276
|
throw new Error("Invalid log level");
|
|
260
277
|
}
|
|
261
|
-
method(this.createLog(level, msg, error));
|
|
278
|
+
method(this.createLog(level, msg, error, meta));
|
|
262
279
|
}
|
|
263
280
|
/**
|
|
264
281
|
* @description Logs a message at the benchmark level.
|
|
265
282
|
* @summary Logs a message at the benchmark level if the current verbosity setting allows it.
|
|
266
283
|
* @param {StringLike} msg - The message to be logged.
|
|
284
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
267
285
|
* @return {void}
|
|
268
286
|
*/
|
|
269
|
-
benchmark(msg) {
|
|
270
|
-
this.log(constants_1.LogLevel.benchmark, msg);
|
|
287
|
+
benchmark(msg, meta) {
|
|
288
|
+
this.log(constants_1.LogLevel.benchmark, msg, undefined, meta);
|
|
271
289
|
}
|
|
272
290
|
/**
|
|
273
291
|
* @description Logs a message at the silly level.
|
|
274
292
|
* @summary Logs a message at the silly level if the current verbosity setting allows it.
|
|
275
293
|
* @param {StringLike} msg - The message to be logged.
|
|
276
294
|
* @param {number} [verbosity=0] - The verbosity level of the message.
|
|
295
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
277
296
|
* @return {void}
|
|
278
297
|
*/
|
|
279
|
-
silly(msg,
|
|
298
|
+
silly(msg, verbosityOrMeta = 0, meta) {
|
|
299
|
+
const verbosity = typeof verbosityOrMeta === "number" ? verbosityOrMeta : 0;
|
|
300
|
+
const payloadMeta = typeof verbosityOrMeta === "number" ? meta : verbosityOrMeta;
|
|
280
301
|
if (this.config("verbose") >= verbosity)
|
|
281
|
-
this.log(constants_1.LogLevel.silly, msg);
|
|
302
|
+
this.log(constants_1.LogLevel.silly, msg, undefined, payloadMeta);
|
|
282
303
|
}
|
|
283
304
|
/**
|
|
284
305
|
* @description Logs a message at the verbose level.
|
|
285
306
|
* @summary Logs a message at the verbose level if the current verbosity setting allows it.
|
|
286
307
|
* @param {StringLike} msg - The message to be logged.
|
|
287
308
|
* @param {number} [verbosity=0] - The verbosity level of the message.
|
|
309
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
288
310
|
* @return {void}
|
|
289
311
|
*/
|
|
290
|
-
verbose(msg,
|
|
312
|
+
verbose(msg, verbosityOrMeta = 0, meta) {
|
|
313
|
+
const verbosity = typeof verbosityOrMeta === "number" ? verbosityOrMeta : 0;
|
|
314
|
+
const payloadMeta = typeof verbosityOrMeta === "number" ? meta : verbosityOrMeta;
|
|
291
315
|
if (this.config("verbose") >= verbosity)
|
|
292
|
-
this.log(constants_1.LogLevel.verbose, msg);
|
|
316
|
+
this.log(constants_1.LogLevel.verbose, msg, undefined, payloadMeta);
|
|
293
317
|
}
|
|
294
318
|
/**
|
|
295
319
|
* @description Logs a message at the info level.
|
|
296
320
|
* @summary Logs a message at the info level for general application information.
|
|
297
321
|
* @param {StringLike} msg - The message to be logged.
|
|
322
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
298
323
|
* @return {void}
|
|
299
324
|
*/
|
|
300
|
-
info(msg) {
|
|
301
|
-
this.log(constants_1.LogLevel.info, msg);
|
|
325
|
+
info(msg, meta) {
|
|
326
|
+
this.log(constants_1.LogLevel.info, msg, undefined, meta);
|
|
302
327
|
}
|
|
303
328
|
/**
|
|
304
329
|
* @description Logs a message at the debug level.
|
|
305
330
|
* @summary Logs a message at the debug level for detailed troubleshooting information.
|
|
306
331
|
* @param {StringLike} msg - The message to be logged.
|
|
332
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
307
333
|
* @return {void}
|
|
308
334
|
*/
|
|
309
|
-
debug(msg) {
|
|
310
|
-
this.log(constants_1.LogLevel.debug, msg);
|
|
335
|
+
debug(msg, meta) {
|
|
336
|
+
this.log(constants_1.LogLevel.debug, msg, undefined, meta);
|
|
311
337
|
}
|
|
312
338
|
/**
|
|
313
339
|
* @description Logs a message at the error level.
|
|
314
340
|
* @summary Logs a message at the error level for errors and exceptions.
|
|
315
341
|
* @param {StringLike | Error} msg - The message to be logged or an Error object.
|
|
316
|
-
* @param {Error} [e] - Optional error to include in the log.
|
|
342
|
+
* @param {Error|object} [e] - Optional error or metadata to include in the log.
|
|
343
|
+
* @param {object} [meta] - Optional metadata to include with the entry when an error is supplied.
|
|
317
344
|
* @return {void}
|
|
318
345
|
*/
|
|
319
|
-
error(msg, e) {
|
|
320
|
-
|
|
346
|
+
error(msg, e, meta) {
|
|
347
|
+
let errorCandidate;
|
|
348
|
+
let payloadMeta;
|
|
349
|
+
if (e instanceof Error) {
|
|
350
|
+
errorCandidate = e;
|
|
351
|
+
payloadMeta = meta;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
payloadMeta = e;
|
|
355
|
+
}
|
|
356
|
+
this.log(constants_1.LogLevel.error, msg, errorCandidate, payloadMeta);
|
|
321
357
|
}
|
|
322
358
|
/**
|
|
323
359
|
* @description Logs a message at the warning level.
|
|
324
360
|
* @summary Logs a message at the warning level for potential issues.
|
|
325
361
|
* @param {StringLike} msg - The message to be logged.
|
|
362
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
326
363
|
* @return {void}
|
|
327
364
|
*/
|
|
328
|
-
warn(msg) {
|
|
329
|
-
this.log(constants_1.LogLevel.warn, msg);
|
|
365
|
+
warn(msg, meta) {
|
|
366
|
+
this.log(constants_1.LogLevel.warn, msg, undefined, meta);
|
|
330
367
|
}
|
|
331
368
|
/**
|
|
332
369
|
* @description Logs a message at the trace level.
|
|
333
370
|
* @summary Logs a message at the trace level for tracing code execution.
|
|
334
371
|
* @param {StringLike} msg - The message to be logged.
|
|
372
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
335
373
|
* @return {void}
|
|
336
374
|
*/
|
|
337
|
-
trace(msg) {
|
|
338
|
-
this.log(constants_1.LogLevel.trace, msg);
|
|
375
|
+
trace(msg, meta) {
|
|
376
|
+
this.log(constants_1.LogLevel.trace, msg, undefined, meta);
|
|
339
377
|
}
|
|
340
378
|
/**
|
|
341
379
|
* @description Updates the logger configuration.
|
|
@@ -477,75 +515,84 @@ class Logging {
|
|
|
477
515
|
* @description Logs a verbose message.
|
|
478
516
|
* @summary Delegates the verbose logging to the global logger instance.
|
|
479
517
|
* @param {StringLike} msg - The message to be logged.
|
|
480
|
-
* @param {number} [verbosity
|
|
518
|
+
* @param {number|object} [verbosity] - The verbosity level or metadata object.
|
|
519
|
+
* @param {object} [meta] - Optional metadata applied when a verbosity level is provided.
|
|
481
520
|
* @return {void}
|
|
482
521
|
*/
|
|
483
|
-
static verbose(msg,
|
|
484
|
-
return this.get().verbose(msg,
|
|
522
|
+
static verbose(msg, verbosityOrMeta = 0, meta) {
|
|
523
|
+
return this.get().verbose(msg, verbosityOrMeta, meta);
|
|
485
524
|
}
|
|
486
525
|
/**
|
|
487
526
|
* @description Logs an info message.
|
|
488
527
|
* @summary Delegates the info logging to the global logger instance.
|
|
489
528
|
* @param {StringLike} msg - The message to be logged.
|
|
529
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
490
530
|
* @return {void}
|
|
491
531
|
*/
|
|
492
|
-
static info(msg) {
|
|
493
|
-
return this.get().info(msg);
|
|
532
|
+
static info(msg, meta) {
|
|
533
|
+
return this.get().info(msg, meta);
|
|
494
534
|
}
|
|
495
535
|
/**
|
|
496
536
|
* @description Logs a trace message.
|
|
497
537
|
* @summary Delegates the trace logging to the global logger instance.
|
|
498
538
|
* @param {StringLike} msg - The message to be logged.
|
|
539
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
499
540
|
* @return {void}
|
|
500
541
|
*/
|
|
501
|
-
static trace(msg) {
|
|
502
|
-
return this.get().trace(msg);
|
|
542
|
+
static trace(msg, meta) {
|
|
543
|
+
return this.get().trace(msg, meta);
|
|
503
544
|
}
|
|
504
545
|
/**
|
|
505
546
|
* @description Logs a debug message.
|
|
506
547
|
* @summary Delegates the debug logging to the global logger instance.
|
|
507
548
|
* @param {StringLike} msg - The message to be logged.
|
|
549
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
508
550
|
* @return {void}
|
|
509
551
|
*/
|
|
510
|
-
static debug(msg) {
|
|
511
|
-
return this.get().debug(msg);
|
|
552
|
+
static debug(msg, meta) {
|
|
553
|
+
return this.get().debug(msg, meta);
|
|
512
554
|
}
|
|
513
555
|
/**
|
|
514
556
|
* @description Logs a benchmark message.
|
|
515
557
|
* @summary Delegates the benchmark logging to the global logger instance.
|
|
516
558
|
* @param {StringLike} msg - The message to be logged.
|
|
559
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
517
560
|
* @return {void}
|
|
518
561
|
*/
|
|
519
|
-
static benchmark(msg) {
|
|
520
|
-
return this.get().benchmark(msg);
|
|
562
|
+
static benchmark(msg, meta) {
|
|
563
|
+
return this.get().benchmark(msg, meta);
|
|
521
564
|
}
|
|
522
565
|
/**
|
|
523
566
|
* @description Logs a silly message.
|
|
524
567
|
* @summary Delegates the silly logging to the global logger instance.
|
|
525
568
|
* @param {StringLike} msg - The message to be logged.
|
|
569
|
+
* @param {number|object} [verbosity] - The verbosity level or metadata object.
|
|
570
|
+
* @param {object} [meta] - Optional metadata applied when a verbosity level is provided.
|
|
526
571
|
* @return {void}
|
|
527
572
|
*/
|
|
528
|
-
static silly(msg) {
|
|
529
|
-
return this.get().silly(msg);
|
|
573
|
+
static silly(msg, verbosityOrMeta = 0, meta) {
|
|
574
|
+
return this.get().silly(msg, verbosityOrMeta, meta);
|
|
530
575
|
}
|
|
531
576
|
/**
|
|
532
577
|
* @description Logs a warning message.
|
|
533
578
|
* @summary Delegates the warning logging to the global logger instance.
|
|
534
579
|
* @param {StringLike} msg - The message to be logged.
|
|
580
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
535
581
|
* @return {void}
|
|
536
582
|
*/
|
|
537
|
-
static warn(msg) {
|
|
538
|
-
return this.get().warn(msg);
|
|
583
|
+
static warn(msg, meta) {
|
|
584
|
+
return this.get().warn(msg, meta);
|
|
539
585
|
}
|
|
540
586
|
/**
|
|
541
587
|
* @description Logs an error message.
|
|
542
588
|
* @summary Delegates the error logging to the global logger instance.
|
|
543
589
|
* @param {StringLike | Error} msg - The message to be logged.
|
|
544
|
-
* @param {Error} [e] - Optional error to include in the log.
|
|
590
|
+
* @param {Error|object} [e] - Optional error or metadata to include in the log.
|
|
591
|
+
* @param {object} [meta] - Optional metadata to include with the entry when an error is supplied.
|
|
545
592
|
* @return {void}
|
|
546
593
|
*/
|
|
547
|
-
static error(msg, e) {
|
|
548
|
-
return this.get().error(msg, e);
|
|
594
|
+
static error(msg, e, meta) {
|
|
595
|
+
return this.get().error(msg, e, meta);
|
|
549
596
|
}
|
|
550
597
|
/**
|
|
551
598
|
* @description Creates a logger for a specific object or context.
|
package/lib/logging.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoggerFactory, LoggingConfig, LoggingContext, StringLike, Theme, Logger } from "./types";
|
|
1
|
+
import { LoggerFactory, LoggingConfig, LoggingContext, LogMeta, StringLike, Theme, Logger } from "./types";
|
|
2
2
|
import { LogLevel } from "./constants";
|
|
3
3
|
import { LoggedEnvironment } from "./environment";
|
|
4
4
|
export declare const ROOT_CONTEXT_SYMBOL: unique symbol;
|
|
@@ -46,7 +46,8 @@ export declare class MiniLogger implements Logger {
|
|
|
46
46
|
* @param {Error} [error] - Optional error to extract stack trace to include in the log.
|
|
47
47
|
* @return {string} A formatted log string with all components.
|
|
48
48
|
*/
|
|
49
|
-
protected createLog(level: LogLevel, message: StringLike | Error, error?: Error): string;
|
|
49
|
+
protected createLog(level: LogLevel, message: StringLike | Error, error?: Error, meta?: LogMeta): string;
|
|
50
|
+
private formatMeta;
|
|
50
51
|
/**
|
|
51
52
|
* @description Logs a message with the specified log level.
|
|
52
53
|
* @summary Checks if the message should be logged based on the current log level, then uses the appropriate console method to output the formatted log.
|
|
@@ -55,66 +56,74 @@ export declare class MiniLogger implements Logger {
|
|
|
55
56
|
* @param {Error} [error] - Optional stack trace to include in the log.
|
|
56
57
|
* @return {void}
|
|
57
58
|
*/
|
|
58
|
-
protected log(level: LogLevel, msg: StringLike | Error, error?: Error): void;
|
|
59
|
+
protected log(level: LogLevel, msg: StringLike | Error, error?: Error, meta?: LogMeta): void;
|
|
59
60
|
/**
|
|
60
61
|
* @description Logs a message at the benchmark level.
|
|
61
62
|
* @summary Logs a message at the benchmark level if the current verbosity setting allows it.
|
|
62
63
|
* @param {StringLike} msg - The message to be logged.
|
|
64
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
63
65
|
* @return {void}
|
|
64
66
|
*/
|
|
65
|
-
benchmark(msg: StringLike): void;
|
|
67
|
+
benchmark(msg: StringLike, meta?: LogMeta): void;
|
|
66
68
|
/**
|
|
67
69
|
* @description Logs a message at the silly level.
|
|
68
70
|
* @summary Logs a message at the silly level if the current verbosity setting allows it.
|
|
69
71
|
* @param {StringLike} msg - The message to be logged.
|
|
70
72
|
* @param {number} [verbosity=0] - The verbosity level of the message.
|
|
73
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
71
74
|
* @return {void}
|
|
72
75
|
*/
|
|
73
|
-
silly(msg: StringLike,
|
|
76
|
+
silly(msg: StringLike, verbosityOrMeta?: number | LogMeta, meta?: LogMeta): void;
|
|
74
77
|
/**
|
|
75
78
|
* @description Logs a message at the verbose level.
|
|
76
79
|
* @summary Logs a message at the verbose level if the current verbosity setting allows it.
|
|
77
80
|
* @param {StringLike} msg - The message to be logged.
|
|
78
81
|
* @param {number} [verbosity=0] - The verbosity level of the message.
|
|
82
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
79
83
|
* @return {void}
|
|
80
84
|
*/
|
|
81
|
-
verbose(msg: StringLike,
|
|
85
|
+
verbose(msg: StringLike, verbosityOrMeta?: number | LogMeta, meta?: LogMeta): void;
|
|
82
86
|
/**
|
|
83
87
|
* @description Logs a message at the info level.
|
|
84
88
|
* @summary Logs a message at the info level for general application information.
|
|
85
89
|
* @param {StringLike} msg - The message to be logged.
|
|
90
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
86
91
|
* @return {void}
|
|
87
92
|
*/
|
|
88
|
-
info(msg: StringLike): void;
|
|
93
|
+
info(msg: StringLike, meta?: LogMeta): void;
|
|
89
94
|
/**
|
|
90
95
|
* @description Logs a message at the debug level.
|
|
91
96
|
* @summary Logs a message at the debug level for detailed troubleshooting information.
|
|
92
97
|
* @param {StringLike} msg - The message to be logged.
|
|
98
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
93
99
|
* @return {void}
|
|
94
100
|
*/
|
|
95
|
-
debug(msg: StringLike): void;
|
|
101
|
+
debug(msg: StringLike, meta?: LogMeta): void;
|
|
96
102
|
/**
|
|
97
103
|
* @description Logs a message at the error level.
|
|
98
104
|
* @summary Logs a message at the error level for errors and exceptions.
|
|
99
105
|
* @param {StringLike | Error} msg - The message to be logged or an Error object.
|
|
100
|
-
* @param {Error} [e] - Optional error to include in the log.
|
|
106
|
+
* @param {Error|object} [e] - Optional error or metadata to include in the log.
|
|
107
|
+
* @param {object} [meta] - Optional metadata to include with the entry when an error is supplied.
|
|
101
108
|
* @return {void}
|
|
102
109
|
*/
|
|
103
|
-
error(msg: StringLike | Error, e?: Error): void;
|
|
110
|
+
error(msg: StringLike | Error, e?: Error | LogMeta, meta?: LogMeta): void;
|
|
104
111
|
/**
|
|
105
112
|
* @description Logs a message at the warning level.
|
|
106
113
|
* @summary Logs a message at the warning level for potential issues.
|
|
107
114
|
* @param {StringLike} msg - The message to be logged.
|
|
115
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
108
116
|
* @return {void}
|
|
109
117
|
*/
|
|
110
|
-
warn(msg: StringLike): void;
|
|
118
|
+
warn(msg: StringLike, meta?: LogMeta): void;
|
|
111
119
|
/**
|
|
112
120
|
* @description Logs a message at the trace level.
|
|
113
121
|
* @summary Logs a message at the trace level for tracing code execution.
|
|
114
122
|
* @param {StringLike} msg - The message to be logged.
|
|
123
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
115
124
|
* @return {void}
|
|
116
125
|
*/
|
|
117
|
-
trace(msg: StringLike): void;
|
|
126
|
+
trace(msg: StringLike, meta?: LogMeta): void;
|
|
118
127
|
/**
|
|
119
128
|
* @description Updates the logger configuration.
|
|
120
129
|
* @summary Merges the provided configuration with the existing configuration.
|
|
@@ -236,60 +245,69 @@ export declare class Logging {
|
|
|
236
245
|
* @description Logs a verbose message.
|
|
237
246
|
* @summary Delegates the verbose logging to the global logger instance.
|
|
238
247
|
* @param {StringLike} msg - The message to be logged.
|
|
239
|
-
* @param {number} [verbosity
|
|
248
|
+
* @param {number|object} [verbosity] - The verbosity level or metadata object.
|
|
249
|
+
* @param {object} [meta] - Optional metadata applied when a verbosity level is provided.
|
|
240
250
|
* @return {void}
|
|
241
251
|
*/
|
|
242
|
-
static verbose(msg: StringLike,
|
|
252
|
+
static verbose(msg: StringLike, verbosityOrMeta?: number | LogMeta, meta?: LogMeta): void;
|
|
243
253
|
/**
|
|
244
254
|
* @description Logs an info message.
|
|
245
255
|
* @summary Delegates the info logging to the global logger instance.
|
|
246
256
|
* @param {StringLike} msg - The message to be logged.
|
|
257
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
247
258
|
* @return {void}
|
|
248
259
|
*/
|
|
249
|
-
static info(msg: StringLike): void;
|
|
260
|
+
static info(msg: StringLike, meta?: LogMeta): void;
|
|
250
261
|
/**
|
|
251
262
|
* @description Logs a trace message.
|
|
252
263
|
* @summary Delegates the trace logging to the global logger instance.
|
|
253
264
|
* @param {StringLike} msg - The message to be logged.
|
|
265
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
254
266
|
* @return {void}
|
|
255
267
|
*/
|
|
256
|
-
static trace(msg: StringLike): void;
|
|
268
|
+
static trace(msg: StringLike, meta?: LogMeta): void;
|
|
257
269
|
/**
|
|
258
270
|
* @description Logs a debug message.
|
|
259
271
|
* @summary Delegates the debug logging to the global logger instance.
|
|
260
272
|
* @param {StringLike} msg - The message to be logged.
|
|
273
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
261
274
|
* @return {void}
|
|
262
275
|
*/
|
|
263
|
-
static debug(msg: StringLike): void;
|
|
276
|
+
static debug(msg: StringLike, meta?: LogMeta): void;
|
|
264
277
|
/**
|
|
265
278
|
* @description Logs a benchmark message.
|
|
266
279
|
* @summary Delegates the benchmark logging to the global logger instance.
|
|
267
280
|
* @param {StringLike} msg - The message to be logged.
|
|
281
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
268
282
|
* @return {void}
|
|
269
283
|
*/
|
|
270
|
-
static benchmark(msg: StringLike): void;
|
|
284
|
+
static benchmark(msg: StringLike, meta?: LogMeta): void;
|
|
271
285
|
/**
|
|
272
286
|
* @description Logs a silly message.
|
|
273
287
|
* @summary Delegates the silly logging to the global logger instance.
|
|
274
288
|
* @param {StringLike} msg - The message to be logged.
|
|
289
|
+
* @param {number|object} [verbosity] - The verbosity level or metadata object.
|
|
290
|
+
* @param {object} [meta] - Optional metadata applied when a verbosity level is provided.
|
|
275
291
|
* @return {void}
|
|
276
292
|
*/
|
|
277
|
-
static silly(msg: StringLike): void;
|
|
293
|
+
static silly(msg: StringLike, verbosityOrMeta?: number | LogMeta, meta?: LogMeta): void;
|
|
278
294
|
/**
|
|
279
295
|
* @description Logs a warning message.
|
|
280
296
|
* @summary Delegates the warning logging to the global logger instance.
|
|
281
297
|
* @param {StringLike} msg - The message to be logged.
|
|
298
|
+
* @param {object} [meta] - Optional metadata to include with the entry.
|
|
282
299
|
* @return {void}
|
|
283
300
|
*/
|
|
284
|
-
static warn(msg: StringLike): void;
|
|
301
|
+
static warn(msg: StringLike, meta?: LogMeta): void;
|
|
285
302
|
/**
|
|
286
303
|
* @description Logs an error message.
|
|
287
304
|
* @summary Delegates the error logging to the global logger instance.
|
|
288
305
|
* @param {StringLike | Error} msg - The message to be logged.
|
|
289
|
-
* @param {Error} [e] - Optional error to include in the log.
|
|
306
|
+
* @param {Error|object} [e] - Optional error or metadata to include in the log.
|
|
307
|
+
* @param {object} [meta] - Optional metadata to include with the entry when an error is supplied.
|
|
290
308
|
* @return {void}
|
|
291
309
|
*/
|
|
292
|
-
static error(msg: StringLike | Error, e?: Error): void;
|
|
310
|
+
static error(msg: StringLike | Error, e?: Error | LogMeta, meta?: LogMeta): void;
|
|
293
311
|
/**
|
|
294
312
|
* @description Creates a logger for a specific object or context.
|
|
295
313
|
* @summary Creates a new logger instance for the given object or context using the factory function.
|