@controlium/utils 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +10 -0
- package/dist/cjs/detokeniser/detokeniser.js +1135 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/jsonUtils/jsonUtils.js +460 -0
- package/dist/cjs/logger/logger.js +863 -0
- package/dist/cjs/logger/logger.spec.js +875 -0
- package/dist/cjs/logger/types.js +2 -0
- package/dist/cjs/stringUtils/stringUtils.js +294 -0
- package/dist/cjs/utils/utils.js +1050 -0
- package/dist/esm/detokeniser/detokeniser.js +1131 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/jsonUtils/jsonUtils.js +420 -0
- package/dist/esm/logger/logger.js +859 -0
- package/dist/esm/logger/logger.spec.js +873 -0
- package/dist/esm/logger/types.js +1 -0
- package/dist/esm/stringUtils/stringUtils.js +290 -0
- package/dist/esm/utils/utils.js +1043 -0
- package/dist/types/detokeniser/detokeniser.d.ts +402 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/jsonUtils/jsonUtils.d.ts +196 -0
- package/dist/types/logger/logger.d.ts +388 -0
- package/dist/types/logger/logger.spec.d.ts +1 -0
- package/dist/types/logger/types.d.ts +235 -0
- package/dist/types/stringUtils/stringUtils.d.ts +129 -0
- package/dist/types/utils/utils.d.ts +450 -0
- package/package.json +110 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { VideoOptions, WriteLineOptions, LogOutputCallbackSignature } from "./types";
|
|
2
|
+
export declare class Logger {
|
|
3
|
+
/**
|
|
4
|
+
* Numeric log level constants used to control and filter log output.
|
|
5
|
+
*
|
|
6
|
+
* Levels are ordered from highest verbosity to lowest:
|
|
7
|
+
* - `Maximum` / `Verbose` — log everything
|
|
8
|
+
* - `FrameworkDebug` — internal framework debug messages
|
|
9
|
+
* - `FrameworkInformation` — internal framework info messages
|
|
10
|
+
* - `TestDebug` — test-level debug messages
|
|
11
|
+
* - `TestInformation` — test-level info messages
|
|
12
|
+
* - `Warning` — warnings and errors
|
|
13
|
+
* - `Error` — errors only
|
|
14
|
+
* - `NoOutput` — suppress all output
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* Logger.loggingLevel = Logger.Levels.TestInformation;
|
|
18
|
+
*/
|
|
19
|
+
static readonly Levels: {
|
|
20
|
+
/** Maximum verbosity. Same numeric value as `Verbose`. */
|
|
21
|
+
readonly Maximum: number;
|
|
22
|
+
/** Verbose logging. Same numeric value as `Maximum`. */
|
|
23
|
+
readonly Verbose: number;
|
|
24
|
+
/** Framework-level debug logs. */
|
|
25
|
+
readonly FrameworkDebug: 6;
|
|
26
|
+
/** Framework-level informational logs. */
|
|
27
|
+
readonly FrameworkInformation: 5;
|
|
28
|
+
/** Test-level debug logs. */
|
|
29
|
+
readonly TestDebug: 4;
|
|
30
|
+
/** Test-level informational logs. */
|
|
31
|
+
readonly TestInformation: 3;
|
|
32
|
+
/** Warnings (and errors). */
|
|
33
|
+
readonly Warning: 2;
|
|
34
|
+
/** Errors only. */
|
|
35
|
+
readonly Error: 1;
|
|
36
|
+
/** No log output is allowed at this level. */
|
|
37
|
+
readonly NoOutput: 0;
|
|
38
|
+
};
|
|
39
|
+
private static readonly videoResolutionLimits;
|
|
40
|
+
private static options;
|
|
41
|
+
private static startTime;
|
|
42
|
+
/**
|
|
43
|
+
* Callback invoked for every log output (after formatting and preamble generation).
|
|
44
|
+
*
|
|
45
|
+
* If defined, the logger calls this function with:
|
|
46
|
+
* - `message`: The final formatted log line or attached payload.
|
|
47
|
+
* - `mediaType`: Optional MIME-type-style string.
|
|
48
|
+
* Examples:
|
|
49
|
+
* - `"text/plain"` for normal log lines
|
|
50
|
+
* - `"text/html"` for HTML attachments
|
|
51
|
+
* - `"base64:image/png"` for screenshots
|
|
52
|
+
*
|
|
53
|
+
* If the callback throws, the logger catches the error and processes it,
|
|
54
|
+
* reporting to the test suite if required.
|
|
55
|
+
*
|
|
56
|
+
* Set this to `undefined` (or call `Logger.clearOutputCallback()`) to disable callback output.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* Logger.logOutputCallback = (message, mediaType) => {
|
|
60
|
+
* myReporter.attach(message, mediaType ?? "text/plain");
|
|
61
|
+
* };
|
|
62
|
+
*/
|
|
63
|
+
static logOutputCallback: LogOutputCallbackSignature | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Resets the logger to its default configuration.
|
|
66
|
+
*
|
|
67
|
+
* Clears the output callback and restores all options to their default values.
|
|
68
|
+
* Optionally resets the elapsed-time start point to the current moment.
|
|
69
|
+
*
|
|
70
|
+
* @param resetStartTime - When `true`, the start time used for elapsed-time
|
|
71
|
+
* calculation is reset to now. When `false` (the default), the existing
|
|
72
|
+
* start time is preserved so elapsed time continues from the original baseline.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* Logger.reset(); // Reset options only, keep elapsed-time baseline
|
|
76
|
+
* Logger.reset(true); // Reset options and restart the elapsed timer
|
|
77
|
+
*/
|
|
78
|
+
static reset(resetStartTime?: boolean): void;
|
|
79
|
+
/**
|
|
80
|
+
* Controls whether log output is written to the console.
|
|
81
|
+
*
|
|
82
|
+
* When `true`, every log line is written to `console.log()` in addition
|
|
83
|
+
* to any configured {@link logOutputCallback}.
|
|
84
|
+
* When `false`, output is sent only to the callback (if defined).
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* Logger.logToConsole = true;
|
|
88
|
+
*/
|
|
89
|
+
static set logToConsole(value: boolean);
|
|
90
|
+
/**
|
|
91
|
+
* Returns whether log output is currently being written to the console.
|
|
92
|
+
*
|
|
93
|
+
* @returns `true` if console logging is enabled; otherwise `false`.
|
|
94
|
+
*/
|
|
95
|
+
static get logToConsole(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Enables or disables Panic Mode.
|
|
98
|
+
*
|
|
99
|
+
* When `true`, the current log level is ignored and all log calls produce
|
|
100
|
+
* output — equivalent to setting the log level to `Verbose`.
|
|
101
|
+
* When `false`, normal log-level filtering applies.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* Logger.panicMode = true; // Force all output regardless of log level
|
|
105
|
+
*/
|
|
106
|
+
static set panicMode(value: boolean);
|
|
107
|
+
/**
|
|
108
|
+
* Returns whether Panic Mode is currently active.
|
|
109
|
+
*
|
|
110
|
+
* When `true`, all log output is written regardless of the configured log level.
|
|
111
|
+
*
|
|
112
|
+
* @returns `true` if Panic Mode is enabled; otherwise `false`.
|
|
113
|
+
*/
|
|
114
|
+
static get panicMode(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Controls whether an exception is thrown when a log-output operation fails.
|
|
117
|
+
*
|
|
118
|
+
* When `true`, any error raised while executing the configured
|
|
119
|
+
* {@link logOutputCallback} is re-thrown to the caller.
|
|
120
|
+
* When `false`, such errors are suppressed and logged internally instead.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* Logger.throwErrorIfLogOutputFails = true;
|
|
124
|
+
*/
|
|
125
|
+
static set throwErrorIfLogOutputFails(value: boolean);
|
|
126
|
+
/**
|
|
127
|
+
* Returns whether log-output failures are re-thrown as exceptions.
|
|
128
|
+
*
|
|
129
|
+
* @returns `true` if logging errors are propagated to the caller;
|
|
130
|
+
* `false` if they are suppressed and logged internally.
|
|
131
|
+
*/
|
|
132
|
+
static get throwErrorIfLogOutputFails(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Returns the current global logging level.
|
|
135
|
+
*
|
|
136
|
+
* Only messages with a level less than or equal to this value
|
|
137
|
+
* (or within the configured {@link loggingFilter} range) will be output.
|
|
138
|
+
*
|
|
139
|
+
* @returns The current numeric log level.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link Levels} for named level constants.
|
|
142
|
+
*/
|
|
143
|
+
static get loggingLevel(): number;
|
|
144
|
+
/**
|
|
145
|
+
* Sets the global logging level.
|
|
146
|
+
*
|
|
147
|
+
* Accepts a named level string (case-insensitive, spaces ignored),
|
|
148
|
+
* or a non-negative integer. Unknown strings and invalid numbers
|
|
149
|
+
* fall back to `FrameworkDebug` and emit a warning.
|
|
150
|
+
*
|
|
151
|
+
* @param requiredLevel - The desired level as a `Levels` constant, number, or string.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* Logger.loggingLevel = Logger.Levels.Warning;
|
|
155
|
+
* Logger.loggingLevel = 3;
|
|
156
|
+
* Logger.loggingLevel = "TestInformation";
|
|
157
|
+
*/
|
|
158
|
+
static set loggingLevel(requiredLevel: string | number);
|
|
159
|
+
/**
|
|
160
|
+
* Returns the current logging level as a human-readable string.
|
|
161
|
+
*
|
|
162
|
+
* @returns A descriptive string for the current log level,
|
|
163
|
+
* e.g. `"Test information (TSINF)"`.
|
|
164
|
+
*/
|
|
165
|
+
static get loggingLevelText(): string;
|
|
166
|
+
/**
|
|
167
|
+
* Builds a human-readable description of the active logging configuration,
|
|
168
|
+
* combining the current level with any active filter range.
|
|
169
|
+
*
|
|
170
|
+
* Includes a Panic Mode preamble prefix when {@link panicMode} is active.
|
|
171
|
+
*
|
|
172
|
+
* @param level - The current logging level.
|
|
173
|
+
* @param minLevel - The minimum level of the active filter range (`NoOutput` if no filter).
|
|
174
|
+
* @param maxLevel - The maximum level of the active filter range (`NoOutput` if no filter).
|
|
175
|
+
* @returns A descriptive string. Returns the plain level name when no valid
|
|
176
|
+
* filter range is active.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* Logger.loggingLevelDescription(Logger.Levels.FrameworkDebug, Logger.Levels.NoOutput, Logger.Levels.NoOutput);
|
|
180
|
+
* // => "Framework debug (FKDBG)"
|
|
181
|
+
*/
|
|
182
|
+
static loggingLevelDescription(level: number, minLevel: number, maxLevel: number): string;
|
|
183
|
+
/**
|
|
184
|
+
* Returns the current log-level filter range.
|
|
185
|
+
*
|
|
186
|
+
* When both `min` and `max` are `NoOutput` (i.e. `0`), no filter is active
|
|
187
|
+
* and only {@link loggingLevel} controls output.
|
|
188
|
+
* When a valid range is set, messages whose level falls within
|
|
189
|
+
* `[min, max]` are also output regardless of the current logging level.
|
|
190
|
+
*
|
|
191
|
+
* @returns An object with `min` and `max` numeric level values.
|
|
192
|
+
*/
|
|
193
|
+
static get loggingFilter(): {
|
|
194
|
+
min: number;
|
|
195
|
+
max: number;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Sets a log-level filter range for additional output inclusion.
|
|
199
|
+
*
|
|
200
|
+
* Messages whose level falls within `[min, max]` will be output even if
|
|
201
|
+
* they fall outside the current {@link loggingLevel}. Pass `NoOutput` (or
|
|
202
|
+
* omit) for either bound to disable that side of the filter.
|
|
203
|
+
*
|
|
204
|
+
* Both bounds accept a named level string or a non-negative integer.
|
|
205
|
+
* Invalid values fall back to `NoOutput` and emit a warning.
|
|
206
|
+
*
|
|
207
|
+
* @param min - Lower bound of the filter range (inclusive).
|
|
208
|
+
* @param max - Upper bound of the filter range (inclusive).
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* Logger.loggingFilter = { min: Logger.Levels.Error, max: Logger.Levels.Warning };
|
|
212
|
+
*/
|
|
213
|
+
static set loggingFilter({ min, max }: {
|
|
214
|
+
min?: string | number;
|
|
215
|
+
max?: string | number;
|
|
216
|
+
});
|
|
217
|
+
/**
|
|
218
|
+
* Returns the current `writeLine` formatting options.
|
|
219
|
+
*
|
|
220
|
+
* These control preamble suppression, max lines, timestamp format,
|
|
221
|
+
* and elapsed time format for log lines written via {@link writeLine}.
|
|
222
|
+
*
|
|
223
|
+
* @returns The active {@link WriteLineOptions} configuration object.
|
|
224
|
+
*/
|
|
225
|
+
static get writeLineOptions(): WriteLineOptions;
|
|
226
|
+
/**
|
|
227
|
+
* Returns the current video attachment options.
|
|
228
|
+
*
|
|
229
|
+
* These defaults are used by {@link attachVideo} and {@link attachVideoFile}
|
|
230
|
+
* when no explicit options are provided.
|
|
231
|
+
*
|
|
232
|
+
* @returns The active {@link VideoOptions} configuration object.
|
|
233
|
+
*/
|
|
234
|
+
static get videoOptions(): VideoOptions;
|
|
235
|
+
/**
|
|
236
|
+
* Sets the video attachment options used when attaching video to log output.
|
|
237
|
+
*
|
|
238
|
+
* Provided values are merged with the current options. If `height` or `width`
|
|
239
|
+
* fall outside the valid resolution limits, both dimensions are ignored and
|
|
240
|
+
* the existing values are retained.
|
|
241
|
+
*
|
|
242
|
+
* @param options - Partial or full {@link VideoOptions} to apply.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* Logger.videoOptions = { videoCodec: "mp4", width: 1280, height: 720 };
|
|
246
|
+
*/
|
|
247
|
+
static set videoOptions(options: VideoOptions);
|
|
248
|
+
/**
|
|
249
|
+
* Clears the {@link logOutputCallback}, disabling callback-based log output.
|
|
250
|
+
*
|
|
251
|
+
* After calling this, log output will only go to the console
|
|
252
|
+
* (if {@link logToConsole} is `true`), or be silently dropped.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* Logger.clearOutputCallback();
|
|
256
|
+
*/
|
|
257
|
+
static clearOutputCallback(): void;
|
|
258
|
+
/**
|
|
259
|
+
* Attaches a screenshot to the log output at the specified log level.
|
|
260
|
+
*
|
|
261
|
+
* The screenshot is base64-encoded and passed to {@link logOutputCallback}
|
|
262
|
+
* with a media type of `"base64:image/png"`. Accepts either a raw `Buffer`
|
|
263
|
+
* or an existing base64 string.
|
|
264
|
+
*
|
|
265
|
+
* Has no effect if the given `logLevel` does not pass the current level filter.
|
|
266
|
+
*
|
|
267
|
+
* @param logLevel - The log level at which to attach the screenshot.
|
|
268
|
+
* @param screenshot - A `Buffer` containing raw PNG data, or a base64-encoded string.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* Logger.attachScreenshot(Logger.Levels.TestDebug, screenshotBuffer);
|
|
272
|
+
*/
|
|
273
|
+
static attachScreenshot(logLevel: number, screenshot: Buffer | string): void;
|
|
274
|
+
/**
|
|
275
|
+
* Attaches an HTML string to the log output at the specified log level.
|
|
276
|
+
*
|
|
277
|
+
* The HTML is passed to {@link logOutputCallback} with a media type of `"text/html"`.
|
|
278
|
+
* Useful for attaching rich content such as tables or styled reports.
|
|
279
|
+
*
|
|
280
|
+
* Has no effect if the given `logLevel` does not pass the current level filter.
|
|
281
|
+
*
|
|
282
|
+
* @param logLevel - The log level at which to attach the HTML.
|
|
283
|
+
* @param htmlString - A valid HTML string to attach.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* Logger.attachHTML(Logger.Levels.TestInformation, "<b>Test passed</b>");
|
|
287
|
+
*/
|
|
288
|
+
static attachHTML(logLevel: number, htmlString: string): void;
|
|
289
|
+
/**
|
|
290
|
+
* Reads a video file from disk and attaches it to the log output.
|
|
291
|
+
*
|
|
292
|
+
* The file at `videoFilePath` is read as a `Buffer` and passed to
|
|
293
|
+
* {@link attachVideo}. If the file cannot be read, an error is processed
|
|
294
|
+
* via {@link throwErrorIfLogOutputFails}.
|
|
295
|
+
*
|
|
296
|
+
* Has no effect if the given `logLevel` does not pass the current level filter.
|
|
297
|
+
*
|
|
298
|
+
* @param logLevel - The log level at which to attach the video.
|
|
299
|
+
* @param videoFilePath - Absolute or relative path to the video file.
|
|
300
|
+
* @param options - Optional {@link VideoOptions} overriding the current defaults.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* Logger.attachVideoFile(Logger.Levels.TestDebug, "./recordings/run.webm");
|
|
304
|
+
*/
|
|
305
|
+
static attachVideoFile(logLevel: number, videoFilePath: string, options?: VideoOptions): void;
|
|
306
|
+
/**
|
|
307
|
+
* Attaches a video buffer to the log output at the specified log level.
|
|
308
|
+
*
|
|
309
|
+
* The video is base64-encoded and wrapped in an HTML `<video>` element,
|
|
310
|
+
* then passed to {@link logOutputCallback} with a media type of `"text/html"`.
|
|
311
|
+
* When {@link panicMode} is active, the video element is given a
|
|
312
|
+
* `title="PANIC_MODE"` attribute.
|
|
313
|
+
*
|
|
314
|
+
* Has no effect if the given `logLevel` does not pass the current level filter.
|
|
315
|
+
*
|
|
316
|
+
* @param logLevel - The log level at which to attach the video.
|
|
317
|
+
* @param video - A `Buffer` containing the raw video data.
|
|
318
|
+
* @param options - Optional {@link VideoOptions} overriding the current defaults.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* Logger.attachVideo(Logger.Levels.TestDebug, videoBuffer, { width: 640, height: 360 });
|
|
322
|
+
*/
|
|
323
|
+
static attachVideo(logLevel: number, video: Buffer, options?: VideoOptions): void;
|
|
324
|
+
/**
|
|
325
|
+
* Passes arbitrary data to the {@link logOutputCallback} at the specified log level.
|
|
326
|
+
*
|
|
327
|
+
* If the callback is not set, an error is logged instead. If the callback throws,
|
|
328
|
+
* the error is processed via {@link throwErrorIfLogOutputFails}.
|
|
329
|
+
*
|
|
330
|
+
* Has no effect if the given `logLevel` does not pass the current level filter.
|
|
331
|
+
*
|
|
332
|
+
* @param logLevel - The log level at which to attach the data.
|
|
333
|
+
* @param dataString - The data payload to pass to the callback.
|
|
334
|
+
* @param mediaType - A MIME-type-style string describing the data
|
|
335
|
+
* (e.g. `"text/html"`, `"base64:image/png"`).
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* Logger.attach(Logger.Levels.TestDebug, myPayload, "text/plain");
|
|
339
|
+
*/
|
|
340
|
+
static attach(logLevel: number, dataString: string, mediaType: string): void;
|
|
341
|
+
/**
|
|
342
|
+
* Writes a log line (or multiple lines) at the specified log level.
|
|
343
|
+
*
|
|
344
|
+
* Multi-line strings are split and each line is written individually.
|
|
345
|
+
* If the total number of lines exceeds `maxLines`, intermediate lines
|
|
346
|
+
* are replaced with a single truncation notice.
|
|
347
|
+
*
|
|
348
|
+
* Each line is prefixed with a preamble (timestamp, elapsed time, calling method,
|
|
349
|
+
* and level label) unless suppressed via `options` or the global
|
|
350
|
+
* {@link writeLineOptions} configuration.
|
|
351
|
+
*
|
|
352
|
+
* Has no effect if the given `logLevel` does not pass the current level filter
|
|
353
|
+
* (unless {@link panicMode} is active).
|
|
354
|
+
*
|
|
355
|
+
* @param logLevel - The log level at which to write the message.
|
|
356
|
+
* @param textString - The message to log. May contain newlines.
|
|
357
|
+
* @param options - Optional per-call overrides for {@link WriteLineOptions}.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* Logger.writeLine(Logger.Levels.TestInformation, "Test started");
|
|
361
|
+
* Logger.writeLine(Logger.Levels.Warning, "Something looks off", { suppressAllPreamble: true });
|
|
362
|
+
*/
|
|
363
|
+
static writeLine(logLevel: number, textString: string, options?: WriteLineOptions): void;
|
|
364
|
+
/** Builds a fresh default options object. Extracted so both the field initialiser and reset() share one source of truth. */
|
|
365
|
+
private static buildDefaultOptions;
|
|
366
|
+
private static levelToText;
|
|
367
|
+
private static levelFromText;
|
|
368
|
+
private static checkAndGetVideoResolution;
|
|
369
|
+
private static doWriteLine;
|
|
370
|
+
private static getPreAmble;
|
|
371
|
+
/**
|
|
372
|
+
* Left-pads a number (or numeric string) with zeroes to reach the required minimum length.
|
|
373
|
+
* Kept private and self-contained so `logger.ts` has no external utility dependencies.
|
|
374
|
+
*/
|
|
375
|
+
private static pad;
|
|
376
|
+
private static getWriteTypeString;
|
|
377
|
+
private static callingMethodDetails;
|
|
378
|
+
private static isValidVideoResolutionNumber;
|
|
379
|
+
private static logLevelOk;
|
|
380
|
+
private static processError;
|
|
381
|
+
/**
|
|
382
|
+
* Truncates a string for safe display in error messages.
|
|
383
|
+
* Shows the first {@link ERROR_DISPLAY_STRING_HEAD_LENGTH} characters, an ellipsis,
|
|
384
|
+
* and the last {@link ERROR_DISPLAY_STRING_TAIL_LENGTH} characters when the string
|
|
385
|
+
* exceeds {@link ERROR_DISPLAY_STRING_MAX_LENGTH}.
|
|
386
|
+
*/
|
|
387
|
+
private static truncateForDisplay;
|
|
388
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A numeric log level value, as defined by {@link Logger.Levels}.
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = number;
|
|
5
|
+
/**
|
|
6
|
+
* Options controlling how attached video content is encoded and sized.
|
|
7
|
+
*
|
|
8
|
+
* All fields are optional — omitted values fall back to the Logger's
|
|
9
|
+
* current video defaults. Use {@link ResolvedVideoOptions} where all
|
|
10
|
+
* fields are guaranteed to be present (i.e. after merging with defaults).
|
|
11
|
+
*/
|
|
12
|
+
export interface VideoOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Video codec identifier embedded in the `<video>` tag's MIME type.
|
|
15
|
+
*
|
|
16
|
+
* @example "webm"
|
|
17
|
+
* @example "mp4"
|
|
18
|
+
*/
|
|
19
|
+
videoCodec?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Output video width in pixels.
|
|
22
|
+
* Must fall within the Logger's internal min/max resolution limits.
|
|
23
|
+
* If invalid, both width and height are ignored and the current defaults are kept.
|
|
24
|
+
*/
|
|
25
|
+
width?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Output video height in pixels.
|
|
28
|
+
* Must fall within the Logger's internal min/max resolution limits.
|
|
29
|
+
* If invalid, both width and height are ignored and the current defaults are kept.
|
|
30
|
+
*/
|
|
31
|
+
height?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A fully-resolved video options object in which all fields are guaranteed present.
|
|
35
|
+
*
|
|
36
|
+
* Used internally by `Logger` after merging any user-supplied {@link VideoOptions}
|
|
37
|
+
* with the configured defaults. Stored on {@link Options.video} so read sites
|
|
38
|
+
* never need to null-guard individual fields.
|
|
39
|
+
*/
|
|
40
|
+
export interface ResolvedVideoOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Video codec identifier embedded in the `<video>` tag's MIME type.
|
|
43
|
+
*
|
|
44
|
+
* @example "webm"
|
|
45
|
+
* @example "mp4"
|
|
46
|
+
*/
|
|
47
|
+
videoCodec: string;
|
|
48
|
+
/** Output video width in pixels. */
|
|
49
|
+
width: number;
|
|
50
|
+
/** Output video height in pixels. */
|
|
51
|
+
height: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Controls how {@link Logger.writeLine} formats and emits its output.
|
|
55
|
+
*
|
|
56
|
+
* All fields are optional — omitted values fall back to the Logger's
|
|
57
|
+
* current `writeLineOptions` defaults. Options can be supplied per-call
|
|
58
|
+
* to override defaults for a single `writeLine` invocation.
|
|
59
|
+
*/
|
|
60
|
+
export interface WriteLineOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Maximum number of lines emitted from a multi-line input string.
|
|
63
|
+
*
|
|
64
|
+
* When the input contains more lines than this limit, intermediate lines
|
|
65
|
+
* are dropped and replaced with a single truncation notice showing how
|
|
66
|
+
* many lines were skipped. The first and last lines are always preserved.
|
|
67
|
+
*
|
|
68
|
+
* A value less than `1` is treated as `1`.
|
|
69
|
+
*/
|
|
70
|
+
maxLines?: number;
|
|
71
|
+
/**
|
|
72
|
+
* When `true`, the preamble is suppressed for every line after the first
|
|
73
|
+
* in a multi-line message. The first line still receives a full preamble.
|
|
74
|
+
*
|
|
75
|
+
* Has no effect when {@link suppressAllPreamble} is `true`.
|
|
76
|
+
*/
|
|
77
|
+
suppressMultilinePreamble?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* When `true`, the preamble is suppressed for every output line,
|
|
80
|
+
* whether the input is single-line or multi-line.
|
|
81
|
+
*
|
|
82
|
+
* Takes precedence over {@link suppressMultilinePreamble}.
|
|
83
|
+
*/
|
|
84
|
+
suppressAllPreamble?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* When `true`, the wall-clock timestamp is omitted from the preamble.
|
|
87
|
+
*
|
|
88
|
+
* Has no effect when {@link suppressAllPreamble} is `true`.
|
|
89
|
+
*/
|
|
90
|
+
suppressTimeStamp?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* When `true`, the elapsed-time value is omitted from the preamble.
|
|
93
|
+
*
|
|
94
|
+
* Has no effect when {@link suppressAllPreamble} is `true`.
|
|
95
|
+
*/
|
|
96
|
+
suppressElapsed?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Format string for the wall-clock timestamp, using date-fns syntax.
|
|
99
|
+
*
|
|
100
|
+
* Has no effect when {@link suppressTimeStamp} or {@link suppressAllPreamble}
|
|
101
|
+
* is `true`.
|
|
102
|
+
*
|
|
103
|
+
* @example "HH:mm:ss"
|
|
104
|
+
*/
|
|
105
|
+
timeFormat?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Format string for the elapsed time since the logger was started or last
|
|
108
|
+
* reset, using date-fns syntax.
|
|
109
|
+
*
|
|
110
|
+
* Has no effect when {@link suppressElapsed} or {@link suppressAllPreamble}
|
|
111
|
+
* is `true`.
|
|
112
|
+
*
|
|
113
|
+
* @example "mm:ss.SSS"
|
|
114
|
+
*/
|
|
115
|
+
elapsedFormat?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Number of additional call-stack frames to skip when determining the
|
|
118
|
+
* call-site label shown in the preamble.
|
|
119
|
+
*
|
|
120
|
+
* By default (`0` or `undefined`), the preamble shows the location of the
|
|
121
|
+
* `writeLine` call itself. Increase this when `writeLine` is invoked from
|
|
122
|
+
* inside a helper or wrapper and you want the preamble to reflect where
|
|
123
|
+
* *that wrapper* was called from rather than the wrapper's own location.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // Without stackOffset the preamble shows the helper's location:
|
|
127
|
+
* // "myLogHelper (myLogHelper.ts:12:5)"
|
|
128
|
+
* //
|
|
129
|
+
* // With stackOffset = 1 it shows the helper's caller instead:
|
|
130
|
+
* // "MyTest.someStep (myTest.ts:45:3)"
|
|
131
|
+
* Logger.writeLine(Logger.Levels.TestInformation, message, { stackOffset: 1 });
|
|
132
|
+
*
|
|
133
|
+
* @remarks Not yet implemented — reserved for a future release.
|
|
134
|
+
*/
|
|
135
|
+
stackOffset?: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* General logging behaviour configuration used internally by `Logger`.
|
|
139
|
+
*
|
|
140
|
+
* Consumers should not construct this type directly. Use `Logger.reset()` to
|
|
141
|
+
* initialise the logger and the public getters/setters to modify individual
|
|
142
|
+
* settings at runtime.
|
|
143
|
+
*/
|
|
144
|
+
export interface Options {
|
|
145
|
+
/**
|
|
146
|
+
* The currently active log level.
|
|
147
|
+
*
|
|
148
|
+
* Messages whose level is less than or equal to this value are output
|
|
149
|
+
* (unless overridden by {@link filterMinCurrentLevel}/{@link filterMaxCurrentLevel}
|
|
150
|
+
* or {@link panicMode}).
|
|
151
|
+
*/
|
|
152
|
+
loggingCurrentLevel: number;
|
|
153
|
+
/**
|
|
154
|
+
* Lower bound of the optional level-filter range (inclusive).
|
|
155
|
+
*
|
|
156
|
+
* Messages whose level falls within `[filterMinCurrentLevel, filterMaxCurrentLevel]`
|
|
157
|
+
* are output regardless of {@link loggingCurrentLevel}.
|
|
158
|
+
* Set to `Logger.Levels.NoOutput` when no filter is active.
|
|
159
|
+
*/
|
|
160
|
+
filterMinCurrentLevel: number;
|
|
161
|
+
/**
|
|
162
|
+
* Upper bound of the optional level-filter range (inclusive).
|
|
163
|
+
*
|
|
164
|
+
* Messages whose level falls within `[filterMinCurrentLevel, filterMaxCurrentLevel]`
|
|
165
|
+
* are output regardless of {@link loggingCurrentLevel}.
|
|
166
|
+
* Set to `Logger.Levels.NoOutput` when no filter is active.
|
|
167
|
+
*/
|
|
168
|
+
filterMaxCurrentLevel: number;
|
|
169
|
+
/**
|
|
170
|
+
* When `true`, log lines are also written to `console.log()` in addition
|
|
171
|
+
* to any configured {@link LogOutputCallbackSignature output callback}.
|
|
172
|
+
* When `false`, output goes only to the callback (if one is set).
|
|
173
|
+
*/
|
|
174
|
+
logToConsole: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* When `true`, any error thrown inside the output callback is re-thrown
|
|
177
|
+
* to the caller after being logged internally.
|
|
178
|
+
* When `false`, callback errors are suppressed and only logged internally.
|
|
179
|
+
*/
|
|
180
|
+
throwErrorIfLogOutputFails: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* When `true`, the current log level is ignored and every output call
|
|
183
|
+
* produces output — equivalent to setting {@link loggingCurrentLevel}
|
|
184
|
+
* to `Number.MAX_SAFE_INTEGER`.
|
|
185
|
+
*/
|
|
186
|
+
panicMode: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Short prefix code prepended to the write-type label in each preamble
|
|
189
|
+
* when {@link panicMode} is active.
|
|
190
|
+
*
|
|
191
|
+
* @example "P"
|
|
192
|
+
*/
|
|
193
|
+
panicCodePreamble: string;
|
|
194
|
+
/**
|
|
195
|
+
* Longer descriptor prefix prepended to level-description strings
|
|
196
|
+
* when {@link panicMode} is active.
|
|
197
|
+
*
|
|
198
|
+
* @example "P: "
|
|
199
|
+
*/
|
|
200
|
+
panicDescriptorPreamble: string;
|
|
201
|
+
/** Active formatting options applied by {@link Logger.writeLine}. */
|
|
202
|
+
writeLine: WriteLineOptions;
|
|
203
|
+
/**
|
|
204
|
+
* Active video attachment options.
|
|
205
|
+
*
|
|
206
|
+
* Stored as {@link ResolvedVideoOptions} (all fields required) so that
|
|
207
|
+
* read sites inside `Logger` never need to null-guard individual properties.
|
|
208
|
+
*/
|
|
209
|
+
video: ResolvedVideoOptions;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Signature of the callback invoked for every log output line or data attachment.
|
|
213
|
+
*
|
|
214
|
+
* Assign an implementation to `Logger.logOutputCallback` to receive all log
|
|
215
|
+
* output through a custom handler (e.g. a test reporter's `attach` method).
|
|
216
|
+
*
|
|
217
|
+
* If the callback throws, `Logger` catches the error and handles it according
|
|
218
|
+
* to the {@link Options.throwErrorIfLogOutputFails} setting.
|
|
219
|
+
*
|
|
220
|
+
* @param message - The fully formatted log line, or the raw data payload for
|
|
221
|
+
* attachments (screenshot, video, HTML).
|
|
222
|
+
* @param mediaType - Optional MIME-type-style content descriptor indicating how
|
|
223
|
+
* `message` should be interpreted. Examples:
|
|
224
|
+
* - `"text/plain"` — a normal formatted log line (default when omitted)
|
|
225
|
+
* - `"text/html"` — an HTML attachment
|
|
226
|
+
* - `"base64:image/png"` — a base64-encoded PNG screenshot
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* Logger.logOutputCallback = (message, mediaType) => {
|
|
230
|
+
* myReporter.attach(message, { contentType: mediaType ?? "text/plain" });
|
|
231
|
+
* };
|
|
232
|
+
*/
|
|
233
|
+
export interface LogOutputCallbackSignature {
|
|
234
|
+
(message: string, mediaType?: string): void;
|
|
235
|
+
}
|