@visulima/pail 4.0.0-alpha.9 → 4.0.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.
Files changed (145) hide show
  1. package/CHANGELOG.md +519 -0
  2. package/LICENSE.md +270 -166
  3. package/README.md +53 -24
  4. package/dist/error.d.ts +95 -96
  5. package/dist/error.js +5 -76
  6. package/dist/index.browser.d.ts +568 -47
  7. package/dist/index.browser.js +19 -1499
  8. package/dist/index.server.d.ts +749 -65
  9. package/dist/index.server.js +32 -3179
  10. package/dist/middleware/elysia.d.ts +66 -63
  11. package/dist/middleware/elysia.js +1 -70
  12. package/dist/middleware/express.d.ts +74 -71
  13. package/dist/middleware/express.js +1 -29
  14. package/dist/middleware/fastify.d.ts +70 -67
  15. package/dist/middleware/fastify.js +1 -46
  16. package/dist/middleware/hono.d.ts +75 -72
  17. package/dist/middleware/hono.js +1 -33
  18. package/dist/middleware/next/handler.d.ts +102 -34
  19. package/dist/middleware/next/handler.js +1 -53
  20. package/dist/middleware/sveltekit.d.ts +101 -98
  21. package/dist/middleware/sveltekit.js +1 -43
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +1 -0
  26. package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +2 -0
  27. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  28. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CcDdPQSt.js +44 -0
  30. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  31. package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +62 -0
  32. package/dist/packem_shared/abstract-pretty-reporter-DrLBJ6ds.js +57 -0
  33. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +25 -0
  34. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  35. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  36. package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +47 -0
  37. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  38. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  39. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  40. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  41. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  42. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  43. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  44. package/dist/packem_shared/types.d-bWnqHJKL.d.ts +211 -0
  45. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  46. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  47. package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +717 -0
  48. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  49. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  50. package/dist/processor/caller/caller-processor.d.ts +50 -47
  51. package/dist/processor/caller/caller-processor.js +1 -59
  52. package/dist/processor/environment-processor.d.ts +114 -113
  53. package/dist/processor/environment-processor.js +1 -78
  54. package/dist/processor/message-formatter-processor.d.ts +59 -49
  55. package/dist/processor/message-formatter-processor.js +1 -713
  56. package/dist/processor/opentelemetry-processor.d.ts +70 -66
  57. package/dist/processor/opentelemetry-processor.js +1 -52
  58. package/dist/processor/redact-processor.d.ts +99 -41
  59. package/dist/processor/redact-processor.js +1 -30
  60. package/dist/processor/sampling-processor.d.ts +103 -101
  61. package/dist/processor/sampling-processor.js +1 -59
  62. package/dist/reporter/file/json-file-reporter.d.ts +109 -42
  63. package/dist/reporter/file/json-file-reporter.js +2 -136
  64. package/dist/reporter/http/abstract-http-reporter.d.ts +256 -211
  65. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  66. package/dist/reporter/http/http-reporter.d.ts +41 -36
  67. package/dist/reporter/http/http-reporter.edge-light.d.ts +487 -39
  68. package/dist/reporter/http/http-reporter.edge-light.js +2 -733
  69. package/dist/reporter/http/http-reporter.js +1 -13
  70. package/dist/reporter/json/index.browser.d.ts +98 -3
  71. package/dist/reporter/json/index.browser.js +1 -2
  72. package/dist/reporter/json/index.d.ts +53 -3
  73. package/dist/reporter/json/index.js +1 -2
  74. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  75. package/dist/reporter/pretty/index.browser.js +1 -1
  76. package/dist/reporter/pretty/index.d.ts +270 -2
  77. package/dist/reporter/pretty/index.js +1 -1
  78. package/dist/reporter/simple/simple-reporter.server.d.ts +215 -18
  79. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  80. package/dist/wide-event.d.ts +6 -300
  81. package/dist/wide-event.js +1 -281
  82. package/package.json +43 -58
  83. package/dist/constants.d.ts +0 -37
  84. package/dist/interactive/index.d.ts +0 -2
  85. package/dist/interactive/index.js +0 -2
  86. package/dist/interactive/interactive-manager.d.ts +0 -108
  87. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  88. package/dist/middleware/next/middleware.d.ts +0 -59
  89. package/dist/middleware/next/storage.d.ts +0 -14
  90. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  91. package/dist/middleware/shared/headers.d.ts +0 -14
  92. package/dist/middleware/shared/routes.d.ts +0 -30
  93. package/dist/middleware/shared/storage.d.ts +0 -29
  94. package/dist/packem_shared/AbstractJsonReporter-CGKHS8_M.js +0 -286
  95. package/dist/packem_shared/AbstractJsonReporter-DDjDkciI.js +0 -286
  96. package/dist/packem_shared/InteractiveManager-Cd6A14ZK.js +0 -172
  97. package/dist/packem_shared/InteractiveStreamHook-ePIURL_U.js +0 -133
  98. package/dist/packem_shared/JsonReporter-B3XX8GHN.js +0 -58
  99. package/dist/packem_shared/JsonReporter-p_BXg6Sj.js +0 -28
  100. package/dist/packem_shared/PrettyReporter-BYL3NrdA.js +0 -214
  101. package/dist/packem_shared/PrettyReporter-CvBn-hxP.js +0 -1459
  102. package/dist/packem_shared/Spinner-DIdVcfWq.js +0 -2183
  103. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +0 -2602
  104. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  105. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  106. package/dist/packem_shared/createPailError-B11aRfrT.js +0 -76
  107. package/dist/packem_shared/getBarChar-BWj1UrH3.js +0 -404
  108. package/dist/packem_shared/headers-Cp4uLtr4.js +0 -123
  109. package/dist/packem_shared/index-DnkF86LQ.js +0 -658
  110. package/dist/packem_shared/index-frijFf5m.js +0 -1252
  111. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  112. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  113. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  114. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  115. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  116. package/dist/pail.browser.d.ts +0 -412
  117. package/dist/pail.server.d.ts +0 -233
  118. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  119. package/dist/progress-bar.d.ts +0 -136
  120. package/dist/progress-bar.js +0 -404
  121. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  122. package/dist/reporter/http/utils/compression.d.ts +0 -7
  123. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  124. package/dist/reporter/http/utils/retry.d.ts +0 -27
  125. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  126. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  127. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  128. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  129. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  130. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  131. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  132. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  133. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  134. package/dist/reporter/utils/format-label.d.ts +0 -3
  135. package/dist/spinner.d.ts +0 -220
  136. package/dist/spinner.js +0 -2183
  137. package/dist/types.d.ts +0 -241
  138. package/dist/utils/ansi-escapes.d.ts +0 -4
  139. package/dist/utils/arrayify.d.ts +0 -2
  140. package/dist/utils/get-longest-badge.d.ts +0 -4
  141. package/dist/utils/get-longest-label.d.ts +0 -4
  142. package/dist/utils/merge-types.d.ts +0 -4
  143. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  144. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  145. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,24 +0,0 @@
1
- const GLOB_STRIP_RE = /\*+/g;
2
- const pailMiddleware = (NextResponseClass, options) => {
3
- const { exclude, include } = options ?? {};
4
- return (request) => {
5
- const path = request.nextUrl.pathname;
6
- if (exclude?.some((p) => path.startsWith(p.replaceAll(GLOB_STRIP_RE, "")))) {
7
- return NextResponseClass.next();
8
- }
9
- if (include?.length && !include.some((p) => path.startsWith(p.replaceAll(GLOB_STRIP_RE, "")))) {
10
- return NextResponseClass.next();
11
- }
12
- const requestId = request.headers.get("x-request-id") ?? crypto.randomUUID();
13
- const requestHeaders = new Headers(request.headers);
14
- requestHeaders.set("x-request-id", requestId);
15
- requestHeaders.set("x-pail-start", String(Date.now()));
16
- const response = NextResponseClass.next({
17
- request: { headers: requestHeaders }
18
- });
19
- response.headers.set("x-request-id", requestId);
20
- return response;
21
- };
22
- };
23
-
24
- export { pailMiddleware };
@@ -1,36 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- AsyncLocalStorage
22
- } = __cjs_getBuiltinModule("node:async_hooks");
23
-
24
- const createLoggerStorage = (contextHint) => {
25
- const storage = new AsyncLocalStorage();
26
- const useLogger = () => {
27
- const logger = storage.getStore();
28
- if (!logger) {
29
- throw new Error(`[pail] useLogger() called outside of ${contextHint}`);
30
- }
31
- return logger;
32
- };
33
- return { storage, useLogger };
34
- };
35
-
36
- export { createLoggerStorage as c };
@@ -1,33 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- AsyncLocalStorage
22
- } = __cjs_getBuiltinModule("node:async_hooks");
23
-
24
- const pailStorage = new AsyncLocalStorage();
25
- const useLogger = () => {
26
- const logger = pailStorage.getStore();
27
- if (!logger) {
28
- throw new Error("[pail] useLogger() called outside of withPail() context. Wrap your route handler or server action with withPail().");
29
- }
30
- return logger;
31
- };
32
-
33
- export { pailStorage, useLogger };
@@ -1,14 +0,0 @@
1
- const writeConsoleLogBasedOnLevel = (level) => {
2
- if (level === "error") {
3
- return console.__error ?? console.error;
4
- }
5
- if (level === "warn") {
6
- return console.__warn ?? console.warn;
7
- }
8
- if (level === "trace") {
9
- return console.__trace ?? console.trace;
10
- }
11
- return console.__log ?? console.log;
12
- };
13
-
14
- export { writeConsoleLogBasedOnLevel as w };
@@ -1,6 +0,0 @@
1
- const writeStream = (data, stream) => {
2
- const write = stream.__write ?? stream.write;
3
- return write.call(stream, data);
4
- };
5
-
6
- export { writeStream as w };
@@ -1,412 +0,0 @@
1
- import type { stringify } from "safe-stable-stringify";
2
- import type { LiteralUnion } from "type-fest";
3
- import type { ConstructorOptions, DefaultLogTypes, ExtendedRfc5424LogLevels, LoggerFunction, LoggerTypesConfig, Meta, Processor, Reporter } from "./types.d.ts";
4
- /**
5
- * Pail Browser Implementation.
6
- *
7
- * A comprehensive logging library for browser environments with support for
8
- * multiple log levels, custom types, processors, reporters, and advanced features
9
- * like throttling, scoping, timers, and counters.
10
- * @template T - Custom logger types (string union)
11
- * @template L - Log level types (string union)
12
- * @example
13
- * ```typescript
14
- * const logger = new PailBrowserImpl({
15
- * logLevel: "debug",
16
- * types: {
17
- * http: { color: "blue", label: "HTTP", logLevel: "info" }
18
- * },
19
- * reporters: [new JsonReporter()]
20
- * });
21
- *
22
- * logger.info("Application started");
23
- * logger.http("GET /api/users 200");
24
- * logger.error("Something went wrong", error);
25
- * ```
26
- */
27
- export declare class PailBrowserImpl<T extends string = string, L extends string = string> {
28
- #private;
29
- protected timersMap: Map<string, number>;
30
- protected countMap: Map<string, number>;
31
- protected seqTimers: Set<string>;
32
- protected readonly lastLog: {
33
- count?: number;
34
- object?: Meta<L>;
35
- time?: Date;
36
- timeout?: ReturnType<typeof setTimeout>;
37
- };
38
- protected readonly logLevels: Record<string, number>;
39
- protected disabled: boolean;
40
- protected paused: boolean;
41
- protected messageQueue: {
42
- messageObject: any[];
43
- raw: boolean;
44
- type: LiteralUnion<DefaultLogTypes, T>;
45
- }[];
46
- protected scopeName: string[];
47
- protected readonly types: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>;
48
- protected readonly longestLabel: string;
49
- protected readonly processors: Set<Processor<L>>;
50
- protected readonly generalLogLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
51
- protected reporters: Set<Reporter<L>>;
52
- protected readonly throttle: number;
53
- protected readonly throttleMin: number;
54
- protected readonly stringify: typeof stringify;
55
- protected groups: string[];
56
- protected readonly startTimerMessage: string;
57
- protected readonly endTimerMessage: string;
58
- protected rawReporter: Reporter<L>;
59
- protected force: Record<string, LoggerFunction>;
60
- /**
61
- * Creates a new Pail browser logger instance.
62
- *
63
- * Initializes the logger with the provided configuration options,
64
- * setting up reporters, processors, log levels, and other internal state.
65
- * @param options Configuration options for the logger
66
- */
67
- constructor(options: ConstructorOptions<T, L>);
68
- /**
69
- * Wraps the global console methods to redirect them through the logger.
70
- *
71
- * This method replaces console methods (log, info, warn, error, etc.) with
72
- * calls to the corresponding logger methods. The original console methods
73
- * are backed up and can be restored using restoreConsole().
74
- * @example
75
- * ```typescript
76
- * const logger = createPail();
77
- * logger.wrapConsole();
78
- *
79
- * console.log("This will go through the logger");
80
- * console.error("This too!");
81
- *
82
- * logger.restoreConsole(); // Restore original console methods
83
- * ```
84
- */
85
- wrapConsole(): void;
86
- /**
87
- * Restores the original global console methods.
88
- *
89
- * This method restores the console methods that were backed up by wrapConsole().
90
- * After calling this, console methods will work as they did before wrapping.
91
- * @example
92
- * ```typescript
93
- * const logger = createPail();
94
- * logger.wrapConsole();
95
- *
96
- * // Console methods are now wrapped
97
- * logger.restoreConsole();
98
- * // Console methods are restored to original behavior
99
- * ```
100
- */
101
- restoreConsole(): void;
102
- /**
103
- * Wraps uncaught exception and unhandled rejection handlers.
104
- *
105
- * This method sets up global error handlers that will log uncaught exceptions
106
- * and unhandled promise rejections through the logger. This is useful for
107
- * capturing and logging application crashes.
108
- * @example
109
- * ```typescript
110
- * const logger = createPail();
111
- * logger.wrapException();
112
- *
113
- * // Now uncaught errors will be logged
114
- * throw new Error("This will be logged");
115
- * ```
116
- */
117
- wrapException(): void;
118
- /**
119
- * Disables all logging output.
120
- *
121
- * When disabled, all log calls will be silently ignored and no output
122
- * will be produced by any reporters. This can be useful for temporarily
123
- * suppressing log output in production or during testing.
124
- * @example
125
- * ```typescript
126
- * const logger = createPail();
127
- * logger.disable();
128
- * logger.info("This won't be logged"); // Silent
129
- * logger.enable();
130
- * logger.info("This will be logged"); // Output produced
131
- * ```
132
- */
133
- disable(): void;
134
- /**
135
- * Enables logging output.
136
- *
137
- * Re-enables logging after it has been disabled. All subsequent log calls
138
- * will produce output according to the configured reporters.
139
- * @example
140
- * ```typescript
141
- * const logger = createPail();
142
- * logger.disable();
143
- * logger.info("This won't be logged");
144
- * logger.enable(); // Re-enable logging
145
- * logger.info("This will be logged");
146
- * ```
147
- */
148
- enable(): void;
149
- /**
150
- * Checks if logging is currently enabled.
151
- *
152
- * Returns true if logging is enabled and false if it has been disabled.
153
- * @returns True if logging is enabled, false if disabled
154
- * @example
155
- * ```typescript
156
- * const logger = createPail();
157
- * console.log(logger.isEnabled()); // true
158
- * logger.disable();
159
- * console.log(logger.isEnabled()); // false
160
- * ```
161
- */
162
- isEnabled(): boolean;
163
- /**
164
- * Pauses logging and starts queuing messages.
165
- *
166
- * When paused, all log calls will be queued instead of being output immediately.
167
- * The queued messages will be processed when resume() is called. This is useful
168
- * for temporarily buffering log output during critical operations.
169
- * @example
170
- * ```typescript
171
- * const logger = createPail();
172
- * logger.pause();
173
- * logger.info("This will be queued"); // Queued, not output yet
174
- * logger.warn("This too"); // Also queued
175
- * logger.resume(); // Now both messages are output
176
- * ```
177
- */
178
- pause(): void;
179
- /**
180
- * Resumes logging and flushes all queued messages.
181
- *
182
- * Processes all messages that were queued during the pause period and
183
- * resumes normal logging behavior. Messages are output in the order
184
- * they were originally called.
185
- * @example
186
- * ```typescript
187
- * const logger = createPail();
188
- * logger.pause();
189
- * logger.info("Message 1"); // Queued
190
- * logger.info("Message 2"); // Queued
191
- * logger.resume(); // Both messages are now output in order
192
- * logger.info("Message 3"); // Output immediately
193
- * ```
194
- */
195
- resume(): void;
196
- /**
197
- * Creates a scoped logger instance.
198
- *
199
- * Returns a new logger instance that inherits all configuration but adds
200
- * the specified scope names to all log messages. This is useful for
201
- * categorizing logs by component, module, or feature.
202
- * @template N - The new custom logger type names
203
- * @param name Scope names to apply to all log messages
204
- * @returns A new scoped logger instance
205
- * @throws {Error} If no scope name is provided
206
- * @example
207
- * ```typescript
208
- * const logger = createPail();
209
- * const scopedLogger = logger.scope("auth", "login");
210
- * scopedLogger.info("User logged in"); // Will include scope: ["auth", "login"]
211
- * ```
212
- */
213
- scope<N extends string = T>(...name: string[]): PailBrowserType<N, L>;
214
- /**
215
- * Removes the current scope from the logger.
216
- *
217
- * Clears all scope names that were set by previous scope() calls.
218
- * After calling this, log messages will no longer include scope information.
219
- * @example
220
- * ```typescript
221
- * const logger = createPail();
222
- * const scopedLogger = logger.scope("auth");
223
- * scopedLogger.info("Scoped message"); // Has scope
224
- * scopedLogger.unscope();
225
- * scopedLogger.info("Unscoped message"); // No scope
226
- * ```
227
- */
228
- unscope(): void;
229
- /**
230
- * Creates a child logger that inherits settings from the parent.
231
- *
232
- * Returns a new logger instance that inherits all configuration from the parent
233
- * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
234
- * you to override only what you need. Child loggers are independent instances with
235
- * their own state (timers, counters, etc.).
236
- * @template N - The new custom logger type names
237
- * @template LC - The new log level types
238
- * @param options Configuration options to override or extend parent settings
239
- * @returns A new child logger instance
240
- * @example
241
- * ```typescript
242
- * const parent = createPail({
243
- * logLevel: "info",
244
- * types: { http: { label: "HTTP", logLevel: "info" } },
245
- * reporters: [new PrettyReporter()],
246
- * });
247
- *
248
- * // Child inherits parent settings but overrides log level
249
- * const child = parent.child({ logLevel: "debug" });
250
- * child.info("This will be logged"); // Uses debug level from child
251
- * child.http("GET /api 200"); // Inherits http type from parent
252
- *
253
- * // Child can add new types
254
- * const childWithNewType = parent.child({
255
- * types: { db: { label: "DB", logLevel: "info" } },
256
- * });
257
- * childWithNewType.db("Query executed"); // New type available
258
- * ```
259
- */
260
- child<N extends string = T, LC extends string = L>(options?: Partial<ConstructorOptions<N, LC>>): PailBrowserType<N, LC>;
261
- /**
262
- * Starts a timer with the specified label.
263
- *
264
- * Records the current timestamp and associates it with the given label.
265
- * Multiple timers can be active simultaneously with different labels.
266
- * @param label The timer label (defaults to "default")
267
- * @example
268
- * ```typescript
269
- * const logger = createPail();
270
- * logger.time("operation");
271
- * // ... some operation ...
272
- * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
273
- * ```
274
- */
275
- time(label?: string): void;
276
- /**
277
- * Logs the current elapsed time for a timer without stopping it.
278
- *
279
- * Calculates and logs the time elapsed since the timer was started,
280
- * but keeps the timer running. If no label is provided, uses the
281
- * most recently started timer.
282
- * @param label The timer label (uses last timer if not specified)
283
- * @param data Additional data to include in the log message
284
- * @example
285
- * ```typescript
286
- * const logger = createPail();
287
- * logger.time("task");
288
- * // ... some work ...
289
- * logger.timeLog("task"); // Logs current elapsed time
290
- * // ... more work ...
291
- * logger.timeEnd("task"); // Logs final time and stops timer
292
- * ```
293
- */
294
- timeLog(label?: string, ...data: unknown[]): void;
295
- /**
296
- * Stops a timer and logs the final elapsed time.
297
- *
298
- * Calculates the total time elapsed since the timer was started,
299
- * logs the result, and removes the timer. If no label is provided,
300
- * uses the most recently started timer.
301
- * @param label The timer label (uses last timer if not specified)
302
- * @example
303
- * ```typescript
304
- * const logger = createPail();
305
- * logger.time("operation");
306
- * // ... perform operation ...
307
- * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
308
- * ```
309
- */
310
- timeEnd(label?: string): void;
311
- /**
312
- * Starts a log group with the specified label.
313
- *
314
- * Groups related log messages together. In browser environments,
315
- * this uses the native console.group() functionality. In other
316
- * environments, it tracks group nesting internally.
317
- * @param label The group label (defaults to "console.group")
318
- * @example
319
- * ```typescript
320
- * const logger = createPail();
321
- * logger.group("Database Operations");
322
- * logger.info("Connecting to database");
323
- * logger.info("Running migration");
324
- * logger.groupEnd(); // End the group
325
- * ```
326
- */
327
- group(label?: string): void;
328
- /**
329
- * Ends the current log group.
330
- *
331
- * Closes the most recently opened log group. In browser environments,
332
- * this uses the native console.groupEnd() functionality.
333
- * @example
334
- * ```typescript
335
- * const logger = createPail();
336
- * logger.group("Processing");
337
- * logger.info("Step 1");
338
- * logger.info("Step 2");
339
- * logger.groupEnd(); // Closes the "Processing" group
340
- * ```
341
- */
342
- groupEnd(): void;
343
- /**
344
- * Increments and logs a counter with the specified label.
345
- *
346
- * Maintains an internal counter for each label and logs the current count
347
- * each time it's called. Useful for tracking how many times certain
348
- * code paths are executed.
349
- * @param label The counter label (defaults to "default")
350
- * @example
351
- * ```typescript
352
- * const logger = createPail();
353
- * logger.count("requests"); // Logs: "requests: 1"
354
- * logger.count("requests"); // Logs: "requests: 2"
355
- * logger.count("errors"); // Logs: "errors: 1"
356
- * ```
357
- */
358
- count(label?: string): void;
359
- /**
360
- * Resets a counter to zero.
361
- *
362
- * Removes the counter with the specified label, effectively resetting
363
- * it to zero. If the counter doesn't exist, logs a warning.
364
- * @param label The counter label to reset (defaults to "default")
365
- * @example
366
- * ```typescript
367
- * const logger = createPail();
368
- * logger.count("requests"); // Logs: "requests: 1"
369
- * logger.countReset("requests"); // Resets counter
370
- * logger.count("requests"); // Logs: "requests: 1" (starts over)
371
- * ```
372
- */
373
- countReset(label?: string): void;
374
- /**
375
- * Clears the console output.
376
- *
377
- * Calls the native console.clear() method to clear all output from
378
- * the console. This is a convenience method that wraps the native
379
- * console.clear() functionality.
380
- * @example
381
- * ```typescript
382
- * const logger = createPail();
383
- * logger.info("Some message");
384
- * logger.clear(); // Clears the console
385
- * ```
386
- */
387
- clear(): void;
388
- /**
389
- * Logs a raw message bypassing normal processing.
390
- *
391
- * Sends a message directly to the raw reporter without going through
392
- * the normal logging pipeline (processors, throttling, etc.). This is
393
- * useful for logging that needs to bypass all formatting and processing.
394
- * @param message The raw message to log
395
- * @param arguments_ Additional arguments to include
396
- * @example
397
- * ```typescript
398
- * const logger = createPail();
399
- * logger.raw("Direct message", { data: "value" });
400
- * ```
401
- */
402
- raw(message: string, ...arguments_: unknown[]): void;
403
- protected extendReporter(reporter: Reporter<L>): Reporter<L>;
404
- protected registerReporters(reporters: Reporter<L>[]): void;
405
- protected registerProcessors(processors: Processor<L>[]): void;
406
- protected logger(type: LiteralUnion<DefaultLogTypes, T>, raw: boolean, force: boolean, ...messageObject: any[]): void;
407
- }
408
- export type PailBrowserType<T extends string = string, L extends string = string> = Console & (new <TC extends string = string, LC extends string = string>(options?: ConstructorOptions<TC, LC>) => PailBrowserType<TC, LC>) & PailBrowserImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction> & {
409
- force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
410
- };
411
- export type PailConstructor<T extends string = string, L extends string = string> = new (options?: ConstructorOptions<T, L>) => PailBrowserType<T, L>;
412
- export declare const PailBrowser: PailBrowserType;