@darksheep/logger 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +36 -16
- package/package.json +7 -5
- package/src/create-logger.js +5 -5
- package/src/formatters/formatter-console/stack.js +1 -1
- package/src/formatters/formatter-console.js +2 -2
- package/src/index.js +17 -7
- package/src/logger.js +43 -38
- package/src/replacer.js +25 -21
- package/src/replacers/buffers.js +5 -1
- package/src/replacers/error.js +5 -2
- package/src/replacers/http-client-request.js +5 -1
- package/src/replacers/http-incoming-message.js +7 -2
- package/src/replacers/http-server-response.js +5 -1
- package/src/replacers/index.js +1 -1
- package/src/replacers/long-strings.js +5 -1
- package/src/replacers/net-socket.js +5 -1
- package/src/replacers/secrets.js +106 -13
- package/src/utilities/environment.js +25 -3
- package/src/utilities/legacy-secrets.js +36 -0
- package/src/utilities/log-types.js +12 -4
- package/src/utilities/parse-filters.js +3 -3
- package/src/utilities/parse-log-level.js +5 -1
- package/src/utilities/resource-usage.js +9 -6
- package/types/create-logger.d.ts +3 -2
- package/types/formatter.d.ts +2 -2
- package/types/formatters/formatter-console/stack.d.ts +15 -11
- package/types/formatters/formatter-console.d.ts +2 -2
- package/types/formatters/formatter-json.d.ts +1 -1
- package/types/index.d.ts +26 -11
- package/types/logger.d.ts +150 -61
- package/types/replacer.d.ts +16 -16
- package/types/replacers/buffers.d.ts +6 -2
- package/types/replacers/error.d.ts +13 -12
- package/types/replacers/http-client-request.d.ts +6 -2
- package/types/replacers/http-incoming-message.d.ts +11 -5
- package/types/replacers/http-server-response.d.ts +6 -2
- package/types/replacers/index.d.ts +8 -8
- package/types/replacers/long-strings.d.ts +6 -2
- package/types/replacers/net-socket.d.ts +6 -2
- package/types/replacers/secrets.d.ts +8 -4
- package/types/stdout-write.d.ts +1 -1
- package/types/utilities/colour.d.ts +30 -30
- package/types/utilities/environment.d.ts +14 -22
- package/types/utilities/json-path.d.ts +1 -1
- package/types/utilities/last-callsite.d.ts +1 -1
- package/types/utilities/legacy-secrets.d.ts +33 -0
- package/types/utilities/log-filters.d.ts +2 -2
- package/types/utilities/log-types.d.ts +30 -4
- package/types/utilities/parse-filters.d.ts +1 -1
- package/types/utilities/parse-log-level.d.ts +6 -2
- package/types/utilities/resource-usage.d.ts +2 -2
- package/types/utilities/stacktrace.d.ts +15 -15
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type Filters = {
|
|
2
|
+
allowed: RegExp[];
|
|
3
|
+
blocked: RegExp[];
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{ allowed: RegExp[], blocked: RegExp[] }} Filters
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the redact and remove filters, mapping the legacy `LOG_SECRETS`
|
|
10
|
+
* control onto them when the split vars are not set.
|
|
11
|
+
*
|
|
12
|
+
* In `LOG_SECRETS` a bare pattern obscured (redacted) the value and a
|
|
13
|
+
* `-`-prefixed pattern removed the key -- which is exactly the `allowed` /
|
|
14
|
+
* `blocked` split that `parseFilters` already produces. So the legacy
|
|
15
|
+
* `allowed` patterns become the redact set and the legacy `blocked` patterns
|
|
16
|
+
* become the remove set (neither carried exemptions). Whenever the matching
|
|
17
|
+
* split var is set it wins and the legacy value is ignored for that half.
|
|
18
|
+
*
|
|
19
|
+
* @param {{
|
|
20
|
+
* secrets?: string | undefined;
|
|
21
|
+
* redact?: string | undefined;
|
|
22
|
+
* remove?: string | undefined;
|
|
23
|
+
* }} options - The raw environment values.
|
|
24
|
+
* @returns {{ redactFilters: Filters, removeFilters: Filters }}
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveSecretFilters({ secrets, redact, remove }: {
|
|
27
|
+
secrets?: string | undefined;
|
|
28
|
+
redact?: string | undefined;
|
|
29
|
+
remove?: string | undefined;
|
|
30
|
+
}): {
|
|
31
|
+
redactFilters: Filters;
|
|
32
|
+
removeFilters: Filters;
|
|
33
|
+
};
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* @param {import('./log-types.js').LogLevel} level - The log level to check.
|
|
4
4
|
* @returns {boolean}
|
|
5
5
|
*/
|
|
6
|
-
export function checkLogLevel(level: import(
|
|
6
|
+
export declare function checkLogLevel(level: import('./log-types.js').LogLevel): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Check to see if a message with {channel} should get logged.
|
|
9
9
|
* @param {string} [channel] - The channel to check.
|
|
10
10
|
* @returns {boolean}
|
|
11
11
|
*/
|
|
12
|
-
export function checkLogFilters(channel?: string): boolean;
|
|
12
|
+
export declare function checkLogFilters(channel?: string): boolean;
|
|
@@ -39,14 +39,14 @@ export type LogLevels = {
|
|
|
39
39
|
* @property {6} silly - Information to help resolve complex logic issues.
|
|
40
40
|
*/
|
|
41
41
|
/** @type {LogLevels} */
|
|
42
|
-
export const LogLevels: LogLevels;
|
|
43
|
-
export const LogNames: {
|
|
42
|
+
export declare const LogLevels: LogLevels;
|
|
43
|
+
export declare const LogNames: {
|
|
44
44
|
[k: string]: string;
|
|
45
45
|
};
|
|
46
46
|
export type LogLevelNames = keyof LogLevels;
|
|
47
47
|
export type LogLevel = LogLevels[LogLevelNames];
|
|
48
|
-
export type Callsite = import(
|
|
49
|
-
export type NormalisedError = import(
|
|
48
|
+
export type Callsite = import('./stacktrace.js').Callsite;
|
|
49
|
+
export type NormalisedError = import('../replacers/error.js').NormalisedError;
|
|
50
50
|
export type LogInternal = {
|
|
51
51
|
/**
|
|
52
52
|
* - A timestamp for the log message.
|
|
@@ -82,3 +82,29 @@ export type LogEntry = {
|
|
|
82
82
|
level: LogLevel;
|
|
83
83
|
message: string;
|
|
84
84
|
} & LogInternal & Record<string, unknown>;
|
|
85
|
+
/**
|
|
86
|
+
* @typedef {keyof LogLevels} LogLevelNames
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* @typedef {LogLevels[LogLevelNames]} LogLevel
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* @typedef {import('./stacktrace.js').Callsite} Callsite
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {import('../replacers/error.js').NormalisedError} NormalisedError
|
|
96
|
+
*/
|
|
97
|
+
/**
|
|
98
|
+
* @typedef {Object} LogInternal
|
|
99
|
+
* @property {Date} [timestamp] - A timestamp for the log message.
|
|
100
|
+
* @property {string} [channel] - A channel to bind to the log.
|
|
101
|
+
* @property {LogLevel} [level] - The log level.
|
|
102
|
+
* @property {string} [message] - A message to use.
|
|
103
|
+
* @property {string | Callsite[]} [stack] - The stack trace bound to the log.
|
|
104
|
+
* @property {NormalisedError | Error} [cause] - A child error for the core error.
|
|
105
|
+
* @property {string} [trail] - The trail id bound to the callsite.
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* @typedef {LogInternal & Record<string, unknown>} LogContext
|
|
109
|
+
* @typedef {{ level: LogLevel, message: string } & LogInternal & Record<string, unknown>} LogEntry
|
|
110
|
+
*/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param {RegExp[]} [fallback] - Fallback to the following allowed regexp.
|
|
4
4
|
* @returns {{ allowed: RegExp[], blocked: RegExp[] }}
|
|
5
5
|
*/
|
|
6
|
-
export function parseFilters(filter?: string, fallback?: RegExp[]): {
|
|
6
|
+
export declare function parseFilters(filter?: string, fallback?: RegExp[]): {
|
|
7
7
|
allowed: RegExp[];
|
|
8
8
|
blocked: RegExp[];
|
|
9
9
|
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { LogLevel } from './log-types.js';
|
|
3
|
+
*/
|
|
4
|
+
import type { LogLevel } from './log-types.js';
|
|
1
5
|
/**
|
|
2
6
|
* Convert a given string to a LogLevel.
|
|
3
7
|
* @param {string} [input] - The string to convert.
|
|
4
8
|
* @param {string} [node] - The current NODE_ENV.
|
|
5
|
-
* @returns {
|
|
9
|
+
* @returns {LogLevel}
|
|
6
10
|
*/
|
|
7
|
-
export function parseLogLevel(input?: string, node?: string):
|
|
11
|
+
export declare function parseLogLevel(input?: string, node?: string): LogLevel;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Get the current memory consumption.
|
|
3
3
|
* @returns {NodeJS.MemoryUsage}
|
|
4
4
|
*/
|
|
5
|
-
export function getMemoryUsage(): NodeJS.MemoryUsage;
|
|
5
|
+
export declare function getMemoryUsage(): NodeJS.MemoryUsage;
|
|
6
6
|
/**
|
|
7
7
|
* Get the callsite that we think is outside the package.
|
|
8
8
|
* @returns {Record<'elapsed'|'total'|'system'|'user', number> | void}
|
|
9
9
|
*/
|
|
10
|
-
export function getCPUUsage(): Record<
|
|
10
|
+
export declare function getCPUUsage(): Record<'elapsed' | 'total' | 'system' | 'user', number> | void;
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} Callsite
|
|
3
|
-
* @property {string} file - The file name for the callsite.
|
|
4
|
-
* @property {string} [relativePath] - The relative path for the callsite.file.
|
|
5
|
-
* @property {string} [absolutePath] - The absolute path for the callsite.file.
|
|
6
|
-
* @property {string} methodName - The methodName from the callsite.
|
|
7
|
-
* @property {number} line - The line number in the file.
|
|
8
|
-
* @property {number} column - The column number in the file.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Get the callsite that we think is outside the package.
|
|
12
|
-
* @param {string} [stack] - The stacktrace to parse.
|
|
13
|
-
* @returns {Callsite[]}
|
|
14
|
-
*/
|
|
15
|
-
export function parseStack(stack?: string): Callsite[];
|
|
16
1
|
export type Callsite = {
|
|
17
2
|
/**
|
|
18
3
|
* - The file name for the callsite.
|
|
@@ -39,3 +24,18 @@ export type Callsite = {
|
|
|
39
24
|
*/
|
|
40
25
|
column: number;
|
|
41
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} Callsite
|
|
29
|
+
* @property {string} file - The file name for the callsite.
|
|
30
|
+
* @property {string} [relativePath] - The relative path for the callsite.file.
|
|
31
|
+
* @property {string} [absolutePath] - The absolute path for the callsite.file.
|
|
32
|
+
* @property {string} methodName - The methodName from the callsite.
|
|
33
|
+
* @property {number} line - The line number in the file.
|
|
34
|
+
* @property {number} column - The column number in the file.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Get the callsite that we think is outside the package.
|
|
38
|
+
* @param {string} [stack] - The stacktrace to parse.
|
|
39
|
+
* @returns {Callsite[]}
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseStack(stack?: string): Callsite[];
|