@visulima/pail 3.1.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/LICENSE.md +3 -407
- package/README.md +298 -0
- package/dist/constants.d.ts +37 -0
- package/dist/index.browser.d.ts +47 -12
- package/dist/index.browser.js +12 -1
- package/dist/index.server.d.ts +65 -40
- package/dist/index.server.js +533 -2
- package/dist/interactive/index.d.ts +2 -28
- package/dist/interactive/index.js +2 -1
- package/dist/interactive/interactive-manager.d.ts +108 -0
- package/dist/interactive/interactive-stream-hook.d.ts +68 -0
- package/dist/object-tree.d.ts +65 -7
- package/dist/object-tree.js +89 -2
- package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
- package/dist/packem_shared/JsonReporter-C0AXk99i.js +58 -0
- package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
- package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
- package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
- package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
- package/dist/packem_shared/index-BomQ3E6J.js +650 -0
- package/dist/packem_shared/index-DqKWykfa.js +1146 -0
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
- package/dist/packem_shared/pail.browser-CPjQrsyy.js +1427 -0
- package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
- package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
- package/dist/pail.browser.d.ts +412 -0
- package/dist/pail.server.d.ts +233 -0
- package/dist/processor/caller/caller-processor.d.ts +40 -7
- package/dist/processor/caller/caller-processor.js +59 -1
- package/dist/processor/caller/get-caller-filename.d.ts +23 -0
- package/dist/processor/message-formatter-processor.d.ts +44 -9
- package/dist/processor/message-formatter-processor.js +67 -1
- package/dist/processor/opentelemetry-processor.d.ts +70 -0
- package/dist/processor/opentelemetry-processor.js +52 -0
- package/dist/processor/redact-processor.d.ts +39 -8
- package/dist/processor/redact-processor.js +30 -1
- package/dist/progress-bar.d.ts +75 -15
- package/dist/progress-bar.js +404 -1
- package/dist/reporter/file/json-file-reporter.d.ts +39 -20
- package/dist/reporter/file/json-file-reporter.js +136 -4
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +48 -0
- package/dist/reporter/http/abstract-http-reporter.d.ts +215 -0
- package/dist/reporter/http/abstract-http-reporter.js +435 -0
- package/dist/reporter/http/http-reporter.d.ts +39 -0
- package/dist/reporter/http/http-reporter.edge-light.d.ts +40 -0
- package/dist/reporter/http/http-reporter.edge-light.js +651 -0
- package/dist/reporter/http/http-reporter.js +13 -0
- package/dist/reporter/http/utils/compression.d.ts +7 -0
- package/dist/reporter/http/utils/log-size-error.d.ts +30 -0
- package/dist/reporter/http/utils/retry.d.ts +27 -0
- package/dist/reporter/json/abstract-json-reporter.d.ts +61 -0
- package/dist/reporter/json/index.browser.d.ts +3 -13
- package/dist/reporter/json/index.browser.js +2 -1
- package/dist/reporter/json/index.d.ts +3 -16
- package/dist/reporter/json/index.js +2 -1
- package/dist/reporter/json/json-reporter.browser.d.ts +40 -0
- package/dist/reporter/json/json-reporter.server.d.ts +50 -0
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +83 -0
- package/dist/reporter/pretty/index.browser.d.ts +2 -13
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +2 -25
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +36 -0
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +70 -0
- package/dist/reporter/raw/raw-reporter.browser.d.ts +5 -0
- package/dist/reporter/raw/raw-reporter.server.d.ts +13 -0
- package/dist/reporter/simple/simple-reporter.server.d.ts +10 -14
- package/dist/reporter/simple/simple-reporter.server.js +186 -8
- package/dist/reporter/utils/default-inspector-config.d.ts +3 -0
- package/dist/reporter/utils/format-label.d.ts +3 -0
- package/dist/spinner.d.ts +170 -104
- package/dist/spinner.js +2150 -1
- package/dist/types.d.ts +241 -0
- package/dist/utils/ansi-escapes.d.ts +4 -0
- package/dist/utils/arrayify.d.ts +2 -0
- package/dist/utils/get-longest-badge.d.ts +4 -0
- package/dist/utils/get-longest-label.d.ts +4 -0
- package/dist/utils/merge-types.d.ts +4 -0
- package/dist/utils/stream/safe-stream-handler.d.ts +21 -0
- package/dist/utils/write-console-log-based-on-level.d.ts +4 -0
- package/dist/utils/write-stream.d.ts +2 -0
- package/package.json +53 -4
- package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
- package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
- package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
- package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
- package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
- package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
- package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
- package/dist/packem_shared/abstract-json-reporter-CPsNkpz8.d.ts +0 -22
- package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-DB2G-qlI.d.ts +0 -28
- package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
- package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
- package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
- package/dist/packem_shared/index-CysYvHXs.js +0 -8
- package/dist/packem_shared/index-D9hWq9ka.js +0 -1
- package/dist/packem_shared/index.d-BR1GjZri.d.ts +0 -53
- package/dist/packem_shared/index.d-oxZvg_y7.d.ts +0 -20
- package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
- package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
- package/dist/packem_shared/pail.browser-CmWcqnn9.d.ts +0 -64
- package/dist/packem_shared/types-DVzG8TWL.d.ts +0 -95
- package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
- package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
|
@@ -1,21 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { Meta, Processor } from "../../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Global namespace extension for caller file metadata.
|
|
4
|
+
*
|
|
5
|
+
* Extends the VisulimaPail.CustomMeta interface to include file information
|
|
6
|
+
* that will be added by the CallerProcessor.
|
|
7
|
+
*/
|
|
6
8
|
declare global {
|
|
7
9
|
namespace VisulimaPail {
|
|
8
10
|
interface CustomMeta<L> {
|
|
11
|
+
/** File information where the log was called from */
|
|
9
12
|
file: {
|
|
13
|
+
/** Column number in the source file */
|
|
10
14
|
column: number | undefined;
|
|
15
|
+
/** Line number in the source file */
|
|
11
16
|
line: number | undefined;
|
|
17
|
+
/** Name/path of the source file */
|
|
12
18
|
name: string | undefined;
|
|
13
19
|
} | undefined;
|
|
14
20
|
}
|
|
15
21
|
}
|
|
16
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Caller Processor.
|
|
25
|
+
*
|
|
26
|
+
* A processor that adds file location information to log metadata.
|
|
27
|
+
* Uses stack trace analysis to determine the file, line, and column
|
|
28
|
+
* where the log call originated from.
|
|
29
|
+
* @template L - The log level type
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { createPail } from "@visulima/pail";
|
|
33
|
+
* import CallerProcessor from "@visulima/pail/processor/caller";
|
|
34
|
+
*
|
|
35
|
+
* const logger = createPail({
|
|
36
|
+
* processors: [new CallerProcessor()]
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* logger.info("This log will include file location info");
|
|
40
|
+
* // Result includes: file: { name: "...", line: 123, column: 45 }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
17
43
|
declare class CallerProcessor<L extends string = string> implements Processor<L> {
|
|
44
|
+
/**
|
|
45
|
+
* Processes log metadata to add caller file information.
|
|
46
|
+
*
|
|
47
|
+
* Analyzes the call stack to determine the file location where the log
|
|
48
|
+
* was called from and adds this information to the metadata.
|
|
49
|
+
* @param meta The log metadata to process
|
|
50
|
+
* @returns The processed metadata with file location information added
|
|
51
|
+
*/
|
|
18
52
|
process(meta: Meta<L>): Meta<L>;
|
|
19
53
|
}
|
|
20
|
-
|
|
21
|
-
export { CallerProcessor as default };
|
|
54
|
+
export default CallerProcessor;
|
|
@@ -1 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
const getCallerFilename = () => {
|
|
2
|
+
const errorStack = Error.prepareStackTrace;
|
|
3
|
+
try {
|
|
4
|
+
let result = [];
|
|
5
|
+
Error.prepareStackTrace = (_error, stack) => {
|
|
6
|
+
const callSitesWithoutCurrent = stack.slice(1);
|
|
7
|
+
result = callSitesWithoutCurrent;
|
|
8
|
+
return callSitesWithoutCurrent;
|
|
9
|
+
};
|
|
10
|
+
const callers = result.reduce((accumulator, x) => {
|
|
11
|
+
if (x.isNative() || x.getFileName()?.includes("pail/dist")) {
|
|
12
|
+
return accumulator;
|
|
13
|
+
}
|
|
14
|
+
accumulator.push({
|
|
15
|
+
columnNumber: x.getColumnNumber(),
|
|
16
|
+
fileName: x.getFileName() ?? void 0,
|
|
17
|
+
lineNumber: x.getLineNumber()
|
|
18
|
+
});
|
|
19
|
+
return accumulator;
|
|
20
|
+
}, []);
|
|
21
|
+
const firstExternalFilePath = callers[0];
|
|
22
|
+
if (firstExternalFilePath) {
|
|
23
|
+
return {
|
|
24
|
+
columnNumber: firstExternalFilePath.columnNumber ?? void 0,
|
|
25
|
+
fileName: firstExternalFilePath.fileName,
|
|
26
|
+
lineNumber: firstExternalFilePath.lineNumber ?? void 0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
fileName: "anonymous",
|
|
31
|
+
lineNumber: void 0
|
|
32
|
+
};
|
|
33
|
+
} finally {
|
|
34
|
+
Error.prepareStackTrace = errorStack;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
class CallerProcessor {
|
|
39
|
+
/**
|
|
40
|
+
* Processes log metadata to add caller file information.
|
|
41
|
+
*
|
|
42
|
+
* Analyzes the call stack to determine the file location where the log
|
|
43
|
+
* was called from and adds this information to the metadata.
|
|
44
|
+
* @param meta The log metadata to process
|
|
45
|
+
* @returns The processed metadata with file location information added
|
|
46
|
+
*/
|
|
47
|
+
// eslint-disable-next-line class-methods-use-this
|
|
48
|
+
process(meta) {
|
|
49
|
+
const { columnNumber, fileName, lineNumber } = getCallerFilename();
|
|
50
|
+
meta.file = {
|
|
51
|
+
column: columnNumber,
|
|
52
|
+
line: lineNumber,
|
|
53
|
+
name: fileName
|
|
54
|
+
};
|
|
55
|
+
return meta;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { CallerProcessor as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the file location information of the caller.
|
|
3
|
+
*
|
|
4
|
+
* Uses Node.js stack trace API to analyze the call stack and determine
|
|
5
|
+
* the file, line, and column where this function was called from.
|
|
6
|
+
* Filters out internal pail files and native code.
|
|
7
|
+
* @returns Object containing file location information
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const location = getCallerFilename();
|
|
11
|
+
* console.log(location);
|
|
12
|
+
* // { fileName: "/path/to/file.js", lineNumber: 42, columnNumber: 10 }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
declare const getCallerFilename: () => {
|
|
16
|
+
/** Column number where the call originated */
|
|
17
|
+
columnNumber?: number;
|
|
18
|
+
/** File name/path where the call originated */
|
|
19
|
+
fileName: string | undefined;
|
|
20
|
+
/** Line number where the call originated */
|
|
21
|
+
lineNumber?: number;
|
|
22
|
+
};
|
|
23
|
+
export default getCallerFilename;
|
|
@@ -1,17 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { FormatterFunction } from "@visulima/fmt";
|
|
2
|
+
import type { Meta, StringifyAwareProcessor } from "../types.d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Message Formatter Processor.
|
|
5
|
+
*
|
|
6
|
+
* A processor that formats log messages using the {@link https://www.visulima.com/docs/package/fmt|@visulima/fmt} library.
|
|
7
|
+
* Supports custom formatters, string interpolation, and complex object formatting.
|
|
8
|
+
* Processes both the main message and contextual data.
|
|
9
|
+
* @template L - The log level type
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createPail } from "@visulima/pail";
|
|
13
|
+
* import MessageFormatterProcessor from "@visulima/pail/processor/message-formatter";
|
|
14
|
+
*
|
|
15
|
+
* const logger = createPail({
|
|
16
|
+
* processors: [new MessageFormatterProcessor({
|
|
17
|
+
* formatters: {
|
|
18
|
+
* user: (value) => `[USER:${value.id}]`
|
|
19
|
+
* }
|
|
20
|
+
* })]
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* logger.info("User {user} logged in", { user: { id: 123 } });
|
|
24
|
+
* // Output: "User [USER:123] logged in"
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
8
27
|
declare class MessageFormatterProcessor<L extends string = string> implements StringifyAwareProcessor<L> {
|
|
9
28
|
#private;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new MessageFormatterProcessor instance.
|
|
31
|
+
* @param options Configuration options
|
|
32
|
+
* @param options.formatters Custom formatters for message interpolation
|
|
33
|
+
*/
|
|
10
34
|
constructor(options?: {
|
|
11
35
|
formatters?: Record<string, FormatterFunction>;
|
|
12
36
|
});
|
|
37
|
+
/**
|
|
38
|
+
* Sets the stringify function for object serialization.
|
|
39
|
+
* @param function_ The stringify function to use for serializing objects
|
|
40
|
+
*/
|
|
13
41
|
setStringify(function_: any): void;
|
|
42
|
+
/**
|
|
43
|
+
* Processes log metadata to format messages.
|
|
44
|
+
*
|
|
45
|
+
* Applies string interpolation and custom formatters to the message
|
|
46
|
+
* and contextual data in the log metadata.
|
|
47
|
+
* @param meta The log metadata to process
|
|
48
|
+
* @returns The processed metadata with formatted messages
|
|
49
|
+
*/
|
|
14
50
|
process(meta: Meta<L>): Meta<L>;
|
|
15
51
|
}
|
|
16
|
-
|
|
17
|
-
export { MessageFormatterProcessor as default };
|
|
52
|
+
export default MessageFormatterProcessor;
|
|
@@ -1 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
import { b as build } from '../packem_shared/index-BomQ3E6J.js';
|
|
2
|
+
|
|
3
|
+
class MessageFormatterProcessor {
|
|
4
|
+
/** Custom stringify function for object serialization */
|
|
5
|
+
#stringify;
|
|
6
|
+
/** Custom formatters for message interpolation */
|
|
7
|
+
#formatters;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new MessageFormatterProcessor instance.
|
|
10
|
+
* @param options Configuration options
|
|
11
|
+
* @param options.formatters Custom formatters for message interpolation
|
|
12
|
+
*/
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.#formatters = options.formatters;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sets the stringify function for object serialization.
|
|
18
|
+
* @param function_ The stringify function to use for serializing objects
|
|
19
|
+
*/
|
|
20
|
+
// eslint-disable-next-line , @typescript-eslint/no-explicit-any
|
|
21
|
+
setStringify(function_) {
|
|
22
|
+
this.#stringify = function_;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Processes log metadata to format messages.
|
|
26
|
+
*
|
|
27
|
+
* Applies string interpolation and custom formatters to the message
|
|
28
|
+
* and contextual data in the log metadata.
|
|
29
|
+
* @param meta The log metadata to process
|
|
30
|
+
* @returns The processed metadata with formatted messages
|
|
31
|
+
*/
|
|
32
|
+
process(meta) {
|
|
33
|
+
const formatter = build({
|
|
34
|
+
formatters: this.#formatters});
|
|
35
|
+
if (meta.message !== void 0) {
|
|
36
|
+
meta.message = this.#format(formatter, meta.message, meta.context ?? []);
|
|
37
|
+
}
|
|
38
|
+
return meta;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Recursively formats data using the formatter.
|
|
42
|
+
*
|
|
43
|
+
* Applies string interpolation and formatting to strings, arrays, and objects.
|
|
44
|
+
* @param formatter The formatter function to use
|
|
45
|
+
* @param data The data to format (string, array, or object)
|
|
46
|
+
* @param arguments_ Additional arguments for formatting
|
|
47
|
+
* @returns The formatted data
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
#format(formatter, data, arguments_ = []) {
|
|
52
|
+
if (typeof data === "string") {
|
|
53
|
+
return formatter(data, arguments_);
|
|
54
|
+
}
|
|
55
|
+
if (typeof data === "object" && data !== null) {
|
|
56
|
+
for (const index in data) {
|
|
57
|
+
const value = data[index];
|
|
58
|
+
if (typeof value === "string" || Array.isArray(value) || typeof value === "object") {
|
|
59
|
+
data[index] = this.#format(formatter, value, arguments_);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { MessageFormatterProcessor as default };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Meta, Processor } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the OpenTelemetry processor.
|
|
4
|
+
*/
|
|
5
|
+
export interface OpenTelemetryProcessorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Field name for the span ID. Defaults to 'span_id'
|
|
8
|
+
*/
|
|
9
|
+
spanIdFieldName?: string;
|
|
10
|
+
/**
|
|
11
|
+
* If specified, all trace fields will be nested under this key
|
|
12
|
+
*/
|
|
13
|
+
traceFieldName?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Field name for the trace flags. Defaults to 'trace_flags'
|
|
16
|
+
*/
|
|
17
|
+
traceFlagsFieldName?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Field name for the trace ID. Defaults to 'trace_id'
|
|
20
|
+
*/
|
|
21
|
+
traceIdFieldName?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* OpenTelemetry Processor.
|
|
25
|
+
*
|
|
26
|
+
* A processor that adds OpenTelemetry trace context to log metadata.
|
|
27
|
+
* Extracts trace ID, span ID, and trace flags from the active OpenTelemetry span
|
|
28
|
+
* and adds them to the log context for distributed tracing correlation.
|
|
29
|
+
* @template L - The log level type
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { createPail } from "@visulima/pail";
|
|
33
|
+
* import { OpenTelemetryProcessor } from "@visulima/pail/processor/opentelemetry";
|
|
34
|
+
*
|
|
35
|
+
* const logger = createPail({
|
|
36
|
+
* processors: [new OpenTelemetryProcessor()]
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* logger.info("Processing request");
|
|
40
|
+
* // Context includes: { trace_id: "...", span_id: "...", trace_flags: "01" }
|
|
41
|
+
* ```
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // With custom field names
|
|
45
|
+
* const logger = createPail({
|
|
46
|
+
* processors: [new OpenTelemetryProcessor({
|
|
47
|
+
* traceFieldName: "trace",
|
|
48
|
+
* traceIdFieldName: "traceId",
|
|
49
|
+
* spanIdFieldName: "spanId"
|
|
50
|
+
* })]
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare class OpenTelemetryProcessor<L extends string = string> implements Processor<L> {
|
|
55
|
+
#private;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new OpenTelemetryProcessor instance.
|
|
58
|
+
* @param options Configuration options for field names and nesting
|
|
59
|
+
*/
|
|
60
|
+
constructor(options?: OpenTelemetryProcessorOptions);
|
|
61
|
+
/**
|
|
62
|
+
* Processes log metadata to add OpenTelemetry trace context.
|
|
63
|
+
*
|
|
64
|
+
* Extracts trace information from the active OpenTelemetry span and adds it
|
|
65
|
+
* to the log context. If no valid span is found, the metadata is returned unchanged.
|
|
66
|
+
* @param meta The log metadata to process
|
|
67
|
+
* @returns The processed metadata with trace context added
|
|
68
|
+
*/
|
|
69
|
+
process(meta: Meta<L>): Meta<L>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { trace, context, isSpanContextValid } from '@opentelemetry/api';
|
|
2
|
+
|
|
3
|
+
class OpenTelemetryProcessor {
|
|
4
|
+
/** Field name for trace ID */
|
|
5
|
+
#traceIdField;
|
|
6
|
+
/** Field name for span ID */
|
|
7
|
+
#spanIdField;
|
|
8
|
+
/** Field name for trace flags */
|
|
9
|
+
#traceFlagsField;
|
|
10
|
+
/** Optional field name to nest all trace fields under */
|
|
11
|
+
#traceFieldName;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new OpenTelemetryProcessor instance.
|
|
14
|
+
* @param options Configuration options for field names and nesting
|
|
15
|
+
*/
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.#traceIdField = options.traceIdFieldName || "trace_id";
|
|
18
|
+
this.#spanIdField = options.spanIdFieldName || "span_id";
|
|
19
|
+
this.#traceFlagsField = options.traceFlagsFieldName || "trace_flags";
|
|
20
|
+
this.#traceFieldName = options.traceFieldName;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Processes log metadata to add OpenTelemetry trace context.
|
|
24
|
+
*
|
|
25
|
+
* Extracts trace information from the active OpenTelemetry span and adds it
|
|
26
|
+
* to the log context. If no valid span is found, the metadata is returned unchanged.
|
|
27
|
+
* @param meta The log metadata to process
|
|
28
|
+
* @returns The processed metadata with trace context added
|
|
29
|
+
*/
|
|
30
|
+
process(meta) {
|
|
31
|
+
const span = trace.getSpan(context.active());
|
|
32
|
+
if (!span) {
|
|
33
|
+
return meta;
|
|
34
|
+
}
|
|
35
|
+
const spanContext = span.spanContext();
|
|
36
|
+
if (!isSpanContextValid(spanContext)) {
|
|
37
|
+
return meta;
|
|
38
|
+
}
|
|
39
|
+
const fields = {
|
|
40
|
+
[this.#spanIdField]: spanContext.spanId,
|
|
41
|
+
[this.#traceFlagsField]: `0${spanContext.traceFlags.toString(16)}`,
|
|
42
|
+
[this.#traceIdField]: spanContext.traceId
|
|
43
|
+
};
|
|
44
|
+
const traceData = this.#traceFieldName ? {
|
|
45
|
+
[this.#traceFieldName]: fields
|
|
46
|
+
} : fields;
|
|
47
|
+
meta.context = [...meta.context || [], traceData];
|
|
48
|
+
return meta;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { OpenTelemetryProcessor };
|
|
@@ -1,13 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { RedactOptions, Rules } from "@visulima/redact";
|
|
2
|
+
import type { Meta, Processor } from "../types.d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Redact Processor.
|
|
5
|
+
*
|
|
6
|
+
* A processor that redacts sensitive information from log messages and metadata.
|
|
7
|
+
* Uses the {@link https://www.visulima.com/docs/package/redact|@visulima/redact} library to identify and mask sensitive data like
|
|
8
|
+
* passwords, API keys, credit card numbers, and other PII.
|
|
9
|
+
* @template L - The log level type
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createPail } from "@visulima/pail";
|
|
13
|
+
* import RedactProcessor from "@visulima/pail/processor/redact";
|
|
14
|
+
*
|
|
15
|
+
* const logger = createPail({
|
|
16
|
+
* processors: [new RedactProcessor()]
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* logger.info("User login", {
|
|
20
|
+
* username: "john",
|
|
21
|
+
* password: "secret123", // Will be redacted
|
|
22
|
+
* apiKey: "sk-123456" // Will be redacted
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
7
26
|
declare class RedactProcessor<L extends string = string> implements Processor<L> {
|
|
8
27
|
#private;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new RedactProcessor instance.
|
|
30
|
+
* @param rules Custom redaction rules (uses standardRules if not provided)
|
|
31
|
+
* @param options Additional redaction options
|
|
32
|
+
*/
|
|
9
33
|
constructor(rules?: Rules, options?: RedactOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Processes log metadata to redact sensitive information.
|
|
36
|
+
*
|
|
37
|
+
* Applies redaction rules to the message, context, and error properties
|
|
38
|
+
* in the log metadata to prevent sensitive data from being logged.
|
|
39
|
+
* @param meta The log metadata to process
|
|
40
|
+
* @returns The processed metadata with sensitive data redacted
|
|
41
|
+
*/
|
|
10
42
|
process(meta: Meta<L>): Meta<L>;
|
|
11
43
|
}
|
|
12
|
-
|
|
13
|
-
export { RedactProcessor as default };
|
|
44
|
+
export default RedactProcessor;
|
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { redact, standardRules } from '@visulima/redact';
|
|
2
|
+
|
|
3
|
+
class RedactProcessor {
|
|
4
|
+
/** The redact function configured with custom rules and options */
|
|
5
|
+
#redact;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new RedactProcessor instance.
|
|
8
|
+
* @param rules Custom redaction rules (uses standardRules if not provided)
|
|
9
|
+
* @param options Additional redaction options
|
|
10
|
+
*/
|
|
11
|
+
constructor(rules, options) {
|
|
12
|
+
this.#redact = (input) => redact(input, rules || standardRules, options);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Processes log metadata to redact sensitive information.
|
|
16
|
+
*
|
|
17
|
+
* Applies redaction rules to the message, context, and error properties
|
|
18
|
+
* in the log metadata to prevent sensitive data from being logged.
|
|
19
|
+
* @param meta The log metadata to process
|
|
20
|
+
* @returns The processed metadata with sensitive data redacted
|
|
21
|
+
*/
|
|
22
|
+
process(meta) {
|
|
23
|
+
meta.message = this.#redact(meta.message);
|
|
24
|
+
meta.context = this.#redact(meta.context);
|
|
25
|
+
meta.error = this.#redact(meta.error);
|
|
26
|
+
return meta;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { RedactProcessor as default };
|
package/dist/progress-bar.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface ProgressBarOptions {
|
|
1
|
+
import type InteractiveManager from "./interactive/interactive-manager.d.ts";
|
|
2
|
+
export type ProgressBarStyle = "shades_classic" | "shades_grey" | "rect" | "filled" | "solid" | "ascii" | "custom";
|
|
3
|
+
export interface ProgressBarOptions {
|
|
5
4
|
barCompleteChar?: string | string[];
|
|
6
5
|
barGlue?: string;
|
|
7
6
|
barIncompleteChar?: string | string[];
|
|
@@ -12,10 +11,10 @@ interface ProgressBarOptions {
|
|
|
12
11
|
total: number;
|
|
13
12
|
width?: number;
|
|
14
13
|
}
|
|
15
|
-
interface SingleBarOptions extends ProgressBarOptions {
|
|
14
|
+
export interface SingleBarOptions extends ProgressBarOptions {
|
|
16
15
|
format?: string;
|
|
17
16
|
}
|
|
18
|
-
interface MultiBarOptions {
|
|
17
|
+
export interface MultiBarOptions {
|
|
19
18
|
barCompleteChar?: string | string[];
|
|
20
19
|
barGlue?: string;
|
|
21
20
|
barIncompleteChar?: string | string[];
|
|
@@ -24,27 +23,63 @@ interface MultiBarOptions {
|
|
|
24
23
|
fps?: number;
|
|
25
24
|
style?: ProgressBarStyle;
|
|
26
25
|
}
|
|
27
|
-
interface ProgressBarPayload {
|
|
26
|
+
export interface ProgressBarPayload {
|
|
28
27
|
[key: string]: string | number | boolean;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Gets the appropriate bar character based on style and completion state.
|
|
31
|
+
* @param char Custom character override
|
|
32
|
+
* @param style Progress bar style to use
|
|
33
|
+
* @param complete Whether to get completed or incomplete character
|
|
34
|
+
* @returns The appropriate character for the given style
|
|
35
|
+
*/
|
|
36
|
+
export declare const getBarChar: (char: string | undefined, style: ProgressBarStyle, complete?: boolean) => string;
|
|
37
|
+
export declare const applyStyleToOptions: <T extends ProgressBarOptions | MultiBarOptions>(options: T) => T;
|
|
38
|
+
export declare class ProgressBar {
|
|
33
39
|
protected options: ProgressBarOptions;
|
|
34
40
|
protected current: number;
|
|
35
41
|
private startTime;
|
|
36
42
|
private interactiveManager?;
|
|
37
43
|
private isActive;
|
|
38
44
|
private payload?;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new progress bar instance.
|
|
47
|
+
* @param options Configuration options for the progress bar
|
|
48
|
+
* @param interactiveManager Optional interactive manager for rendering
|
|
49
|
+
* @param payload Optional initial payload data for format placeholders
|
|
50
|
+
*/
|
|
39
51
|
constructor(options: ProgressBarOptions, interactiveManager?: InteractiveManager, payload?: ProgressBarPayload);
|
|
52
|
+
/**
|
|
53
|
+
* Updates the progress bar to a new value.
|
|
54
|
+
* @param current The current progress value
|
|
55
|
+
* @param payload Optional payload data to merge with existing data
|
|
56
|
+
*/
|
|
40
57
|
update(current: number, payload?: ProgressBarPayload): void;
|
|
58
|
+
/**
|
|
59
|
+
* Increments the progress bar by a specified step.
|
|
60
|
+
* @param step Amount to increment (default: 1)
|
|
61
|
+
* @param payload Optional payload data to merge with existing data
|
|
62
|
+
*/
|
|
41
63
|
increment(step?: number, payload?: ProgressBarPayload): void;
|
|
64
|
+
/**
|
|
65
|
+
* Renders the progress bar as a formatted string.
|
|
66
|
+
* @returns Formatted progress bar string with all placeholders replaced
|
|
67
|
+
*/
|
|
42
68
|
render(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Starts the progress bar.
|
|
71
|
+
* @param total Optional total value to set
|
|
72
|
+
* @param startValue Optional starting value
|
|
73
|
+
* @param payload Optional initial payload data
|
|
74
|
+
*/
|
|
43
75
|
start(total?: number, startValue?: number, payload?: ProgressBarPayload): void;
|
|
76
|
+
/**
|
|
77
|
+
* Stops the progress bar and cleanup.
|
|
78
|
+
*/
|
|
44
79
|
stop(): void;
|
|
45
80
|
private calculateETA;
|
|
46
81
|
}
|
|
47
|
-
declare class MultiBarInstance extends ProgressBar {
|
|
82
|
+
export declare class MultiBarInstance extends ProgressBar {
|
|
48
83
|
private multiBar;
|
|
49
84
|
constructor(multiBar: MultiProgressBar, options: ProgressBarOptions, payload?: ProgressBarPayload);
|
|
50
85
|
update(current: number, payload?: ProgressBarPayload): void;
|
|
@@ -54,7 +89,7 @@ declare class MultiBarInstance extends ProgressBar {
|
|
|
54
89
|
total: number;
|
|
55
90
|
};
|
|
56
91
|
}
|
|
57
|
-
declare class MultiProgressBar {
|
|
92
|
+
export declare class MultiProgressBar {
|
|
58
93
|
private bars;
|
|
59
94
|
private options;
|
|
60
95
|
private interactiveManager?;
|
|
@@ -62,15 +97,40 @@ declare class MultiProgressBar {
|
|
|
62
97
|
private nextBarId;
|
|
63
98
|
private composite;
|
|
64
99
|
private barColors;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a new multi progress bar manager.
|
|
102
|
+
* @param options Configuration options for the progress bars
|
|
103
|
+
* @param interactiveManager Optional interactive manager for rendering
|
|
104
|
+
*/
|
|
65
105
|
constructor(options?: MultiBarOptions, interactiveManager?: InteractiveManager);
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new progress bar within this multi-bar manager.
|
|
108
|
+
* @param total Total value for the progress bar
|
|
109
|
+
* @param current Starting current value (default: 0)
|
|
110
|
+
* @param payload Optional initial payload data for format placeholders
|
|
111
|
+
* @returns The created progress bar instance
|
|
112
|
+
*/
|
|
66
113
|
create(total: number, current?: number, payload?: ProgressBarPayload): ProgressBar;
|
|
114
|
+
/**
|
|
115
|
+
* Removes a progress bar from the manager.
|
|
116
|
+
* @param bar The progress bar instance to remove
|
|
117
|
+
* @returns True if the bar was removed, false if not found
|
|
118
|
+
*/
|
|
67
119
|
remove(bar: ProgressBar): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Renders all progress bars.
|
|
122
|
+
*/
|
|
68
123
|
renderAll(): void;
|
|
124
|
+
/**
|
|
125
|
+
* Sets or removes a color function for a specific bar.
|
|
126
|
+
* @param bar The progress bar instance to color (must be from this MultiProgressBar)
|
|
127
|
+
* @param color Color function or undefined to remove color
|
|
128
|
+
*/
|
|
69
129
|
setBarColor(bar: MultiBarInstance, color: ((text: string) => string) | undefined): void;
|
|
130
|
+
/**
|
|
131
|
+
* Stops all progress bars and cleanup.
|
|
132
|
+
*/
|
|
70
133
|
stop(): void;
|
|
71
134
|
private renderComposite;
|
|
72
135
|
private getCompositeChar;
|
|
73
136
|
}
|
|
74
|
-
|
|
75
|
-
export { MultiBarInstance, MultiProgressBar, ProgressBar, applyStyleToOptions, getBarChar };
|
|
76
|
-
export type { MultiBarOptions, ProgressBarOptions, ProgressBarPayload, ProgressBarStyle, SingleBarOptions };
|