@applitools/logger
Advanced tools
| "use strict"; | ||
| // Process-global bounded log ring. No imports — avoids a printer.ts → logger.ts cycle. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.__resetLogBufferForTests = exports.isLogBufferActive = exports.disableLogBuffer = exports.onLogBufferFull = exports.consumeLogBuffer = exports.appendToLogBuffer = void 0; | ||
| const LOG_BUFFER_MAX_ENTRIES = 50000; | ||
| const LOG_BUFFER_MAX_CHARS = 8000000; | ||
| let logBuffer = []; | ||
| let logBufferChars = 0; | ||
| let onFull; | ||
| // eslint-disable-next-line no-control-regex | ||
| const ANSI_REGEX = /\x1b\[[0-9;]*m/g; | ||
| /** @internal Append one formatted+masked line; no-op once disabled. On overflow, | ||
| * calls the full-handler if set, else drops oldest. */ | ||
| function appendToLogBuffer(line) { | ||
| if (!logBuffer) | ||
| return; | ||
| logBuffer.push(line); | ||
| logBufferChars += line.length; | ||
| if (logBuffer.length > LOG_BUFFER_MAX_ENTRIES || logBufferChars > LOG_BUFFER_MAX_CHARS) { | ||
| if (onFull) | ||
| onFull(); | ||
| else { | ||
| const dropped = logBuffer.shift(); | ||
| if (dropped) | ||
| logBufferChars -= dropped.length; | ||
| } | ||
| } | ||
| } | ||
| exports.appendToLogBuffer = appendToLogBuffer; | ||
| /** @internal Join lines, strip ANSI, clear, and return the text ('' if empty/disabled). */ | ||
| function consumeLogBuffer() { | ||
| if (!logBuffer) | ||
| return ''; | ||
| const text = logBuffer.length ? logBuffer.join('\n') + '\n' : ''; | ||
| logBuffer = []; | ||
| logBufferChars = 0; | ||
| return text.replace(ANSI_REGEX, ''); | ||
| } | ||
| exports.consumeLogBuffer = consumeLogBuffer; | ||
| /** @internal Register the on-full handler (last wins; `undefined` unregisters). */ | ||
| function onLogBufferFull(cb) { | ||
| onFull = cb; | ||
| } | ||
| exports.onLogBufferFull = onLogBufferFull; | ||
| /** @internal Permanently stop capturing for this process (opt-out path). Frees the ring. */ | ||
| function disableLogBuffer() { | ||
| logBuffer = undefined; | ||
| logBufferChars = 0; | ||
| onFull = undefined; | ||
| } | ||
| exports.disableLogBuffer = disableLogBuffer; | ||
| /** @internal True until `disableLogBuffer()` has run. */ | ||
| function isLogBufferActive() { | ||
| return logBuffer !== undefined; | ||
| } | ||
| exports.isLogBufferActive = isLogBufferActive; | ||
| /** @internal Test-only: reset to a fresh, enabled ring. */ | ||
| function __resetLogBufferForTests() { | ||
| logBuffer = []; | ||
| logBufferChars = 0; | ||
| onFull = undefined; | ||
| } | ||
| exports.__resetLogBufferForTests = __resetLogBufferForTests; |
| /** @internal Append one formatted+masked line; no-op once disabled. On overflow, | ||
| * calls the full-handler if set, else drops oldest. */ | ||
| export declare function appendToLogBuffer(line: string): void; | ||
| /** @internal Join lines, strip ANSI, clear, and return the text ('' if empty/disabled). */ | ||
| export declare function consumeLogBuffer(): string; | ||
| /** @internal Register the on-full handler (last wins; `undefined` unregisters). */ | ||
| export declare function onLogBufferFull(cb: (() => void) | undefined): void; | ||
| /** @internal Permanently stop capturing for this process (opt-out path). Frees the ring. */ | ||
| export declare function disableLogBuffer(): void; | ||
| /** @internal True until `disableLogBuffer()` has run. */ | ||
| export declare function isLogBufferActive(): boolean; | ||
| /** @internal Test-only: reset to a fresh, enabled ring. */ | ||
| export declare function __resetLogBufferForTests(): void; |
+15
-0
| # Changelog | ||
| ## [2.3.0](https://github.com/Applitools-Dev/sdk/compare/js/logger@2.2.13...js/logger@2.3.0) (2026-06-28) | ||
| ### Features | ||
| * stream SDK logs to Azure Blob per server flag | AD-13401 ([#3849](https://github.com/Applitools-Dev/sdk/issues/3849)) ([7f9dfec](https://github.com/Applitools-Dev/sdk/commit/7f9dfecd874aefc33104db015451a22eee500324)) | ||
| ### Dependencies | ||
| * @applitools/utils bumped to 1.15.1 | ||
| #### Bug Fixes | ||
| * updated extract git fallback logic | FLD-4492 ([#3831](https://github.com/Applitools-Dev/sdk/issues/3831)) ([0d98f3c](https://github.com/Applitools-Dev/sdk/commit/0d98f3cdf828eff756ffbfc5d4cdff7b19a20557)) | ||
| ## [2.2.13](https://github.com/Applitools-Dev/sdk/compare/js/logger@2.2.12...js/logger@2.2.13) (2026-06-18) | ||
@@ -4,0 +19,0 @@ |
+1
-0
@@ -18,4 +18,5 @@ "use strict"; | ||
| __exportStar(require("./formatter"), exports); | ||
| __exportStar(require("./log-buffer"), exports); | ||
| __exportStar(require("./handler-console"), exports); | ||
| __exportStar(require("./handler-debug"), exports); | ||
| __exportStar(require("./logger"), exports); |
+1
-0
@@ -18,2 +18,3 @@ "use strict"; | ||
| __exportStar(require("./formatter"), exports); | ||
| __exportStar(require("./log-buffer"), exports); | ||
| __exportStar(require("./handler-console"), exports); | ||
@@ -20,0 +21,0 @@ __exportStar(require("./handler-debug"), exports); |
+30
-21
@@ -5,2 +5,3 @@ "use strict"; | ||
| const log_level_1 = require("./log-level"); | ||
| const log_buffer_1 = require("./log-buffer"); | ||
| function makePrinter({ handler, level = log_level_1.LogLevel.silent, format, masks, maskLog }) { | ||
@@ -10,44 +11,52 @@ var _a; | ||
| return { debug, log, info: log, warn, error, fatal, verbose: log }; | ||
| // Capture at all levels when active; gate handler dispatch by display level. | ||
| function emit(threshold, levelName, messages) { | ||
| const gated = level < threshold; | ||
| if (gated && !(0, log_buffer_1.isLogBufferActive)()) | ||
| return undefined; | ||
| const line = formatter(messages, { ...format, level: levelName, masks, maskLog }); | ||
| if ((0, log_buffer_1.isLogBufferActive)() && typeof line === 'string') | ||
| (0, log_buffer_1.appendToLogBuffer)(line); | ||
| return gated ? undefined : line; | ||
| } | ||
| function debug(...messages) { | ||
| if (level < log_level_1.LogLevel.debug) | ||
| return; | ||
| const options = { ...format, level: 'debug', masks, maskLog }; | ||
| handler.log(formatter(messages, options)); | ||
| const line = emit(log_level_1.LogLevel.debug, 'debug', messages); | ||
| if (line !== undefined) | ||
| handler.log(line); | ||
| } | ||
| function log(...messages) { | ||
| if (level < log_level_1.LogLevel.info) | ||
| return; | ||
| const options = { ...format, level: 'info', masks, maskLog }; | ||
| handler.log(formatter(messages, options)); | ||
| const line = emit(log_level_1.LogLevel.info, 'info', messages); | ||
| if (line !== undefined) | ||
| handler.log(line); | ||
| } | ||
| function warn(...messages) { | ||
| if (level < log_level_1.LogLevel.warn) | ||
| const line = emit(log_level_1.LogLevel.warn, 'warn', messages); | ||
| if (line === undefined) | ||
| return; | ||
| const options = { ...format, level: 'warn', masks, maskLog }; | ||
| if (handler.warn) | ||
| handler.warn(formatter(messages, options)); | ||
| handler.warn(line); | ||
| else | ||
| handler.log(formatter(messages, options)); | ||
| handler.log(line); | ||
| } | ||
| function error(...messages) { | ||
| if (level < log_level_1.LogLevel.error) | ||
| const line = emit(log_level_1.LogLevel.error, 'error', messages); | ||
| if (line === undefined) | ||
| return; | ||
| const options = { ...format, level: 'error', masks, maskLog }; | ||
| if (handler.error) | ||
| handler.error(formatter(messages, options)); | ||
| handler.error(line); | ||
| else | ||
| handler.log(formatter(messages, options)); | ||
| handler.log(line); | ||
| } | ||
| function fatal(...messages) { | ||
| if (level < log_level_1.LogLevel.fatal) | ||
| const line = emit(log_level_1.LogLevel.fatal, 'fatal', messages); | ||
| if (line === undefined) | ||
| return; | ||
| const options = { ...format, level: 'fatal', masks, maskLog }; | ||
| if (handler.fatal) | ||
| handler.fatal(formatter(messages, options)); | ||
| handler.fatal(line); | ||
| else if (handler.error) | ||
| handler.error(formatter(messages, options)); | ||
| handler.error(line); | ||
| else | ||
| handler.log(formatter(messages, options)); | ||
| handler.log(line); | ||
| } | ||
| } | ||
| exports.makePrinter = makePrinter; |
+2
-2
| { | ||
| "name": "@applitools/logger", | ||
| "version": "2.2.13", | ||
| "version": "2.3.0", | ||
| "description": "Applitools logger", | ||
@@ -52,3 +52,3 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@applitools/utils": "1.15.0", | ||
| "@applitools/utils": "1.15.1", | ||
| "chalk": "4.1.2", | ||
@@ -55,0 +55,0 @@ "debug": "4.3.4" |
| export type * from './types'; | ||
| export type { Handler as CustomHandler } from './types'; | ||
| export * from './formatter'; | ||
| export * from './log-buffer'; | ||
| export * from './handler-console'; | ||
| export * from './handler-debug'; | ||
| export * from './logger'; |
+1
-0
| export type * from './types'; | ||
| export type { Handler as CustomHandler } from './types'; | ||
| export * from './formatter'; | ||
| export * from './log-buffer'; | ||
| export * from './handler-console'; | ||
@@ -5,0 +6,0 @@ export * from './handler-debug'; |
79734
5.69%32
6.67%1070
9.07%+ Added
- Removed
Updated