@visulima/pail 4.0.0-alpha.11 → 4.0.0-alpha.12

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.md +152 -894
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +1 -1
  6. package/dist/index.server.d.ts +722 -61
  7. package/dist/index.server.js +5 -4
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/express.d.ts +73 -71
  10. package/dist/middleware/fastify.d.ts +69 -67
  11. package/dist/middleware/hono.d.ts +74 -72
  12. package/dist/middleware/next/handler.d.ts +101 -34
  13. package/dist/middleware/sveltekit.d.ts +100 -98
  14. package/dist/object-tree.d.ts +67 -70
  15. package/dist/packem_shared/{PrettyReporter-BtTr13Ha.js → PrettyReporter-CIbrmjUV.js} +1 -1
  16. package/dist/packem_shared/{PrettyReporter-BCvyNzXO.js → PrettyReporter-CNJEO9g7.js} +11 -8
  17. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  18. package/dist/packem_shared/{abstract-pretty-reporter-CXAKYCb8.js → abstract-pretty-reporter-CkqCt5hg.js} +4 -2
  19. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  20. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  21. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  22. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  23. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  24. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  25. package/dist/processor/caller/caller-processor.d.ts +49 -47
  26. package/dist/processor/environment-processor.d.ts +113 -113
  27. package/dist/processor/environment-processor.js +3 -10
  28. package/dist/processor/message-formatter-processor.d.ts +51 -49
  29. package/dist/processor/message-formatter-processor.js +2 -2
  30. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  31. package/dist/processor/redact-processor.d.ts +60 -41
  32. package/dist/processor/sampling-processor.d.ts +102 -101
  33. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  34. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  35. package/dist/reporter/http/http-reporter.d.ts +40 -36
  36. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  37. package/dist/reporter/json/index.browser.d.ts +99 -3
  38. package/dist/reporter/json/index.d.ts +51 -3
  39. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  40. package/dist/reporter/pretty/index.browser.js +1 -1
  41. package/dist/reporter/pretty/index.d.ts +219 -2
  42. package/dist/reporter/pretty/index.js +1 -1
  43. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  44. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  45. package/dist/wide-event.d.ts +5 -300
  46. package/package.json +6 -7
  47. package/dist/constants.d.ts +0 -37
  48. package/dist/middleware/next/middleware.d.ts +0 -59
  49. package/dist/middleware/next/storage.d.ts +0 -14
  50. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  51. package/dist/middleware/shared/headers.d.ts +0 -14
  52. package/dist/middleware/shared/routes.d.ts +0 -30
  53. package/dist/middleware/shared/storage.d.ts +0 -29
  54. package/dist/pail.browser.d.ts +0 -412
  55. package/dist/pail.server.d.ts +0 -158
  56. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  57. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  58. package/dist/reporter/http/utils/compression.d.ts +0 -7
  59. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  60. package/dist/reporter/http/utils/retry.d.ts +0 -27
  61. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  62. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  63. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  64. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  65. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  66. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  67. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  68. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  69. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  70. package/dist/reporter/utils/format-label.d.ts +0 -3
  71. package/dist/types.d.ts +0 -241
  72. package/dist/utils/arrayify.d.ts +0 -2
  73. package/dist/utils/get-longest-badge.d.ts +0 -4
  74. package/dist/utils/get-longest-label.d.ts +0 -4
  75. package/dist/utils/merge-types.d.ts +0 -4
  76. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  77. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  78. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,27 +0,0 @@
1
- /**
2
- * Sends an HTTP request with retry logic and rate limiting support.
3
- * @param url The URL to send the request to
4
- * @param method The HTTP method to use
5
- * @param headers Request headers
6
- * @param body The request body (string or Uint8Array)
7
- * @param maxRetries Maximum number of retry attempts
8
- * @param retryDelay Base delay between retries in milliseconds
9
- * @param respectRateLimit Whether to respect rate limiting (429 responses)
10
- * @param onDebugRequestResponse Optional callback for debugging requests/responses
11
- * @param onError Optional callback for error handling
12
- */
13
- declare const sendWithRetry: (url: string, method: string, headers: Record<string, string>, body: string | Uint8Array, maxRetries: number, retryDelay: number, respectRateLimit: boolean, onDebugRequestResponse?: (requestResponse: {
14
- req: {
15
- body: string | Uint8Array;
16
- headers: Record<string, string>;
17
- method: string;
18
- url: string;
19
- };
20
- res: {
21
- body: string;
22
- headers: Record<string, string>;
23
- status: number;
24
- statusText: string;
25
- };
26
- }) => void, onError?: (error: Error) => void) => Promise<void>;
27
- export default sendWithRetry;
@@ -1,61 +0,0 @@
1
- import type { stringify } from "safe-stable-stringify";
2
- import type { LiteralUnion } from "type-fest";
3
- import type { ExtendedRfc5424LogLevels, ReadonlyMeta, StringifyAwareReporter } from "../../types.d.ts";
4
- /**
5
- * Options for configuring JSON reporters.
6
- */
7
- export type AbstractJsonReporterOptions = {
8
- /** Error serialization options */
9
- error: Partial<{
10
- /** Properties to exclude from error serialization */
11
- exclude?: string[];
12
- /** Maximum depth for error object serialization */
13
- maxDepth?: number;
14
- /** Whether to use toJSON methods during serialization */
15
- useToJSON?: boolean;
16
- }>;
17
- };
18
- /**
19
- * Abstract JSON Reporter.
20
- *
21
- * Base class for JSON-based reporters that provides common functionality
22
- * for serializing log metadata to JSON format. Handles error serialization,
23
- * context processing, and provides a template method for actual output.
24
- * @template L - The log level type
25
- * @example
26
- * ```typescript
27
- * class CustomJsonReporter extends AbstractJsonReporter {
28
- * protected _log(message: string): void {
29
- * console.log(message);
30
- * }
31
- * }
32
- * ```
33
- */
34
- export declare abstract class AbstractJsonReporter<L extends string = string> implements StringifyAwareReporter<L> {
35
- /** Custom stringify function for object serialization */
36
- protected stringify: typeof stringify | undefined;
37
- /** Error serialization options */
38
- protected errorOptions: AbstractJsonReporterOptions["error"];
39
- /**
40
- * Creates a new AbstractJsonReporter instance.
41
- * @param options Configuration options for JSON formatting and error handling
42
- */
43
- constructor(options?: Partial<AbstractJsonReporterOptions>);
44
- /**
45
- * Sets a custom stringify function for object serialization.
46
- * @param function_ The stringify function to use for serialization
47
- */
48
- setStringify(function_: typeof stringify): void;
49
- log(meta: ReadonlyMeta<L>): void;
50
- /**
51
- * Template method for outputting the JSON log message.
52
- *
53
- * Subclasses must implement this method to define how the JSON message
54
- * is actually written (to console, file, network, etc.).
55
- * @param message The JSON-formatted log message
56
- * @param logLevel The log level of the message
57
- * @protected
58
- * @abstract
59
- */
60
- protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
61
- }
@@ -1,40 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { ExtendedRfc5424LogLevels } from "../../types.d.ts";
3
- import type { AbstractJsonReporterOptions } from "./abstract-json-reporter.d.ts";
4
- import { AbstractJsonReporter } from "./abstract-json-reporter.d.ts";
5
- /**
6
- * Browser JSON Reporter.
7
- *
8
- * A JSON reporter for browser environments that outputs structured log data
9
- * to the browser console. Uses appropriate console methods based on log level.
10
- * @template L - The log level type
11
- * @example
12
- * ```typescript
13
- * import { createPail } from "@visulima/pail";
14
- *
15
- * const logger = createPail({
16
- * reporters: [new JsonReporter()]
17
- * });
18
- *
19
- * logger.info("Application started", { version: "1.0.0" });
20
- * // Outputs: {"level":"info","message":"Application started","context":[{"version":"1.0.0"}],...}
21
- * ```
22
- */
23
- declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> {
24
- /**
25
- * Creates a new Browser JSON Reporter instance.
26
- * @param options Configuration options for JSON formatting
27
- */
28
- constructor(options?: Partial<AbstractJsonReporterOptions>);
29
- /**
30
- * Outputs the JSON message to the browser console.
31
- *
32
- * Uses the appropriate console method based on the log level
33
- * (console.log, console.error, console.warn, etc.).
34
- * @param message The JSON-formatted log message
35
- * @param logLevel The log level determining which console method to use
36
- * @protected
37
- */
38
- protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
39
- }
40
- export default JsonReporter;
@@ -1,50 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { ExtendedRfc5424LogLevels, StreamAwareReporter } from "../../types.d.ts";
3
- import type { AbstractJsonReporterOptions } from "./abstract-json-reporter.d.ts";
4
- import { AbstractJsonReporter } from "./abstract-json-reporter.d.ts";
5
- /**
6
- * Server JSON Reporter.
7
- *
8
- * A JSON reporter for Node.js server environments that outputs structured log data
9
- * to stdout/stderr streams. Routes error-level logs to stderr and others to stdout.
10
- * @template L - The log level type
11
- * @example
12
- * ```typescript
13
- * import { createPail } from "@visulima/pail";
14
- *
15
- * const logger = createPail({
16
- * reporters: [new JsonReporter()]
17
- * });
18
- *
19
- * logger.info("Server started", { port: 3000 });
20
- * logger.error("Database connection failed", error);
21
- * ```
22
- */
23
- declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> implements StreamAwareReporter<L> {
24
- #private;
25
- /**
26
- * Creates a new Server JSON Reporter instance.
27
- * @param options Configuration options for JSON formatting
28
- */
29
- constructor(options?: Partial<AbstractJsonReporterOptions>);
30
- /**
31
- * Sets the stdout stream for the reporter.
32
- * @param stdout_ The writable stream to use for stdout output
33
- */
34
- setStdout(stdout_: NodeJS.WriteStream): void;
35
- /**
36
- * Sets the stderr stream for the reporter.
37
- * @param stderr_ The writable stream to use for stderr output
38
- */
39
- setStderr(stderr_: NodeJS.WriteStream): void;
40
- /**
41
- * Outputs the JSON message to the appropriate stream.
42
- *
43
- * Routes error and warning level messages to stderr, others to stdout.
44
- * @param message The JSON-formatted log message
45
- * @param logLevel The log level determining which stream to use
46
- * @protected
47
- */
48
- protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
49
- }
50
- export default JsonReporter;
@@ -1,83 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { DefaultLogTypes, LoggerTypesAwareReporter, LoggerTypesConfig, ReadonlyMeta } from "../../types.d.ts";
3
- /**
4
- * Default date formatter for pretty reporters.
5
- *
6
- * Formats a Date object as HH:MM:SS (24-hour format).
7
- * @param date The date to format
8
- * @returns Formatted time string
9
- * @example
10
- * ```typescript
11
- * dateFormatter(new Date()); // "14:30:25"
12
- * ```
13
- */
14
- export declare const dateFormatter: (date: Date) => string;
15
- /**
16
- * Abstract Pretty Reporter.
17
- *
18
- * Base class for pretty-printing reporters that format log messages with colors,
19
- * styles, and structured layout. Provides common functionality for styling options
20
- * and logger type configuration.
21
- * @template T - Custom logger type names
22
- * @template L - Log level types
23
- * @example
24
- * ```typescript
25
- * class CustomPrettyReporter extends AbstractPrettyReporter {
26
- * public log(meta: ReadonlyMeta) {
27
- * const formatted = this.formatMessage(meta);
28
- * console.log(formatted);
29
- * }
30
- * }
31
- * ```
32
- */
33
- export declare abstract class AbstractPrettyReporter<T extends string = string, L extends string = string> implements LoggerTypesAwareReporter<T, L> {
34
- /** Styling options for pretty formatting */
35
- protected readonly styles: PrettyStyleOptions;
36
- /** Logger type configurations for styling */
37
- protected loggerTypes: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>;
38
- /**
39
- * Creates a new AbstractPrettyReporter instance.
40
- * @param options Styling options for pretty formatting
41
- * @protected
42
- */
43
- protected constructor(options: Partial<PrettyStyleOptions>);
44
- /**
45
- * Sets the logger types configuration for styling.
46
- * @param types Logger type configurations with colors and labels
47
- */
48
- setLoggerTypes(types: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>): void;
49
- /**
50
- * Logs a message with pretty formatting.
51
- * @param meta The log metadata to format and output
52
- * @abstract
53
- */
54
- abstract log(meta: ReadonlyMeta<L>): void;
55
- }
56
- /**
57
- * Options for configuring pretty reporter styling.
58
- */
59
- export type PrettyStyleOptions = {
60
- /** Bold styling options */
61
- bold: {
62
- /** Whether to bold the label text */
63
- label: boolean;
64
- };
65
- /** Function to format dates in log output */
66
- dateFormatter: (date: Date) => string;
67
- /** Maximum length of message before line break (optional) */
68
- messageLength: number | undefined;
69
- /** Underline styling options */
70
- underline: {
71
- /** Whether to underline the label */
72
- label: boolean;
73
- /** Whether to underline prefixes */
74
- prefix: boolean;
75
- /** Whether to underline suffixes */
76
- suffix: boolean;
77
- };
78
- /** Uppercase styling options */
79
- uppercase: {
80
- /** Whether to uppercase the label text */
81
- label: boolean;
82
- };
83
- };
@@ -1,36 +0,0 @@
1
- import type { ReadonlyMeta } from "../../types.d.ts";
2
- import type { PrettyStyleOptions } from "./abstract-pretty-reporter.d.ts";
3
- import { AbstractPrettyReporter } from "./abstract-pretty-reporter.d.ts";
4
- /**
5
- * Browser Pretty Reporter.
6
- *
7
- * A pretty-printing reporter for browser environments that formats log messages
8
- * with colors and structured layout for console output. Uses browser-compatible
9
- * color formatting and console APIs.
10
- * @template T - Custom logger type names
11
- * @template L - Log level types
12
- * @example
13
- * ```typescript
14
- * import { createPail } from "@visulima/pail";
15
- *
16
- * const logger = createPail({
17
- * reporters: [new PrettyReporter({
18
- * bold: { label: true },
19
- * uppercase: { label: true }
20
- * })]
21
- * });
22
- *
23
- * logger.info("Application started");
24
- * logger.error("Something went wrong", error);
25
- * ```
26
- */
27
- declare class PrettyReporter<T extends string = string, L extends string = string> extends AbstractPrettyReporter<T, L> {
28
- #private;
29
- /**
30
- * Creates a new Browser Pretty Reporter instance.
31
- * @param options Styling options for pretty formatting
32
- */
33
- constructor(options?: Partial<PrettyStyleOptions>);
34
- log(meta: ReadonlyMeta<L>): void;
35
- }
36
- export default PrettyReporter;
@@ -1,70 +0,0 @@
1
- import type { RenderErrorOptions } from "@visulima/error/error";
2
- import type { Options as InspectorOptions } from "@visulima/inspector";
3
- import type { InteractiveManager } from "@visulima/interactive-manager";
4
- import type { LiteralUnion } from "type-fest";
5
- import type { ExtendedRfc5424LogLevels, InteractiveStreamReporter, ReadonlyMeta } from "../../types.d.ts";
6
- import type { PrettyStyleOptions } from "./abstract-pretty-reporter.d.ts";
7
- import { AbstractPrettyReporter } from "./abstract-pretty-reporter.d.ts";
8
- /**
9
- * Options for configuring the Server Pretty Reporter.
10
- */
11
- export type PrettyReporterOptions = PrettyStyleOptions & {
12
- /** Error rendering options */
13
- error: Partial<Omit<RenderErrorOptions, "color" | "prefix" | "indentation">>;
14
- /** Object inspection options */
15
- inspect: Partial<InspectorOptions>;
16
- };
17
- /**
18
- * Server Pretty Reporter.
19
- *
20
- * A comprehensive pretty-printing reporter for Node.js server environments that
21
- * formats log messages with colors, structured layout, and advanced features like
22
- * error rendering, object inspection, and interactive terminal support.
23
- * @template T - Custom logger type names
24
- * @template L - Log level types
25
- * @example
26
- * ```typescript
27
- * import { createPail } from "@visulima/pail";
28
- *
29
- * const logger = createPail({
30
- * reporters: [new PrettyReporter({
31
- * bold: { label: true },
32
- * error: { color: { title: 'red' } }
33
- * })]
34
- * });
35
- *
36
- * logger.info("Server started on port 3000");
37
- * logger.error("Database error", dbError);
38
- * ```
39
- */
40
- export declare class PrettyReporter<T extends string = string, L extends string = string> extends AbstractPrettyReporter<T, L> implements InteractiveStreamReporter<L> {
41
- #private;
42
- /**
43
- * Creates a new Server Pretty Reporter instance.
44
- * @param options Configuration options for styling, error rendering, and object inspection
45
- */
46
- constructor(options?: Partial<PrettyReporterOptions>);
47
- /**
48
- * Sets the stdout stream for the reporter.
49
- * @param stdout_ The writable stream to use for standard output
50
- */
51
- setStdout(stdout_: NodeJS.WriteStream): void;
52
- /**
53
- * Sets the stderr stream for the reporter.
54
- * @param stderr_ The writable stream to use for error output
55
- */
56
- setStderr(stderr_: NodeJS.WriteStream): void;
57
- /**
58
- * Sets the interactive manager for handling interactive output.
59
- * @param manager The interactive manager instance, or undefined to disable
60
- */
61
- setInteractiveManager(manager?: InteractiveManager): void;
62
- /**
63
- * Enables or disables interactive mode.
64
- * @param interactive Whether to enable interactive terminal features
65
- */
66
- setIsInteractive(interactive: boolean): void;
67
- log(meta: ReadonlyMeta<L>): void;
68
- protected _formatMessage(data: ReadonlyMeta<L>): string;
69
- protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
70
- }
@@ -1,5 +0,0 @@
1
- import type { ReadonlyMeta, Reporter } from "../../types.d.ts";
2
- declare class RawReporter<L extends string = string> implements Reporter<L> {
3
- log(meta: ReadonlyMeta<L>): void;
4
- }
5
- export default RawReporter;
@@ -1,13 +0,0 @@
1
- import type { Options as InspectorOptions } from "@visulima/inspector";
2
- import type { InteractiveManager } from "@visulima/interactive-manager";
3
- import type { ReadonlyMeta, StreamAwareReporter } from "../../types.d.ts";
4
- declare class RawReporter<L extends string = string> implements StreamAwareReporter<L> {
5
- #private;
6
- constructor(inspectOptions?: Partial<InspectorOptions>);
7
- setStdout(stdout_: NodeJS.WriteStream): void;
8
- setStderr(stderr_: NodeJS.WriteStream): void;
9
- setInteractiveManager(manager?: InteractiveManager): void;
10
- setIsInteractive(interactive: boolean): void;
11
- log(meta: ReadonlyMeta<L>): void;
12
- }
13
- export default RawReporter;
@@ -1,3 +0,0 @@
1
- import type { Options } from "@visulima/inspector";
2
- declare const defaultInspectorConfig: Partial<Options>;
3
- export default defaultInspectorConfig;
@@ -1,3 +0,0 @@
1
- import type { PrettyStyleOptions } from "../pretty/abstract-pretty-reporter.d.ts";
2
- declare const formatLabel: (label: string, styles: PrettyStyleOptions) => string;
3
- export default formatLabel;
package/dist/types.d.ts DELETED
@@ -1,241 +0,0 @@
1
- import type { AnsiColors } from "@visulima/colorize";
2
- import type { InteractiveManager } from "@visulima/interactive-manager";
3
- import type { stringify } from "safe-stable-stringify";
4
- import type { LiteralUnion, Primitive } from "type-fest";
5
- /**
6
- * Global namespace for extending Pail's metadata interface.
7
- *
8
- * This global declaration allows other packages and applications to extend
9
- * the Meta interface with custom properties by declaring additional properties
10
- * in the VisulimaPail.CustomMeta interface.
11
- * @example
12
- * ```typescript
13
- * declare global {
14
- * namespace VisulimaPail {
15
- * interface CustomMeta<L> {
16
- * userId?: string;
17
- * requestId?: string;
18
- * }
19
- * }
20
- * }
21
- * ```
22
- */
23
- declare global {
24
- namespace VisulimaPail {
25
- interface CustomMeta<L> {
26
- }
27
- }
28
- }
29
- /**
30
- * Metadata object containing all information about a log entry.
31
- *
32
- * This interface defines the structure of metadata that is passed to reporters
33
- * and processors. It contains all the contextual information about a log message
34
- * including the message itself, timing information, error details, and more.
35
- * @template L - The log level type
36
- */
37
- export interface Meta<L> extends VisulimaPail.CustomMeta<L> {
38
- badge: string | undefined;
39
- context: any[] | undefined;
40
- date: Date | string;
41
- error: Error | undefined;
42
- groups: string[];
43
- label: string | undefined;
44
- message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
45
- prefix: string | undefined;
46
- repeated?: number;
47
- scope: string[] | undefined;
48
- suffix: string | undefined;
49
- traceError: Error | undefined;
50
- type: {
51
- level: ExtendedRfc5424LogLevels | L;
52
- name: string;
53
- };
54
- }
55
- /**
56
- * Extended RFC 5424 Log Levels.
57
- *
58
- * Standard syslog severity levels as defined in RFC 5424, plus additional
59
- * levels commonly used in modern applications. Each level has a numeric
60
- * priority where lower numbers indicate higher severity.
61
- * @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
62
- */
63
- export type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
64
- /**
65
- * Default Log Types.
66
- *
67
- * Predefined semantic log types that provide meaningful categorization
68
- * for different kinds of log messages. Each type has associated styling
69
- * and log level configuration.
70
- */
71
- export type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "warning" | "watch";
72
- /**
73
- * Logger Function Type.
74
- *
75
- * Represents a logging function that can accept either a structured Message object
76
- * or multiple arguments in the traditional console.log style.
77
- */
78
- export interface LoggerFunction {
79
- (message: Message): void;
80
- (...message: any[]): void;
81
- }
82
- /**
83
- * Logger Configuration.
84
- *
85
- * Configuration object that defines how a specific logger type should behave,
86
- * including its visual appearance and log level.
87
- * @template L - The log level type
88
- */
89
- export interface LoggerConfiguration<L extends string> {
90
- badge?: string;
91
- color?: AnsiColors;
92
- label: string;
93
- logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
94
- }
95
- /**
96
- * Logger Types Configuration.
97
- *
98
- * A record mapping logger type names to their configurations.
99
- * @template T - Custom logger type names
100
- * @template L - Log level types
101
- */
102
- export type LoggerTypesConfig<T extends string, L extends string> = Record<T, Partial<LoggerConfiguration<L>>>;
103
- /**
104
- * Default Logger Types Configuration.
105
- *
106
- * A complete mapping of all default log types to their full configurations.
107
- * @template L - Log level types
108
- */
109
- export type DefaultLoggerTypes<L extends string = string> = Record<DefaultLogTypes, LoggerConfiguration<L>>;
110
- /**
111
- * Read-only Metadata.
112
- *
113
- * Immutable version of the Meta interface for use in reporters.
114
- * @template L - The log level type
115
- */
116
- export type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
117
- /**
118
- * Reporter Interface.
119
- *
120
- * Base interface for all reporters. Reporters are responsible for
121
- * outputting log messages to various destinations (console, files, etc.).
122
- * @template L - The log level type
123
- */
124
- export interface Reporter<L extends string> {
125
- log: (meta: ReadonlyMeta<L>) => void;
126
- }
127
- /**
128
- * Stream-Aware Reporter Interface.
129
- *
130
- * Extends Reporter with the ability to work with Node.js streams.
131
- * Used for server-side reporters that need to write to stdout/stderr.
132
- * @template L - The log level type
133
- */
134
- export interface StreamAwareReporter<L extends string> extends Reporter<L> {
135
- /** Set the stderr stream for error output */
136
- setStderr: (stderr: NodeJS.WriteStream) => void;
137
- /** Set the stdout stream for standard output */
138
- setStdout: (stdout: NodeJS.WriteStream) => void;
139
- }
140
- /**
141
- * Logger Types Aware Reporter Interface.
142
- *
143
- * Extends Reporter with the ability to receive logger type configurations.
144
- * Allows reporters to customize their output based on logger types.
145
- * @template T - Custom logger type names
146
- * @template L - The log level type
147
- */
148
- export interface LoggerTypesAwareReporter<T extends string, L extends string> extends Reporter<L> {
149
- /** Set the logger types configuration */
150
- setLoggerTypes: (types: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>) => void;
151
- }
152
- /**
153
- * Stringify-Aware Reporter Interface.
154
- *
155
- * Extends Reporter with the ability to receive a custom stringify function.
156
- * Useful for reporters that need to serialize complex objects.
157
- * @template L - The log level type
158
- */
159
- export interface StringifyAwareReporter<L extends string> extends Reporter<L> {
160
- /** Set the stringify function for object serialization */
161
- setStringify: (stringify: any) => void;
162
- }
163
- /**
164
- * Interactive Stream Reporter Interface.
165
- *
166
- * Extends StreamAwareReporter with interactive capabilities for terminal UIs.
167
- * Supports features like progress bars and dynamic updates.
168
- * @template L - The log level type
169
- */
170
- export interface InteractiveStreamReporter<L extends string> extends StreamAwareReporter<L> {
171
- /** Set the interactive manager for handling interactive output */
172
- setInteractiveManager: (manager?: InteractiveManager) => void;
173
- /** Enable or disable interactive mode */
174
- setIsInteractive: (interactive: boolean) => void;
175
- }
176
- /**
177
- * Processor Interface.
178
- *
179
- * Base interface for all processors. Processors can modify or enhance
180
- * log metadata before it reaches reporters.
181
- * @template L - The log level type
182
- */
183
- export interface Processor<L extends string> {
184
- /** Process the log metadata */
185
- process: (meta: Meta<L>) => Meta<L>;
186
- }
187
- /**
188
- * Stringify-Aware Processor Interface.
189
- *
190
- * Extends Processor with the ability to receive a custom stringify function.
191
- * Useful for processors that need to serialize complex objects.
192
- * @template L - The log level type
193
- */
194
- export interface StringifyAwareProcessor<L extends string> extends Processor<L> {
195
- /** Set the stringify function for object serialization */
196
- setStringify: (stringify: typeof JSON.stringify) => void;
197
- }
198
- export interface ConstructorOptions<T extends string, L extends string> {
199
- disabled?: boolean;
200
- logLevel?: LiteralUnion<ExtendedRfc5424LogLevels, L>;
201
- logLevels?: Partial<Record<ExtendedRfc5424LogLevels, number>> & Record<L, number>;
202
- messages?: {
203
- timerEnd?: string;
204
- timerStart?: string;
205
- };
206
- processors?: Processor<L>[];
207
- rawReporter?: Reporter<L>;
208
- reporters?: Reporter<L>[];
209
- scope?: string[] | string;
210
- throttle?: number;
211
- throttleMin?: number;
212
- types?: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>;
213
- }
214
- export interface ServerConstructorOptions<T extends string, L extends string> extends ConstructorOptions<T, L> {
215
- interactive?: boolean;
216
- stderr: NodeJS.WriteStream;
217
- stdout: NodeJS.WriteStream;
218
- }
219
- export type Message = {
220
- context?: any[];
221
- message: any;
222
- prefix?: string;
223
- suffix?: string;
224
- };
225
- /**
226
- * Internal interface for parent logger optimization properties.
227
- *
228
- * These properties are used internally to optimize child logger creation
229
- * by reusing parent logger's computed values when they haven't changed.
230
- * @internal
231
- */
232
- export interface ParentLoggerOptimization<T extends string = string, L extends string = string> {
233
- parentLogLevels?: Record<string, number>;
234
- parentLongestLabel?: string;
235
- parentMessages?: {
236
- timerEnd: string;
237
- timerStart: string;
238
- };
239
- parentStringify?: typeof stringify;
240
- parentTypes?: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>;
241
- }
@@ -1,2 +0,0 @@
1
- declare const arrayify: <T>(x: T | T[]) => T[];
2
- export default arrayify;
@@ -1,4 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { DefaultLogTypes, LoggerTypesConfig } from "../types.d.ts";
3
- declare const getLongestBadge: <L extends string, T extends string>(types: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>) => string;
4
- export default getLongestBadge;
@@ -1,4 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { DefaultLogTypes, LoggerTypesConfig } from "../types.d.ts";
3
- declare const getLongestLabel: <L extends string, T extends string>(types: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>) => string;
4
- export default getLongestLabel;
@@ -1,4 +0,0 @@
1
- import type { LiteralUnion } from "type-fest";
2
- import type { DefaultLoggerTypes, DefaultLogTypes, LoggerTypesConfig } from "../types.d.ts";
3
- declare const mergeTypes: <L extends string, T extends string>(standard: DefaultLoggerTypes<L>, custom: LoggerTypesConfig<T, L>) => LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>;
4
- export default mergeTypes;