@darksheep/logger 1.0.7 → 1.0.9
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 +27 -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/src/utilities/colour.js
CHANGED
|
@@ -28,18 +28,18 @@ const BACKGROUND = 4;
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* @typedef {Object} ColourOptions
|
|
31
|
-
* @property {ColourNames} [foreground] The foreground colour name
|
|
32
|
-
* @property {ColourMode} [foregroundMode] The foreground colour mode
|
|
33
|
-
* @property {ColourNames} [background] The background colour name
|
|
34
|
-
* @property {ColourMode} [backgroundMode] The background colour mode
|
|
35
|
-
* @property {ColourEffects[]} [effects] The string effents
|
|
36
|
-
* @property {boolean | Omit<ColourOptions, 'reset'>} [reset] How to handle the string termination
|
|
31
|
+
* @property {ColourNames} [foreground] - The foreground colour name.
|
|
32
|
+
* @property {ColourMode} [foregroundMode] - The foreground colour mode.
|
|
33
|
+
* @property {ColourNames} [background] - The background colour name.
|
|
34
|
+
* @property {ColourMode} [backgroundMode] - The background colour mode.
|
|
35
|
+
* @property {ColourEffects[]} [effects] - The string effents.
|
|
36
|
+
* @property {boolean | Omit<ColourOptions, 'reset'>} [reset] - How to handle the string termination.
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* @param {ColourNames} colour
|
|
41
|
-
* @param {typeof FOREGROUND | typeof BACKGROUND} base
|
|
42
|
-
* @param {ColourMode} [mode]
|
|
40
|
+
* @param {ColourNames} colour - The name of the colour.
|
|
41
|
+
* @param {typeof FOREGROUND | typeof BACKGROUND} base - Where the colour should be used.
|
|
42
|
+
* @param {ColourMode} [mode] - The color mode/modifier.
|
|
43
43
|
* @returns {{ colour: typeof colours[ColourNames], mode: number }}
|
|
44
44
|
*/
|
|
45
45
|
function getColour(colour, base, mode) {
|
|
@@ -59,7 +59,7 @@ function getColour(colour, base, mode) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* @param {ColourOptions} options How to colour the string
|
|
62
|
+
* @param {ColourOptions} options - How to colour the string.
|
|
63
63
|
* @returns {{ prefix: string[], suffix: string[] }}
|
|
64
64
|
*/
|
|
65
65
|
function computeColours(options) {
|
|
@@ -74,8 +74,8 @@ function computeColours(options) {
|
|
|
74
74
|
);
|
|
75
75
|
|
|
76
76
|
if (colour != null) {
|
|
77
|
-
prefix.add(`\
|
|
78
|
-
suffix.add(`\
|
|
77
|
+
prefix.add(`\u001B[${mode}${colour}m`);
|
|
78
|
+
suffix.add(`\u001B[${FOREGROUND}9m`);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -87,8 +87,8 @@ function computeColours(options) {
|
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
if (colour != null) {
|
|
90
|
-
prefix.add(`\
|
|
91
|
-
suffix.add(`\
|
|
90
|
+
prefix.add(`\u001B[${mode}${colour}m`);
|
|
91
|
+
suffix.add(`\u001B[${BACKGROUND}9m`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -96,8 +96,8 @@ function computeColours(options) {
|
|
|
96
96
|
for (const effect of options.effects) {
|
|
97
97
|
if (Object.hasOwn(effects, effect)) {
|
|
98
98
|
const [ start, end ] = effects[effect];
|
|
99
|
-
prefix.add(`\
|
|
100
|
-
suffix.add(`\
|
|
99
|
+
prefix.add(`\u001B[${start}m`);
|
|
100
|
+
suffix.add(`\u001B[2${end}m`);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -109,7 +109,7 @@ function computeColours(options) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* Should colours be used in the output
|
|
112
|
+
* Should colours be used in the output.
|
|
113
113
|
* @returns {boolean}
|
|
114
114
|
*/
|
|
115
115
|
export function shouldColour() {
|
|
@@ -124,9 +124,9 @@ export function shouldColour() {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
* Colour a string
|
|
128
|
-
* @param {string} string The string to colour
|
|
129
|
-
* @param {ColourOptions} options The options to use to colour the string
|
|
127
|
+
* Colour a string.
|
|
128
|
+
* @param {string} string - The string to colour.
|
|
129
|
+
* @param {ColourOptions} options - The options to use to colour the string.
|
|
130
130
|
* @returns {string}
|
|
131
131
|
*/
|
|
132
132
|
export function colourString(string, options) {
|
|
@@ -25,7 +25,7 @@ export const environment = {
|
|
|
25
25
|
isProduction: NODE_ENV === 'production',
|
|
26
26
|
|
|
27
27
|
logLevel: parseLogLevel(LOG_LEVEL, NODE_ENV),
|
|
28
|
-
logFilters: parseFilters(LOG_FILTERS, [ /.*/ ]),
|
|
28
|
+
logFilters: parseFilters(LOG_FILTERS, [ /.*/u ]),
|
|
29
29
|
secretFilters: parseFilters(LOG_SECRETS),
|
|
30
30
|
includeCallsite: LOG_CALLSITES,
|
|
31
31
|
stringMaxLength: LOG_MAX_LENGTH,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {string} path The json path component to escape
|
|
2
|
+
* @param {string} path - The json path component to escape.
|
|
3
3
|
* @returns {string}
|
|
4
4
|
*/
|
|
5
5
|
function jsonPathEscape(path) {
|
|
6
6
|
return path
|
|
7
|
-
.
|
|
8
|
-
.
|
|
7
|
+
.replaceAll(/\b~/gu, '~0')
|
|
8
|
+
.replaceAll('/', '~1');
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @param {string[]} nodes The nodes to the element
|
|
12
|
+
* @param {string[]} nodes - The nodes to the element.
|
|
13
13
|
* @returns {string}
|
|
14
14
|
*/
|
|
15
15
|
export function nodesToPath(nodes) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseStack } from './stacktrace.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Get the callsite that we think is outside the package
|
|
4
|
+
* Get the callsite that we think is outside the package.
|
|
5
5
|
* @returns {{ file: string, line: number, column: number } | void}
|
|
6
6
|
*/
|
|
7
7
|
export function getLastCallsite() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { environment } from './environment.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Check to see if {loggerLevel} should get logged
|
|
5
|
-
* @param {import('./log-types.js').LogLevel} level The log level to check
|
|
4
|
+
* Check to see if {loggerLevel} should get logged.
|
|
5
|
+
* @param {import('./log-types.js').LogLevel} level - The log level to check.
|
|
6
6
|
* @returns {boolean}
|
|
7
7
|
*/
|
|
8
8
|
export function checkLogLevel(level) {
|
|
@@ -10,8 +10,8 @@ export function checkLogLevel(level) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Check to see if a message with {channel} should get logged
|
|
14
|
-
* @param {string} [channel] The channel to check
|
|
13
|
+
* Check to see if a message with {channel} should get logged.
|
|
14
|
+
* @param {string} [channel] - The channel to check.
|
|
15
15
|
* @returns {boolean}
|
|
16
16
|
*/
|
|
17
17
|
export function checkLogFilters(channel = '') {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {Object} LogLevels
|
|
3
|
-
* @property {0} critical A crucial part of the application is not working
|
|
4
|
-
* @property {1} error A non critical operation fails
|
|
5
|
-
* @property {2} warning An operation might fail in the future
|
|
6
|
-
* @property {3} notice Information about events that may be unusual
|
|
7
|
-
* @property {4} info Information about successful operations
|
|
8
|
-
* @property {5} debug Information that is unlikely to help in production
|
|
9
|
-
* @property {6} silly Information to help resolve complex logic issues
|
|
3
|
+
* @property {0} critical - A crucial part of the application is not working.
|
|
4
|
+
* @property {1} error - A non critical operation fails.
|
|
5
|
+
* @property {2} warning - An operation might fail in the future.
|
|
6
|
+
* @property {3} notice - Information about events that may be unusual.
|
|
7
|
+
* @property {4} info - Information about successful operations.
|
|
8
|
+
* @property {5} debug - Information that is unlikely to help in production.
|
|
9
|
+
* @property {6} silly - Information to help resolve complex logic issues.
|
|
10
10
|
*/
|
|
11
11
|
/** @type {LogLevels} */
|
|
12
12
|
export const LogLevels = {
|
|
@@ -31,13 +31,13 @@ export const LogNames = Object.fromEntries(
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* @typedef {Object} LogInternal
|
|
34
|
-
* @property {Date} [timestamp] A timestamp for the log message
|
|
35
|
-
* @property {string} [channel] A channel to bind to the log
|
|
36
|
-
* @property {LogLevel} [level] The log level
|
|
37
|
-
* @property {string} [message] A message to use
|
|
38
|
-
* @property {string | Callsite[]} [stack] The stack trace bound to the log
|
|
39
|
-
* @property {NormalisedError | Error} [cause] A child error for the core error
|
|
40
|
-
* @property {string} [trail] The trail id bound to the callsite
|
|
34
|
+
* @property {Date} [timestamp] - A timestamp for the log message.
|
|
35
|
+
* @property {string} [channel] - A channel to bind to the log.
|
|
36
|
+
* @property {LogLevel} [level] - The log level.
|
|
37
|
+
* @property {string} [message] - A message to use.
|
|
38
|
+
* @property {string | Callsite[]} [stack] - The stack trace bound to the log.
|
|
39
|
+
* @property {NormalisedError | Error} [cause] - A child error for the core error.
|
|
40
|
+
* @property {string} [trail] - The trail id bound to the callsite.
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const matcher = /^(
|
|
2
|
-
const oneLevelWildcard = /(?:(?!\.).)
|
|
3
|
-
const multiLevelWildcard =
|
|
1
|
+
const matcher = /^(?<type>-?)(?!-)(?<channel>.+)$/u;
|
|
2
|
+
const oneLevelWildcard = /(?:(?!\.).)*/u;
|
|
3
|
+
const multiLevelWildcard = /.*/u;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @param {string} [filter] The filter string
|
|
7
|
-
* @param {RegExp[]} [fallback] Fallback to the following allowed regexp
|
|
6
|
+
* @param {string} [filter] - The filter string.
|
|
7
|
+
* @param {RegExp[]} [fallback] - Fallback to the following allowed regexp.
|
|
8
8
|
* @returns {{ allowed: RegExp[], blocked: RegExp[] }}
|
|
9
9
|
*/
|
|
10
10
|
export function parseFilters(filter = '', fallback = []) {
|
|
@@ -14,19 +14,24 @@ export function parseFilters(filter = '', fallback = []) {
|
|
|
14
14
|
const blocked = [];
|
|
15
15
|
|
|
16
16
|
for (const filter of filters) {
|
|
17
|
-
const
|
|
17
|
+
const match = matcher.exec(filter);
|
|
18
|
+
if (match?.groups == null) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { channel, type } = match.groups;
|
|
18
23
|
|
|
19
24
|
if (channel == null || channel === '') {
|
|
20
25
|
continue;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
let regex = channel
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
29
|
+
.replaceAll(/[\s#$()*+,\-.?[\\\]^{|}]/gu, String.raw`\$&`)
|
|
30
|
+
.replaceAll(String.raw`\*`, multiLevelWildcard.source)
|
|
31
|
+
.replaceAll(String.raw`\+`, oneLevelWildcard.source);
|
|
27
32
|
|
|
28
33
|
// Allow for multi level wildcards at the start of a filter
|
|
29
|
-
if (regex.startsWith(
|
|
34
|
+
if (regex.startsWith(String.raw`.*\.`)) {
|
|
30
35
|
regex = `(?:.*\\.)?${regex.slice(4)}`;
|
|
31
36
|
}
|
|
32
37
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { LogLevels } from './log-types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Convert a given string to a LogLevel
|
|
5
|
-
* @param {string} [input] The string to convert
|
|
6
|
-
* @param {string} [node] The current NODE_ENV
|
|
4
|
+
* Convert a given string to a LogLevel.
|
|
5
|
+
* @param {string} [input] - The string to convert.
|
|
6
|
+
* @param {string} [node] - The current NODE_ENV.
|
|
7
7
|
* @returns {import('./log-types.js').LogLevel}
|
|
8
8
|
*/
|
|
9
9
|
export function parseLogLevel(input, node) {
|
|
10
10
|
switch (input) {
|
|
11
|
-
case 'crit': return LogLevels.critical;
|
|
12
|
-
case 'critical': return LogLevels.critical;
|
|
13
|
-
case 'error': return LogLevels.error;
|
|
14
|
-
case 'warn': return LogLevels.warning;
|
|
15
|
-
case 'warning': return LogLevels.warning;
|
|
16
|
-
case 'notice': return LogLevels.notice;
|
|
17
|
-
case 'info': return LogLevels.info;
|
|
18
|
-
case 'debug': return LogLevels.debug;
|
|
19
|
-
case 'verbose': return LogLevels.debug;
|
|
20
|
-
case 'silly': return LogLevels.silly;
|
|
11
|
+
case 'crit': { return LogLevels.critical; }
|
|
12
|
+
case 'critical': { return LogLevels.critical; }
|
|
13
|
+
case 'error': { return LogLevels.error; }
|
|
14
|
+
case 'warn': { return LogLevels.warning; }
|
|
15
|
+
case 'warning': { return LogLevels.warning; }
|
|
16
|
+
case 'notice': { return LogLevels.notice; }
|
|
17
|
+
case 'info': { return LogLevels.info; }
|
|
18
|
+
case 'debug': { return LogLevels.debug; }
|
|
19
|
+
case 'verbose': { return LogLevels.debug; }
|
|
20
|
+
case 'silly': { return LogLevels.silly; }
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (node === 'development') {
|
|
@@ -4,17 +4,17 @@ import { parse } from 'stacktrace-parser';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {Object} Callsite
|
|
7
|
-
* @property {string} file The file name for the callsite
|
|
8
|
-
* @property {string} [relativePath] The relative path for the callsite.file
|
|
9
|
-
* @property {string} [absolutePath] The absolute path for the callsite.file
|
|
10
|
-
* @property {string} methodName The methodName from the callsite
|
|
11
|
-
* @property {number} line The line number in the file
|
|
12
|
-
* @property {number} column The column number in the file
|
|
7
|
+
* @property {string} file - The file name for the callsite.
|
|
8
|
+
* @property {string} [relativePath] - The relative path for the callsite.file.
|
|
9
|
+
* @property {string} [absolutePath] - The absolute path for the callsite.file.
|
|
10
|
+
* @property {string} methodName - The methodName from the callsite.
|
|
11
|
+
* @property {number} line - The line number in the file.
|
|
12
|
+
* @property {number} column - The column number in the file.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Get the callsite that we think is outside the package
|
|
17
|
-
* @param {string} [stack] The stacktrace to parse
|
|
16
|
+
* Get the callsite that we think is outside the package.
|
|
17
|
+
* @param {string} [stack] - The stacktrace to parse.
|
|
18
18
|
* @returns {Callsite[]}
|
|
19
19
|
*/
|
|
20
20
|
export function parseStack(stack) {
|
package/types/assert.zod.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {unknown} input
|
|
2
|
+
* @param {unknown} input - The input to convert to a zod schema.
|
|
3
3
|
* @returns {ZodType}
|
|
4
4
|
*/
|
|
5
5
|
export function convertToZod(input: unknown): ZodType;
|
|
6
6
|
/**
|
|
7
|
-
* @param {unknown} input The input object test with
|
|
7
|
+
* @param {unknown} input - The input object test with.
|
|
8
8
|
* @returns {ZodType}
|
|
9
9
|
*/
|
|
10
10
|
export function objectContaining(input: unknown): ZodType;
|
|
11
11
|
/**
|
|
12
|
-
* @param {unknown} actual The value we're testing
|
|
13
|
-
* @param {unknown} expected The schema we're testing against
|
|
12
|
+
* @param {unknown} actual - The value we're testing.
|
|
13
|
+
* @param {unknown} expected - The schema we're testing against.
|
|
14
14
|
* @returns {void}
|
|
15
15
|
*/
|
|
16
16
|
export function assertSchema(actual: unknown, expected: unknown): void;
|
package/types/create-logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {LogEntry} logEntry
|
|
2
|
+
* @param {LogEntry} logEntry - The Log entry which we're going to convert to a splatted string.
|
|
3
3
|
* @returns {string}
|
|
4
4
|
*/
|
|
5
5
|
export function formatterConsole(logEntry: LogEntry): string;
|
|
@@ -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: import("../utilities/log-types.js").LogEntry): string;
|
package/types/logger.d.ts
CHANGED
|
@@ -1,149 +1,149 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {Object} Options
|
|
3
|
-
* @property {typeof replace} [replace] The replacer function to use
|
|
4
|
-
* @property {import('./replacer.js').Replacer<any, any>[]} [replacers] The replacers to use in the replacer
|
|
5
|
-
* @property {typeof formatter} [format] The formatter function to use (eg console or json formatter)
|
|
6
|
-
* @property {typeof stdoutWrite} [write] The place to write the log to
|
|
3
|
+
* @property {typeof replace} [replace] - The replacer function to use.
|
|
4
|
+
* @property {import('./replacer.js').Replacer<any, any>[]} [replacers] - The replacers to use in the replacer.
|
|
5
|
+
* @property {typeof formatter} [format] - The formatter function to use (eg console or json formatter).
|
|
6
|
+
* @property {typeof stdoutWrite} [write] - The place to write the log to.
|
|
7
7
|
*/
|
|
8
8
|
export class Logger {
|
|
9
9
|
/** @type {AsyncLocalStorage<import('./utilities/log-types.js').LogContext[]>} */
|
|
10
10
|
static storage: AsyncLocalStorage<import("./utilities/log-types.js").LogContext[]>;
|
|
11
11
|
/**
|
|
12
|
-
* @param {import('./utilities/log-types.js').LogContext} context Context to bind ot the async context
|
|
12
|
+
* @param {import('./utilities/log-types.js').LogContext} context - Context to bind ot the async context.
|
|
13
13
|
* @returns {void}
|
|
14
14
|
*/
|
|
15
15
|
static addAsyncContext(context: import("./utilities/log-types.js").LogContext): void;
|
|
16
16
|
/**
|
|
17
17
|
* @template [R=unknown]
|
|
18
18
|
* @overload
|
|
19
|
-
* @param {() => R} callback The function to wrap the context in
|
|
19
|
+
* @param {() => R} callback - The function to wrap the context in.
|
|
20
20
|
* @returns {R}
|
|
21
21
|
*/
|
|
22
22
|
static wrap<R = unknown>(callback: () => R): R;
|
|
23
23
|
/**
|
|
24
24
|
* @template [R=unknown]
|
|
25
25
|
* @overload
|
|
26
|
-
* @param {import('./utilities/log-types.js').LogContext} context Context to bind ot the async context
|
|
27
|
-
* @param {() => R} callback The function to wrap the context in
|
|
26
|
+
* @param {import('./utilities/log-types.js').LogContext} context - Context to bind ot the async context.
|
|
27
|
+
* @param {() => R} callback - The function to wrap the context in.
|
|
28
28
|
* @returns {R}
|
|
29
29
|
*/
|
|
30
30
|
static wrap<R = unknown>(context: import("./utilities/log-types.js").LogContext, callback: () => R): R;
|
|
31
31
|
/**
|
|
32
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Context to add to the logger
|
|
33
|
-
* @param {Options} [options] Options for the loggers output
|
|
32
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Context to add to the logger.
|
|
33
|
+
* @param {Options} [options] - Options for the loggers output.
|
|
34
34
|
*/
|
|
35
35
|
constructor(context?: import("./utilities/log-types.js").LogContext | undefined, options?: Options | undefined);
|
|
36
36
|
/** @type {import('./replacer.js').Replacer[]} */
|
|
37
37
|
replacers: import("./replacer.js").Replacer[];
|
|
38
38
|
/**
|
|
39
|
-
* Set the channel in the new logger
|
|
40
|
-
* @param {string} channel The channel name
|
|
39
|
+
* Set the channel in the new logger.
|
|
40
|
+
* @param {string} channel - The channel name.
|
|
41
41
|
* @returns {Logger}
|
|
42
42
|
*/
|
|
43
43
|
channel(channel: string): Logger;
|
|
44
44
|
/**
|
|
45
|
-
* Creating a new logger with {context, ...this.context}
|
|
45
|
+
* Creating a new logger with {context, ...this.context}.
|
|
46
46
|
* @overload
|
|
47
|
-
* @param {import('./utilities/log-types.js').LogContext} context The new context
|
|
47
|
+
* @param {import('./utilities/log-types.js').LogContext} context - The new context.
|
|
48
48
|
* @returns {Logger}
|
|
49
49
|
*/
|
|
50
50
|
context(context: import("./utilities/log-types.js").LogContext): Logger;
|
|
51
51
|
/**
|
|
52
|
-
* Creating a new logger with {context, ...this.context}
|
|
52
|
+
* Creating a new logger with {context, ...this.context}.
|
|
53
53
|
* @overload
|
|
54
|
-
* @param {import('./utilities/log-types.js').LogContext} context The new context
|
|
55
|
-
* @param {import('./utilities/log-types.js').LogLevel} level The log level at which we allow this context
|
|
54
|
+
* @param {import('./utilities/log-types.js').LogContext} context - The new context.
|
|
55
|
+
* @param {import('./utilities/log-types.js').LogLevel} level - The log level at which we allow this context.
|
|
56
56
|
* @returns {Logger}
|
|
57
57
|
*/
|
|
58
58
|
context(context: import("./utilities/log-types.js").LogContext, level: import("./utilities/log-types.js").LogLevel): Logger;
|
|
59
59
|
/**
|
|
60
|
-
* Creating a new logger with {context, ...this.context}
|
|
60
|
+
* Creating a new logger with {context, ...this.context}.
|
|
61
61
|
* @overload
|
|
62
|
-
* @param {import('./utilities/log-types.js').LogLevel} level The log level at which we allow this context
|
|
63
|
-
* @param {import('./utilities/log-types.js').LogContext} context The new context
|
|
62
|
+
* @param {import('./utilities/log-types.js').LogLevel} level - The log level at which we allow this context.
|
|
63
|
+
* @param {import('./utilities/log-types.js').LogContext} context - The new context.
|
|
64
64
|
* @returns {Logger}
|
|
65
65
|
*/
|
|
66
66
|
context(level: import("./utilities/log-types.js").LogLevel, context: import("./utilities/log-types.js").LogContext): Logger;
|
|
67
67
|
/**
|
|
68
|
-
* Write a log with the level 'critical' - A crucial part of the application is not working
|
|
68
|
+
* Write a log with the level 'critical' - A crucial part of the application is not working.
|
|
69
69
|
*
|
|
70
|
-
* @param {Error | string} message The message to log
|
|
71
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
70
|
+
* @param {Error | string} message - The message to log.
|
|
71
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
72
72
|
* @returns {void}
|
|
73
73
|
*/
|
|
74
74
|
critical(message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
75
75
|
/**
|
|
76
|
-
* Write a log with the level 'debug' - Information that is unlikely to help in production
|
|
77
|
-
* @param {Error | string} message The message to log
|
|
78
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
76
|
+
* Write a log with the level 'debug' - Information that is unlikely to help in production.
|
|
77
|
+
* @param {Error | string} message - The message to log.
|
|
78
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
79
79
|
* @returns {void}
|
|
80
80
|
*/
|
|
81
81
|
debug(message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
82
82
|
/**
|
|
83
|
-
* Write a log with the level 'error' - A non critical operation fails
|
|
84
|
-
* @param {Error | string} message The message to log
|
|
85
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
83
|
+
* Write a log with the level 'error' - A non critical operation fails.
|
|
84
|
+
* @param {Error | string} message - The message to log.
|
|
85
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
86
86
|
* @returns {void}
|
|
87
87
|
*/
|
|
88
88
|
error(message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
89
89
|
/**
|
|
90
|
-
* Get a value from the context by key
|
|
91
|
-
* @param {string} key The key to get from the context
|
|
90
|
+
* Get a value from the context by key.
|
|
91
|
+
* @param {string} key - The key to get from the context.
|
|
92
92
|
* @returns {unknown}
|
|
93
93
|
*/
|
|
94
94
|
get(key: string): unknown;
|
|
95
95
|
/**
|
|
96
|
-
* Write a log with the level 'info' - Information about successful operations
|
|
97
|
-
* @param {Error | string} message The message to log
|
|
98
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
96
|
+
* Write a log with the level 'info' - Information about successful operations.
|
|
97
|
+
* @param {Error | string} message - The message to log.
|
|
98
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
99
99
|
* @returns {void}
|
|
100
100
|
*/
|
|
101
101
|
info(message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
102
102
|
/**
|
|
103
|
-
* Write a log with the level 'notice' - Information about events that may be unusual
|
|
104
|
-
* @param {Error | string} message The message to log
|
|
105
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
103
|
+
* Write a log with the level 'notice' - Information about events that may be unusual.
|
|
104
|
+
* @param {Error | string} message - The message to log.
|
|
105
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
106
106
|
* @returns {void}
|
|
107
107
|
*/
|
|
108
108
|
notice(message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
109
109
|
/**
|
|
110
|
-
* Set a value into a new context by key
|
|
111
|
-
* @param {string} key The key to set
|
|
112
|
-
* @param {unknown} value The value to set
|
|
110
|
+
* Set a value into a new context by key.
|
|
111
|
+
* @param {string} key - The key to set.
|
|
112
|
+
* @param {unknown} value - The value to set.
|
|
113
113
|
* @returns {Logger}
|
|
114
114
|
*/
|
|
115
115
|
set(key: string, value: unknown): Logger;
|
|
116
116
|
/**
|
|
117
|
-
* Write a log with the level 'silly' - Information to help resolve complex logic issues
|
|
118
|
-
* @param {Error | string} message The message to log
|
|
119
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
117
|
+
* Write a log with the level 'silly' - Information to help resolve complex logic issues.
|
|
118
|
+
* @param {Error | string} message - The message to log.
|
|
119
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
120
120
|
* @returns {void}
|
|
121
121
|
*/
|
|
122
122
|
silly(message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
123
123
|
/**
|
|
124
|
-
* Set the trail in the new logger
|
|
125
|
-
* @param {string} [trail] The trail id
|
|
124
|
+
* Set the trail in the new logger.
|
|
125
|
+
* @param {string} [trail] - The trail id.
|
|
126
126
|
* @returns {Logger}
|
|
127
127
|
*/
|
|
128
128
|
trail(trail?: string | undefined): Logger;
|
|
129
129
|
/**
|
|
130
|
-
* Write a log with the level 'warning' - An operation might fail in the future
|
|
131
|
-
* @param {Error | string} message The message to log
|
|
132
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Additional context
|
|
130
|
+
* Write a log with the level 'warning' - An operation might fail in the future.
|
|
131
|
+
* @param {Error | string} message - The message to log.
|
|
132
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Additional context.
|
|
133
133
|
* @returns {void}
|
|
134
134
|
*/
|
|
135
135
|
warning(message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
136
136
|
/**
|
|
137
137
|
* @template [R=unknown]
|
|
138
|
-
* @param {() => R} callback The function to wrap the context in
|
|
138
|
+
* @param {() => R} callback - The function to wrap the context in.
|
|
139
139
|
* @returns {R}
|
|
140
140
|
*/
|
|
141
141
|
wrap<R = unknown>(callback: () => R): R;
|
|
142
142
|
/**
|
|
143
|
-
* Write a new log entry
|
|
144
|
-
* @param {import('./utilities/log-types.js').LogLevel} level
|
|
145
|
-
* @param {Error | string} message The message to log
|
|
146
|
-
* @param {import('./utilities/log-types.js').LogContext} [context] Context to add to the log (merged with this.context, and Logger.contexts)
|
|
143
|
+
* Write a new log entry.
|
|
144
|
+
* @param {import('./utilities/log-types.js').LogLevel} level - The log level of the message to log.
|
|
145
|
+
* @param {Error | string} message - The message to log.
|
|
146
|
+
* @param {import('./utilities/log-types.js').LogContext} [context] - Context to add to the log (merged with this.context, and Logger.contexts).
|
|
147
147
|
* @returns {void}
|
|
148
148
|
*/
|
|
149
149
|
write(level: import("./utilities/log-types.js").LogLevel, message: Error | string, context?: import("./utilities/log-types.js").LogContext | undefined): void;
|
|
@@ -151,22 +151,23 @@ export class Logger {
|
|
|
151
151
|
}
|
|
152
152
|
export type Options = {
|
|
153
153
|
/**
|
|
154
|
-
* The replacer function to use
|
|
154
|
+
* - The replacer function to use.
|
|
155
155
|
*/
|
|
156
|
-
replace?: typeof replace
|
|
156
|
+
replace?: typeof replace;
|
|
157
157
|
/**
|
|
158
|
-
* The replacers to use in the replacer
|
|
158
|
+
* - The replacers to use in the replacer.
|
|
159
159
|
*/
|
|
160
|
-
replacers?: import("./replacer.js").Replacer<any, any>[]
|
|
160
|
+
replacers?: import("./replacer.js").Replacer<any, any>[];
|
|
161
161
|
/**
|
|
162
|
-
* The formatter function to use (eg console or json formatter)
|
|
162
|
+
* - The formatter function to use (eg console or json formatter).
|
|
163
163
|
*/
|
|
164
|
-
format?:
|
|
164
|
+
format?: typeof formatter;
|
|
165
165
|
/**
|
|
166
|
-
* The place to write the log to
|
|
166
|
+
* - The place to write the log to.
|
|
167
167
|
*/
|
|
168
|
-
write?: typeof stdoutWrite
|
|
168
|
+
write?: typeof stdoutWrite;
|
|
169
169
|
};
|
|
170
170
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
171
171
|
import { replace } from './replacer.js';
|
|
172
|
+
import { formatter } from './formatter.js';
|
|
172
173
|
import { stdoutWrite } from './stdout-write.js';
|
package/types/replacer.d.ts
CHANGED
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
* @template [T=unknown]
|
|
3
3
|
* @template [O=unknown]
|
|
4
4
|
* @typedef {Object} Replacer
|
|
5
|
-
* @property {string} name The name of the replacer
|
|
6
|
-
* @property {(input: unknown, path?: string[]) => boolean} shouldReplace Check to see if input can be replaced
|
|
7
|
-
* @property {(input: T, path?: string[]) => O} replace The replace function if shouldReplace returns true
|
|
8
|
-
* @property {boolean} [stopHere] Should the traverse stop here
|
|
5
|
+
* @property {string} name - The name of the replacer.
|
|
6
|
+
* @property {(input: unknown, path?: string[]) => boolean} shouldReplace - Check to see if input can be replaced.
|
|
7
|
+
* @property {(input: T, path?: string[]) => O} replace - The replace function if shouldReplace returns true.
|
|
8
|
+
* @property {boolean} [stopHere] - Should the traverse stop here.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
* @param {unknown} object The object we're replacing
|
|
12
|
-
* @param {Replacer[]} replacers The Replacer array to execute
|
|
11
|
+
* @param {unknown} object - The object we're replacing.
|
|
12
|
+
* @param {Replacer[]} replacers - The Replacer array to execute.
|
|
13
13
|
* @returns {unknown}
|
|
14
14
|
*/
|
|
15
15
|
export function replace(object: unknown, replacers?: Replacer[]): unknown;
|
|
16
16
|
export type Replacer<T = unknown, O = unknown> = {
|
|
17
17
|
/**
|
|
18
|
-
* The name of the replacer
|
|
18
|
+
* - The name of the replacer.
|
|
19
19
|
*/
|
|
20
20
|
name: string;
|
|
21
21
|
/**
|
|
22
|
-
* Check to see if input can be replaced
|
|
22
|
+
* - Check to see if input can be replaced.
|
|
23
23
|
*/
|
|
24
24
|
shouldReplace: (input: unknown, path?: string[]) => boolean;
|
|
25
25
|
/**
|
|
26
|
-
* The replace function if shouldReplace returns true
|
|
26
|
+
* - The replace function if shouldReplace returns true.
|
|
27
27
|
*/
|
|
28
28
|
replace: (input: T, path?: string[]) => O;
|
|
29
29
|
/**
|
|
30
|
-
* Should the traverse stop here
|
|
30
|
+
* - Should the traverse stop here.
|
|
31
31
|
*/
|
|
32
|
-
stopHere?: boolean
|
|
32
|
+
stopHere?: boolean;
|
|
33
33
|
};
|