@darksheep/logger 1.0.6 โ 1.0.8
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/CHANGELOG.md +22 -0
- package/package.json +5 -7
- package/src/create-logger.js +1 -1
- package/src/formatters/formatter-console.js +22 -22
- package/src/formatters/formatter-json.js +1 -1
- package/src/logger.js +70 -66
- package/src/replacer.js +9 -8
- package/src/replacers/buffers.js +1 -1
- package/src/replacers/error.js +4 -8
- package/src/stdout-write.js +1 -1
- package/src/utilities/colour.js +20 -20
- package/src/utilities/environment.js +1 -1
- package/src/utilities/json-path.js +4 -4
- package/src/utilities/last-callsite.js +1 -1
- package/src/utilities/log-filters.js +4 -4
- package/src/utilities/log-types.js +14 -14
- package/src/utilities/parse-filters.js +15 -10
- package/src/utilities/parse-log-level.js +13 -13
- package/src/utilities/stacktrace.js +8 -8
- package/types/assert.zod.d.ts +4 -4
- package/types/create-logger.d.ts +1 -1
- package/types/formatters/formatter-console.d.ts +1 -1
- package/types/formatters/formatter-json.d.ts +1 -1
- package/types/logger.d.ts +62 -61
- package/types/replacer.d.ts +11 -11
- package/types/replacers/error.d.ts +6 -6
- package/types/stdout-write.d.ts +1 -1
- package/types/utilities/colour.d.ts +16 -16
- package/types/utilities/json-path.d.ts +1 -1
- package/types/utilities/last-callsite.d.ts +1 -1
- package/types/utilities/log-filters.d.ts +4 -4
- package/types/utilities/log-types.d.ts +28 -28
- package/types/utilities/parse-filters.d.ts +2 -2
- package/types/utilities/parse-log-level.d.ts +3 -3
- package/types/utilities/stacktrace.d.ts +16 -16
- package/types/logger.test.d.ts +0 -1
- package/types/replacer.test.d.ts +0 -1
- package/types/replacers/buffers.test.d.ts +0 -1
- package/types/replacers/error.test.d.ts +0 -1
- package/types/replacers/http-client-request.test.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.8](https://github.com/DarkSheepSoftware/node-packages/compare/logger-v1.0.7...logger-v1.0.8) (2024-10-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ๐ฆ Dependencies
|
|
7
|
+
|
|
8
|
+
* **pkg:** update dependency deepmerge-ts to v7.1.3 ([0a489c4](https://github.com/DarkSheepSoftware/node-packages/commit/0a489c4d3ecf03facfa1e2b110bb219e41f50954))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### ๐งน Chores
|
|
12
|
+
|
|
13
|
+
* Apply stricter tsconfig to logger ([6be4b21](https://github.com/DarkSheepSoftware/node-packages/commit/6be4b21fda7c8975bd1344e7ae48c76156b05fa6))
|
|
14
|
+
* Custom adjustments after eslint --fix ([9d9f082](https://github.com/DarkSheepSoftware/node-packages/commit/9d9f08276956c88918ac0f9e53689efe257c9017))
|
|
15
|
+
|
|
16
|
+
## [1.0.7](https://github.com/DarkSheepSoftware/node-packages/compare/logger-v1.0.6...logger-v1.0.7) (2024-09-30)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Dependencies
|
|
20
|
+
|
|
21
|
+
* The following workspace dependencies were updated
|
|
22
|
+
* dependencies
|
|
23
|
+
* @darksheep/environment bumped from 3.0.8 to 3.0.9
|
|
24
|
+
|
|
3
25
|
## [1.0.6](https://github.com/DarkSheepSoftware/node-packages/compare/logger-v1.0.5...logger-v1.0.6) (2024-09-13)
|
|
4
26
|
|
|
5
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darksheep/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Logging your stuff to where ever you want it",
|
|
5
5
|
"license": "UNLICENCED",
|
|
6
6
|
"type": "module",
|
|
@@ -13,25 +13,23 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"src",
|
|
15
15
|
"types",
|
|
16
|
-
"!*.test
|
|
16
|
+
"!*.test.*",
|
|
17
17
|
"!assert.zod.js"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"prepack": "tsc",
|
|
20
|
+
"prepack": "yarn dlx -q -p typescript tsc",
|
|
21
21
|
"test": "node --test src/**/*.test.js",
|
|
22
22
|
"test:watch": "node --watch --test src/**/*.test.js"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@darksheep/environment": "3.0.
|
|
26
|
-
"deepmerge-ts": "7.1.
|
|
25
|
+
"@darksheep/environment": "3.0.9",
|
|
26
|
+
"deepmerge-ts": "7.1.3",
|
|
27
27
|
"stacktrace-parser": "0.1.10",
|
|
28
28
|
"traverse": "0.6.10"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/node": "~20.16.0",
|
|
32
31
|
"@types/traverse": "~0.6.33",
|
|
33
32
|
"nock": "~13.5.0",
|
|
34
|
-
"typescript": "~5.6.0",
|
|
35
33
|
"zod": "~3.23.0"
|
|
36
34
|
},
|
|
37
35
|
"engines": {
|
package/src/create-logger.js
CHANGED
|
@@ -9,8 +9,8 @@ import { LogNames } from '../utilities/log-types.js';
|
|
|
9
9
|
/** @typedef {import('../utilities/log-types.js').Callsite} Callsite */
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @param {string} [channel] The channel string
|
|
13
|
-
* @param {LogLevel} [level] The LogLevel number
|
|
12
|
+
* @param {string} [channel] - The channel string.
|
|
13
|
+
* @param {LogLevel} [level] - The LogLevel number.
|
|
14
14
|
* @returns {string}
|
|
15
15
|
*/
|
|
16
16
|
function flattenChannelLevel(channel, level) {
|
|
@@ -28,7 +28,7 @@ function flattenChannelLevel(channel, level) {
|
|
|
28
28
|
output += '.';
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
if (level != null) {
|
|
31
|
+
if (level != null && LogNames[level] != null) {
|
|
32
32
|
output += `${LogNames[level].toUpperCase()}`;
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -38,9 +38,9 @@ function flattenChannelLevel(channel, level) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* @param {string} _match The whole match
|
|
42
|
-
* @param {string} type The module type
|
|
43
|
-
* @param {string} name The module name
|
|
41
|
+
* @param {string} _match - The whole match.
|
|
42
|
+
* @param {string} type - The module type.
|
|
43
|
+
* @param {string} name - The module name.
|
|
44
44
|
* @returns {string}
|
|
45
45
|
*/
|
|
46
46
|
function underlineName(_match, type, name) {
|
|
@@ -50,16 +50,16 @@ function underlineName(_match, type, name) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* @param {Callsite} callsite The callsite to underline
|
|
53
|
+
* @param {Callsite} callsite - The callsite to underline.
|
|
54
54
|
* @returns {string}
|
|
55
55
|
*/
|
|
56
56
|
function formatFileSegment(callsite) {
|
|
57
57
|
let { file } = callsite;
|
|
58
58
|
|
|
59
59
|
file = file
|
|
60
|
-
.
|
|
61
|
-
.
|
|
62
|
-
.
|
|
60
|
+
.replaceAll(/^(?:node:)?internal\/[^/]+/gu, underlineName)
|
|
61
|
+
.replaceAll(/^\w+:[a-z]\w+$/gu, underlineName)
|
|
62
|
+
.replaceAll(/node_modules\/(?:@[^/]+\/[^/]+|[^/]+)/gu, underlineName);
|
|
63
63
|
|
|
64
64
|
if (typeof callsite.line === 'number') {
|
|
65
65
|
file += `:${callsite.line}`;
|
|
@@ -73,7 +73,7 @@ function formatFileSegment(callsite) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* @param {Callsite} callsite The node module callsite to format
|
|
76
|
+
* @param {Callsite} callsite - The node module callsite to format.
|
|
77
77
|
* @returns {string}
|
|
78
78
|
*/
|
|
79
79
|
function stackLineModule(callsite) {
|
|
@@ -89,7 +89,7 @@ function stackLineModule(callsite) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
* @param {Callsite} callsite The internal callsite to format
|
|
92
|
+
* @param {Callsite} callsite - The internal callsite to format.
|
|
93
93
|
* @returns {string}
|
|
94
94
|
*/
|
|
95
95
|
function stackLineInternal(callsite) {
|
|
@@ -101,7 +101,7 @@ function stackLineInternal(callsite) {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
-
* @param {Callsite} callsite The callsite to format
|
|
104
|
+
* @param {Callsite} callsite - The callsite to format.
|
|
105
105
|
* @returns {string}
|
|
106
106
|
*/
|
|
107
107
|
function stackLine(callsite) {
|
|
@@ -133,10 +133,10 @@ function stackLine(callsite) {
|
|
|
133
133
|
return `at ${callsite.methodName} (${file})`;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
const fixEmpties = /^\{\s*\}
|
|
136
|
+
const fixEmpties = /^\{\s*\}$/u;
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
|
-
* @param {LogContext} entry The entry we're going to convert
|
|
139
|
+
* @param {LogContext & { type?: unknown }} entry - The entry we're going to convert.
|
|
140
140
|
* @returns {string}
|
|
141
141
|
*/
|
|
142
142
|
function splatify(entry) {
|
|
@@ -160,8 +160,8 @@ function splatify(entry) {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
|
-
* @param {Callsite[] | string | undefined} stack The stack trace to format
|
|
164
|
-
* @param {number} indent The indent to render from
|
|
163
|
+
* @param {Callsite[] | string | undefined} stack - The stack trace to format.
|
|
164
|
+
* @param {number} indent - The indent to render from.
|
|
165
165
|
* @returns {string}
|
|
166
166
|
*/
|
|
167
167
|
function formatStack(stack, indent) {
|
|
@@ -174,14 +174,14 @@ function formatStack(stack, indent) {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
return (stack ?? '')
|
|
177
|
-
.split(/\r?\n|\r/)
|
|
177
|
+
.split(/\r?\n|\r/u)
|
|
178
178
|
.map((line) => `${pad}${line.trim()}`)
|
|
179
179
|
.join('\n');
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* @param {Error} error The error to render
|
|
184
|
-
* @param {number} [indent] The indent to render from
|
|
183
|
+
* @param {Error} error - The error to render.
|
|
184
|
+
* @param {number} [indent] - The indent to render from.
|
|
185
185
|
* @returns {string}
|
|
186
186
|
*/
|
|
187
187
|
function formatError(error, indent = 0) {
|
|
@@ -213,7 +213,7 @@ function formatError(error, indent = 0) {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
|
-
* @param {LogEntry} logEntry
|
|
216
|
+
* @param {LogEntry} logEntry - The Log entry which we're going to convert to a splatted string.
|
|
217
217
|
* @returns {string}
|
|
218
218
|
*/
|
|
219
219
|
export function formatterConsole(logEntry) {
|
|
@@ -238,7 +238,7 @@ export function formatterConsole(logEntry) {
|
|
|
238
238
|
output += formatError(/** @type {Error} */ ({ message, stack, cause }));
|
|
239
239
|
|
|
240
240
|
const context = splatify(entry)
|
|
241
|
-
.
|
|
241
|
+
.replaceAll(/\r?\n|\r/gu, '\n ');
|
|
242
242
|
|
|
243
243
|
return `${output}\n ${context}`.trim();
|
|
244
244
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {import('../utilities/log-types.js').LogEntry} logEntry
|
|
2
|
+
* @param {import('../utilities/log-types.js').LogEntry} logEntry - The Log entry which we're going to convert to JSON.
|
|
3
3
|
* @returns {string}
|
|
4
4
|
*/
|
|
5
5
|
export function formatterJson(logEntry) {
|
package/src/logger.js
CHANGED
|
@@ -13,10 +13,10 @@ import { LogLevels } from './utilities/log-types.js';
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {Object} Options
|
|
16
|
-
* @property {typeof replace} [replace] The replacer function to use
|
|
17
|
-
* @property {import('./replacer.js').Replacer<any, any>[]} [replacers] The replacers to use in the replacer
|
|
18
|
-
* @property {typeof formatter} [format] The formatter function to use (eg console or json formatter)
|
|
19
|
-
* @property {typeof stdoutWrite} [write] The place to write the log to
|
|
16
|
+
* @property {typeof replace} [replace] - The replacer function to use.
|
|
17
|
+
* @property {import('./replacer.js').Replacer<any, any>[]} [replacers] - The replacers to use in the replacer.
|
|
18
|
+
* @property {typeof formatter} [format] - The formatter function to use (eg console or json formatter).
|
|
19
|
+
* @property {typeof stdoutWrite} [write] - The place to write the log to.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
export class Logger {
|
|
@@ -38,8 +38,8 @@ export class Logger {
|
|
|
38
38
|
/** @type {import('./replacer.js').Replacer[]} */
|
|
39
39
|
replacers = [];
|
|
40
40
|
/**
|
|
41
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Context to add to the logger
|
|
42
|
-
* @param {Options} [options] Options for the loggers output
|
|
41
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Context to add to the logger.
|
|
42
|
+
* @param {Options} [options] - Options for the loggers output.
|
|
43
43
|
*/
|
|
44
44
|
constructor(context, options) {
|
|
45
45
|
this.#context = context ?? {};
|
|
@@ -58,7 +58,7 @@ export class Logger {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* @param {import('./utilities/log-types.js').LogContext} context Context to bind ot the async context
|
|
61
|
+
* @param {import('./utilities/log-types.js').LogContext} context - Context to bind ot the async context.
|
|
62
62
|
* @returns {void}
|
|
63
63
|
*/
|
|
64
64
|
static addAsyncContext(context) {
|
|
@@ -74,20 +74,20 @@ export class Logger {
|
|
|
74
74
|
/**
|
|
75
75
|
* @template [R=unknown]
|
|
76
76
|
* @overload
|
|
77
|
-
* @param {() => R} callback The function to wrap the context in
|
|
77
|
+
* @param {() => R} callback - The function to wrap the context in.
|
|
78
78
|
* @returns {R}
|
|
79
79
|
*/
|
|
80
80
|
/**
|
|
81
81
|
* @template [R=unknown]
|
|
82
82
|
* @overload
|
|
83
|
-
* @param {import('./utilities/log-types.js').LogContext} context Context to bind ot the async context
|
|
84
|
-
* @param {() => R} callback The function to wrap the context in
|
|
83
|
+
* @param {import('./utilities/log-types.js').LogContext} context - Context to bind ot the async context.
|
|
84
|
+
* @param {() => R} callback - The function to wrap the context in.
|
|
85
85
|
* @returns {R}
|
|
86
86
|
*/
|
|
87
87
|
/**
|
|
88
88
|
* @template [R=unknown]
|
|
89
|
-
* @param {unknown} context Context to bind ot the async context
|
|
90
|
-
* @param {unknown} [callback] The function to wrap the context in
|
|
89
|
+
* @param {unknown} context - Context to bind ot the async context.
|
|
90
|
+
* @param {unknown} [callback] - The function to wrap the context in.
|
|
91
91
|
* @returns {R}
|
|
92
92
|
*/
|
|
93
93
|
static wrap(context, callback) {
|
|
@@ -108,8 +108,8 @@ export class Logger {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* @param {import('./utilities/log-types.js').LogContext} context The new context
|
|
112
|
-
* @param {import('./utilities/log-types.js').LogLevel} [level] The log level at which we allow this context
|
|
111
|
+
* @param {import('./utilities/log-types.js').LogContext} context - The new context.
|
|
112
|
+
* @param {import('./utilities/log-types.js').LogLevel} [level] - The log level at which we allow this context.
|
|
113
113
|
* @returns {Logger}
|
|
114
114
|
*/
|
|
115
115
|
#overrideContext(context, level) {
|
|
@@ -132,42 +132,44 @@ export class Logger {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
* Set the channel in the new logger
|
|
136
|
-
* @param {string} channel The channel name
|
|
135
|
+
* Set the channel in the new logger.
|
|
136
|
+
* @param {string} channel - The channel name.
|
|
137
137
|
* @returns {Logger}
|
|
138
138
|
*/
|
|
139
139
|
channel(channel) {
|
|
140
140
|
return this.set('channel', channel);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
/*
|
|
144
|
+
* =========
|
|
145
|
+
* Level
|
|
146
|
+
* =========
|
|
147
|
+
*/
|
|
146
148
|
|
|
147
149
|
/**
|
|
148
|
-
* Creating a new logger with {context, ...this.context}
|
|
150
|
+
* Creating a new logger with {context, ...this.context}.
|
|
149
151
|
* @overload
|
|
150
|
-
* @param {import('./utilities/log-types.js').LogContext} context The new context
|
|
152
|
+
* @param {import('./utilities/log-types.js').LogContext} context - The new context.
|
|
151
153
|
* @returns {Logger}
|
|
152
154
|
*/
|
|
153
155
|
/**
|
|
154
|
-
* Creating a new logger with {context, ...this.context}
|
|
156
|
+
* Creating a new logger with {context, ...this.context}.
|
|
155
157
|
* @overload
|
|
156
|
-
* @param {import('./utilities/log-types.js').LogContext} context The new context
|
|
157
|
-
* @param {import('./utilities/log-types.js').LogLevel} level The log level at which we allow this context
|
|
158
|
+
* @param {import('./utilities/log-types.js').LogContext} context - The new context.
|
|
159
|
+
* @param {import('./utilities/log-types.js').LogLevel} level - The log level at which we allow this context.
|
|
158
160
|
* @returns {Logger}
|
|
159
161
|
*/
|
|
160
162
|
/**
|
|
161
|
-
* Creating a new logger with {context, ...this.context}
|
|
163
|
+
* Creating a new logger with {context, ...this.context}.
|
|
162
164
|
* @overload
|
|
163
|
-
* @param {import('./utilities/log-types.js').LogLevel} level The log level at which we allow this context
|
|
164
|
-
* @param {import('./utilities/log-types.js').LogContext} context The new context
|
|
165
|
+
* @param {import('./utilities/log-types.js').LogLevel} level - The log level at which we allow this context.
|
|
166
|
+
* @param {import('./utilities/log-types.js').LogContext} context - The new context.
|
|
165
167
|
* @returns {Logger}
|
|
166
168
|
*/
|
|
167
169
|
/**
|
|
168
|
-
* Creating a new logger with {context, ...this.context}
|
|
169
|
-
* @param {import('./utilities/log-types.js').LogContext | import('./utilities/log-types.js').LogLevel} contextOrLevel The log level at which we allow this context
|
|
170
|
-
* @param {import('./utilities/log-types.js').LogLevel | import('./utilities/log-types.js').LogContext} [levelOrContext] The new context
|
|
170
|
+
* Creating a new logger with {context, ...this.context}.
|
|
171
|
+
* @param {import('./utilities/log-types.js').LogContext | import('./utilities/log-types.js').LogLevel} contextOrLevel - The log level at which we allow this context.
|
|
172
|
+
* @param {import('./utilities/log-types.js').LogLevel | import('./utilities/log-types.js').LogContext} [levelOrContext] - The new context.
|
|
171
173
|
* @returns {Logger}
|
|
172
174
|
*/
|
|
173
175
|
context(contextOrLevel, levelOrContext) {
|
|
@@ -201,10 +203,10 @@ export class Logger {
|
|
|
201
203
|
}
|
|
202
204
|
|
|
203
205
|
/**
|
|
204
|
-
* Write a log with the level 'critical' - A crucial part of the application is not working
|
|
206
|
+
* Write a log with the level 'critical' - A crucial part of the application is not working.
|
|
205
207
|
*
|
|
206
|
-
* @param {Error | string} message The message to log
|
|
207
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
208
|
+
* @param {Error | string} message - The message to log.
|
|
209
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
208
210
|
* @returns {void}
|
|
209
211
|
*/
|
|
210
212
|
critical(message, context) {
|
|
@@ -212,9 +214,9 @@ export class Logger {
|
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
/**
|
|
215
|
-
* Write a log with the level 'debug' - Information that is unlikely to help in production
|
|
216
|
-
* @param {Error | string} message The message to log
|
|
217
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
217
|
+
* Write a log with the level 'debug' - Information that is unlikely to help in production.
|
|
218
|
+
* @param {Error | string} message - The message to log.
|
|
219
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
218
220
|
* @returns {void}
|
|
219
221
|
*/
|
|
220
222
|
debug(message, context) {
|
|
@@ -222,9 +224,9 @@ export class Logger {
|
|
|
222
224
|
}
|
|
223
225
|
|
|
224
226
|
/**
|
|
225
|
-
* Write a log with the level 'error' - A non critical operation fails
|
|
226
|
-
* @param {Error | string} message The message to log
|
|
227
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
227
|
+
* Write a log with the level 'error' - A non critical operation fails.
|
|
228
|
+
* @param {Error | string} message - The message to log.
|
|
229
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
228
230
|
* @returns {void}
|
|
229
231
|
*/
|
|
230
232
|
error(message, context) {
|
|
@@ -232,8 +234,8 @@ export class Logger {
|
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
/**
|
|
235
|
-
* Get a value from the context by key
|
|
236
|
-
* @param {string} key The key to get from the context
|
|
237
|
+
* Get a value from the context by key.
|
|
238
|
+
* @param {string} key - The key to get from the context.
|
|
237
239
|
* @returns {unknown}
|
|
238
240
|
*/
|
|
239
241
|
get(key) {
|
|
@@ -241,9 +243,9 @@ export class Logger {
|
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
/**
|
|
244
|
-
* Write a log with the level 'info' - Information about successful operations
|
|
245
|
-
* @param {Error | string} message The message to log
|
|
246
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
246
|
+
* Write a log with the level 'info' - Information about successful operations.
|
|
247
|
+
* @param {Error | string} message - The message to log.
|
|
248
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
247
249
|
* @returns {void}
|
|
248
250
|
*/
|
|
249
251
|
info(message, context) {
|
|
@@ -251,23 +253,25 @@ export class Logger {
|
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
/**
|
|
254
|
-
* Write a log with the level 'notice' - Information about events that may be unusual
|
|
255
|
-
* @param {Error | string} message The message to log
|
|
256
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
256
|
+
* Write a log with the level 'notice' - Information about events that may be unusual.
|
|
257
|
+
* @param {Error | string} message - The message to log.
|
|
258
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
257
259
|
* @returns {void}
|
|
258
260
|
*/
|
|
259
261
|
notice(message, context) {
|
|
260
262
|
return this.write(LogLevels.notice, message, context);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
/*
|
|
266
|
+
* =========
|
|
267
|
+
* Context
|
|
268
|
+
* =========
|
|
269
|
+
*/
|
|
266
270
|
|
|
267
271
|
/**
|
|
268
|
-
* Set a value into a new context by key
|
|
269
|
-
* @param {string} key The key to set
|
|
270
|
-
* @param {unknown} value The value to set
|
|
272
|
+
* Set a value into a new context by key.
|
|
273
|
+
* @param {string} key - The key to set.
|
|
274
|
+
* @param {unknown} value - The value to set.
|
|
271
275
|
* @returns {Logger}
|
|
272
276
|
*/
|
|
273
277
|
set(key, value) {
|
|
@@ -275,9 +279,9 @@ export class Logger {
|
|
|
275
279
|
}
|
|
276
280
|
|
|
277
281
|
/**
|
|
278
|
-
* Write a log with the level 'silly' - Information to help resolve complex logic issues
|
|
279
|
-
* @param {Error | string} message The message to log
|
|
280
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
282
|
+
* Write a log with the level 'silly' - Information to help resolve complex logic issues.
|
|
283
|
+
* @param {Error | string} message - The message to log.
|
|
284
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
281
285
|
* @returns {void}
|
|
282
286
|
*/
|
|
283
287
|
silly(message, context) {
|
|
@@ -285,8 +289,8 @@ export class Logger {
|
|
|
285
289
|
}
|
|
286
290
|
|
|
287
291
|
/**
|
|
288
|
-
* Set the trail in the new logger
|
|
289
|
-
* @param {string} [trail] The trail id
|
|
292
|
+
* Set the trail in the new logger.
|
|
293
|
+
* @param {string} [trail] - The trail id.
|
|
290
294
|
* @returns {Logger}
|
|
291
295
|
*/
|
|
292
296
|
trail(trail) {
|
|
@@ -299,9 +303,9 @@ export class Logger {
|
|
|
299
303
|
}
|
|
300
304
|
|
|
301
305
|
/**
|
|
302
|
-
* Write a log with the level 'warning' - An operation might fail in the future
|
|
303
|
-
* @param {Error | string} message The message to log
|
|
304
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
306
|
+
* Write a log with the level 'warning' - An operation might fail in the future.
|
|
307
|
+
* @param {Error | string} message - The message to log.
|
|
308
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
305
309
|
* @returns {void}
|
|
306
310
|
*/
|
|
307
311
|
warning(message, context) {
|
|
@@ -310,7 +314,7 @@ export class Logger {
|
|
|
310
314
|
|
|
311
315
|
/**
|
|
312
316
|
* @template [R=unknown]
|
|
313
|
-
* @param {() => R} callback The function to wrap the context in
|
|
317
|
+
* @param {() => R} callback - The function to wrap the context in.
|
|
314
318
|
* @returns {R}
|
|
315
319
|
*/
|
|
316
320
|
wrap(callback) {
|
|
@@ -318,10 +322,10 @@ export class Logger {
|
|
|
318
322
|
}
|
|
319
323
|
|
|
320
324
|
/**
|
|
321
|
-
* Write a new log entry
|
|
322
|
-
* @param {import('./utilities/log-types.js').LogLevel} level
|
|
323
|
-
* @param {Error | string} message The message to log
|
|
324
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Context to add to the log (merged with this.context, and Logger.contexts)
|
|
325
|
+
* Write a new log entry.
|
|
326
|
+
* @param {import('./utilities/log-types.js').LogLevel} level - The log level of the message to log.
|
|
327
|
+
* @param {Error | string} message - The message to log.
|
|
328
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Context to add to the log (merged with this.context, and Logger.contexts).
|
|
325
329
|
* @returns {void}
|
|
326
330
|
*/
|
|
327
331
|
write(level, message, context) {
|
package/src/replacer.js
CHANGED
|
@@ -6,23 +6,24 @@ import { nodesToPath } from './utilities/json-path.js';
|
|
|
6
6
|
* @template [T=unknown]
|
|
7
7
|
* @template [O=unknown]
|
|
8
8
|
* @typedef {Object} Replacer
|
|
9
|
-
* @property {string} name The name of the replacer
|
|
10
|
-
* @property {(input: unknown, path?: string[]) => boolean} shouldReplace Check to see if input can be replaced
|
|
11
|
-
* @property {(input: T, path?: string[]) => O} replace The replace function if shouldReplace returns true
|
|
12
|
-
* @property {boolean} [stopHere] Should the traverse stop here
|
|
9
|
+
* @property {string} name - The name of the replacer.
|
|
10
|
+
* @property {(input: unknown, path?: string[]) => boolean} shouldReplace - Check to see if input can be replaced.
|
|
11
|
+
* @property {(input: T, path?: string[]) => O} replace - The replace function if shouldReplace returns true.
|
|
12
|
+
* @property {boolean} [stopHere] - Should the traverse stop here.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @param {unknown} object The object we're replacing
|
|
17
|
-
* @param {Replacer[]} replacers The Replacer array to execute
|
|
16
|
+
* @param {unknown} object - The object we're replacing.
|
|
17
|
+
* @param {Replacer[]} replacers - The Replacer array to execute.
|
|
18
18
|
* @returns {unknown}
|
|
19
19
|
*/
|
|
20
20
|
export function replace(object, replacers = []) {
|
|
21
|
+
// eslint-disable-next-line unicorn/no-array-for-each -- This is not an array
|
|
21
22
|
return Traverse(object).forEach(
|
|
22
23
|
/**
|
|
23
|
-
* @param {unknown} value Current property in the traversed object
|
|
24
|
-
* @this {import('traverse').TraverseContext}
|
|
24
|
+
* @param {unknown} value - Current property in the traversed object.
|
|
25
25
|
* @returns {void}
|
|
26
|
+
* @this {import('traverse').TraverseContext}
|
|
26
27
|
*/
|
|
27
28
|
function (value) {
|
|
28
29
|
if (value == null) {
|
package/src/replacers/buffers.js
CHANGED
package/src/replacers/error.js
CHANGED
|
@@ -2,9 +2,9 @@ import { parseStack } from '../utilities/stacktrace.js';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {Object} BaseError
|
|
5
|
-
* @property {string} type The error type or name
|
|
6
|
-
* @property {string} message The error message
|
|
7
|
-
* @property {import('../utilities/stacktrace.js').Callsite[]} stack The stacktrace of the error
|
|
5
|
+
* @property {string} type - The error type or name.
|
|
6
|
+
* @property {string} message - The error message.
|
|
7
|
+
* @property {import('../utilities/stacktrace.js').Callsite[]} stack - The stacktrace of the error.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -17,11 +17,7 @@ export const ErrorReplacer = {
|
|
|
17
17
|
shouldReplace: (input) => input instanceof Error,
|
|
18
18
|
replace: (value) => {
|
|
19
19
|
/** @type {Partial<NormalisedError>} */
|
|
20
|
-
const error = {
|
|
21
|
-
type: undefined,
|
|
22
|
-
message: undefined,
|
|
23
|
-
stack: undefined,
|
|
24
|
-
};
|
|
20
|
+
const error = {};
|
|
25
21
|
|
|
26
22
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
27
23
|
if (Object.hasOwn(value, key)) {
|
package/src/stdout-write.js
CHANGED