@applitools/logger
Advanced tools
Comparing version 2.0.20 to 2.1.0
# Changelog | ||
## [2.1.0](https://github.com/Applitools-Dev/sdk/compare/js/logger@2.0.20...js/logger@2.1.0) (2024-12-31) | ||
### Features | ||
* logger masking ([#2640](https://github.com/Applitools-Dev/sdk/issues/2640)) ([bd69d21](https://github.com/Applitools-Dev/sdk/commit/bd69d21f6341447b1acdb042f4ee1a6328d7428f)) | ||
### Dependencies | ||
* @applitools/utils bumped to 1.7.7 | ||
#### Bug Fixes | ||
* shim process execution functions for browser environment ([#2698](https://github.com/Applitools-Dev/sdk/issues/2698)) ([8d77db4](https://github.com/Applitools-Dev/sdk/commit/8d77db48e1c7fd54cad92c89a819a924255e5868)) | ||
## [2.0.20](https://github.com/Applitools-Dev/sdk/compare/js/logger@2.0.19...js/logger@2.0.20) (2024-12-18) | ||
@@ -4,0 +19,0 @@ |
@@ -41,6 +41,7 @@ "use strict"; | ||
}; | ||
function formatter(chunks, { prelude = true, label, timestamp = new Date(), level = 'info', tags, colors } = {}) { | ||
var _a; | ||
function formatter(chunks, { prelude = true, label, timestamp = new Date(), level = 'info', tags, colors, masks, maskLog } = {}) { | ||
var _a, _b; | ||
if (utils.types.isBoolean(colors)) | ||
colors = colors ? defaultColorTheme : undefined; | ||
const shouldMaskMessage = (_a = utils.general.getEnvValue('MASK_LOG', 'boolean')) !== null && _a !== void 0 ? _a : maskLog; | ||
const message = []; | ||
@@ -69,3 +70,3 @@ if (prelude) { | ||
const text = level.toUpperCase().padEnd(5); | ||
const color = (_a = colors === null || colors === void 0 ? void 0 : colors.level) === null || _a === void 0 ? void 0 : _a[level]; | ||
const color = (_b = colors === null || colors === void 0 ? void 0 : colors.level) === null || _b === void 0 ? void 0 : _b[level]; | ||
message.push(color ? (0, colorize_1.colorize)(` ${text} `, { color }) : `[${text}]`); | ||
@@ -77,5 +78,11 @@ } | ||
const strings = chunks.map(chunk => { | ||
return utils.types.isString(chunk) | ||
let text = utils.types.isString(chunk) | ||
? (0, colorize_1.colorize)(chunk, { color }) | ||
: util_1.inspect === null || util_1.inspect === void 0 ? void 0 : (0, util_1.inspect)(chunk, { colors: Boolean(colors), compact: 5, depth: 5 }); | ||
if (shouldMaskMessage) { | ||
masks === null || masks === void 0 ? void 0 : masks.forEach(mask => { | ||
text = text.replaceAll(mask, '***'); | ||
}); | ||
} | ||
return text; | ||
}); | ||
@@ -82,0 +89,0 @@ message.push(strings.join(' ')); |
@@ -36,11 +36,15 @@ "use strict"; | ||
const utils = __importStar(require("@applitools/utils")); | ||
const masks = new Set(); | ||
function makeLogger({ logger: baseLogger, ...options } = {}) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
var _k, _l; | ||
if (baseLogger) | ||
return baseLogger.extend({ level: options.level, ...options.format }); | ||
return baseLogger.extend({ level: options.level, ...options.format, maskLog: options.maskLog }); | ||
(_a = options.console) !== null && _a !== void 0 ? _a : (options.console = true); | ||
(_b = options.format) !== null && _b !== void 0 ? _b : (options.format = {}); | ||
(_c = (_g = options.format).formatter) !== null && _c !== void 0 ? _c : (_g.formatter = formatter_1.formatter); | ||
(_d = (_h = options.format).colors) !== null && _d !== void 0 ? _d : (_h.colors = utils.general.getEnvValue('LOG_COLORS', 'boolean')); | ||
(_c = (_k = options.format).formatter) !== null && _c !== void 0 ? _c : (_k.formatter = formatter_1.formatter); | ||
(_d = (_l = options.format).colors) !== null && _d !== void 0 ? _d : (_l.colors = utils.general.getEnvValue('LOG_COLORS', 'boolean')); | ||
(_e = options.maskLog) !== null && _e !== void 0 ? _e : (options.maskLog = utils.general.getEnvValue('MASK_LOG', 'boolean')); | ||
const userMaskValues = (_g = (_f = utils.general.getEnvValue('MASK_VALUES')) === null || _f === void 0 ? void 0 : _f.split(/(?<!\\),/)) !== null && _g !== void 0 ? _g : []; | ||
userMaskValues.forEach(value => masks.add(value.replace('\\,', ','))); | ||
let forceInitHandler; | ||
@@ -69,3 +73,3 @@ if (!options.handler) { | ||
if (!utils.types.isNumber(options.level)) { | ||
(_e = options.level) !== null && _e !== void 0 ? _e : (options.level = (_f = utils.general.getEnvValue('LOG_LEVEL')) !== null && _f !== void 0 ? _f : (utils.general.getEnvValue('SHOW_LOGS', 'boolean') ? 'all' : undefined)); | ||
(_h = options.level) !== null && _h !== void 0 ? _h : (options.level = (_j = utils.general.getEnvValue('LOG_LEVEL')) !== null && _j !== void 0 ? _j : (utils.general.getEnvValue('SHOW_LOGS', 'boolean') ? 'all' : undefined)); | ||
options.level = log_level_1.LogLevel[options.level]; | ||
@@ -100,5 +104,18 @@ } | ||
options, | ||
console: (0, printer_1.makePrinter)({ handler: options.console, level: log_level_1.LogLevel.all, format: { ...options.format, prelude: false } }), | ||
...(0, printer_1.makePrinter)({ handler: options.handler, level: options.level, format: options.format }), | ||
console: (0, printer_1.makePrinter)({ | ||
handler: options.console, | ||
level: log_level_1.LogLevel.all, | ||
format: { ...options.format, prelude: false }, | ||
maskLog: options.maskLog, | ||
masks, | ||
}), | ||
...(0, printer_1.makePrinter)({ | ||
handler: options.handler, | ||
level: options.level, | ||
format: options.format, | ||
maskLog: options.maskLog, | ||
masks, | ||
}), | ||
extend(optionsOrLogger, extraOptions) { | ||
var _a, _b, _c; | ||
const extendOptions = [options]; | ||
@@ -111,8 +128,20 @@ if (utils.types.has(optionsOrLogger, 'isLogger')) { | ||
format: optionsOrLogger.options.format, | ||
maskLog: (_a = optionsOrLogger.options.maskLog) !== null && _a !== void 0 ? _a : options.maskLog, | ||
}); | ||
if (extraOptions) | ||
extendOptions.push({ console: extraOptions.console, level: extraOptions.level, format: extraOptions }); | ||
if (extraOptions) { | ||
extendOptions.push({ | ||
console: extraOptions.console, | ||
level: extraOptions.level, | ||
maskLog: (_b = extraOptions.maskLog) !== null && _b !== void 0 ? _b : options.maskLog, | ||
format: extraOptions, | ||
}); | ||
} | ||
} | ||
else if (optionsOrLogger) { | ||
extendOptions.push({ console: optionsOrLogger.console, level: optionsOrLogger.level, format: optionsOrLogger }); | ||
extendOptions.push({ | ||
console: optionsOrLogger.console, | ||
level: optionsOrLogger.level, | ||
maskLog: (_c = optionsOrLogger.maskLog) !== null && _c !== void 0 ? _c : options.maskLog, | ||
format: optionsOrLogger, | ||
}); | ||
} | ||
@@ -136,2 +165,5 @@ const extendedOptions = mergeOptions(...extendOptions); | ||
}, | ||
mask(value) { | ||
masks.add(value); | ||
}, | ||
}; | ||
@@ -162,3 +194,3 @@ return logger; | ||
return options.reduce((baseOptions, currentOptions) => { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c, _d, _e, _f; | ||
return { | ||
@@ -168,6 +200,7 @@ ...baseOptions, | ||
level: (_a = currentOptions.level) !== null && _a !== void 0 ? _a : baseOptions.level, | ||
maskLog: (_b = currentOptions.maskLog) !== null && _b !== void 0 ? _b : baseOptions.maskLog, | ||
format: { | ||
...baseOptions.format, | ||
...currentOptions.format, | ||
tags: mergeTags((_c = (_b = baseOptions.format) === null || _b === void 0 ? void 0 : _b.tags) !== null && _c !== void 0 ? _c : [], (_e = (_d = currentOptions.format) === null || _d === void 0 ? void 0 : _d.tags) !== null && _e !== void 0 ? _e : []), | ||
tags: mergeTags((_d = (_c = baseOptions.format) === null || _c === void 0 ? void 0 : _c.tags) !== null && _d !== void 0 ? _d : [], (_f = (_e = currentOptions.format) === null || _e === void 0 ? void 0 : _e.tags) !== null && _f !== void 0 ? _f : []), | ||
}, | ||
@@ -174,0 +207,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const log_level_1 = require("./log-level"); | ||
function makePrinter({ handler, level = log_level_1.LogLevel.silent, format }) { | ||
function makePrinter({ handler, level = log_level_1.LogLevel.silent, format, masks, maskLog }) { | ||
var _a; | ||
@@ -13,3 +13,3 @@ const formatter = (_a = format === null || format === void 0 ? void 0 : format.formatter) !== null && _a !== void 0 ? _a : ((chunks, options) => ({ chunks, options, isRaw: true })); | ||
return; | ||
const options = { ...format, level: 'debug' }; | ||
const options = { ...format, level: 'debug', masks, maskLog }; | ||
handler.log(formatter(messages, options)); | ||
@@ -20,3 +20,3 @@ } | ||
return; | ||
const options = { ...format, level: 'info' }; | ||
const options = { ...format, level: 'info', masks, maskLog }; | ||
handler.log(formatter(messages, options)); | ||
@@ -27,3 +27,3 @@ } | ||
return; | ||
const options = { ...format, level: 'warn' }; | ||
const options = { ...format, level: 'warn', masks, maskLog }; | ||
if (handler.warn) | ||
@@ -37,3 +37,3 @@ handler.warn(formatter(messages, options)); | ||
return; | ||
const options = { ...format, level: 'error' }; | ||
const options = { ...format, level: 'error', masks, maskLog }; | ||
if (handler.error) | ||
@@ -47,3 +47,3 @@ handler.error(formatter(messages, options)); | ||
return; | ||
const options = { ...format, level: 'fatal' }; | ||
const options = { ...format, level: 'fatal', masks, maskLog }; | ||
if (handler.fatal) | ||
@@ -50,0 +50,0 @@ handler.fatal(formatter(messages, options)); |
{ | ||
"name": "@applitools/logger", | ||
"version": "2.0.20", | ||
"version": "2.1.0", | ||
"description": "Applitools logger", | ||
@@ -52,3 +52,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@applitools/utils": "1.7.6", | ||
"@applitools/utils": "1.7.7", | ||
"chalk": "4.1.2", | ||
@@ -55,0 +55,0 @@ "debug": "4.3.4" |
import type { FormatOptions } from './types'; | ||
export declare function formatter(chunks: any[], { prelude, label, timestamp, level, tags, colors }?: FormatOptions): string; | ||
export declare function formatter(chunks: any[], { prelude, label, timestamp, level, tags, colors, masks, maskLog }?: FormatOptions): string; |
import type { Printer, PrinterOptions } from './types'; | ||
export declare function makePrinter({ handler, level, format }: PrinterOptions): Printer; | ||
export declare function makePrinter({ handler, level, format, masks, maskLog }: PrinterOptions): Printer; |
@@ -10,5 +10,7 @@ import type { LogLevel } from './log-level'; | ||
console?: boolean | Handler; | ||
maskLog?: boolean; | ||
}), options?: Omit<FormatOptions, 'level'> & { | ||
level?: LogLevelName | number; | ||
console?: boolean | Handler; | ||
maskLog?: boolean; | ||
}): Logger; | ||
@@ -20,2 +22,3 @@ colorize(string: string, options?: { | ||
close(): void; | ||
mask(value: string): void; | ||
} | ||
@@ -27,2 +30,3 @@ export type LoggerOptions = Omit<Partial<PrinterOptions>, 'handler' | 'level'> & { | ||
level?: LogLevelName | number; | ||
maskLog?: boolean; | ||
}; | ||
@@ -45,2 +49,4 @@ export interface Printer { | ||
}; | ||
masks?: Set<string>; | ||
maskLog?: boolean; | ||
}; | ||
@@ -94,2 +100,4 @@ export type ConsoleHandler = { | ||
colors?: ColoringOptions | boolean; | ||
maskLog?: boolean; | ||
masks?: Set<string>; | ||
}; | ||
@@ -96,0 +104,0 @@ export interface SpyLogger extends Logger { |
59547
834
+ Added@applitools/utils@1.7.7(transitive)
- Removed@applitools/utils@1.7.6(transitive)
Updated@applitools/utils@1.7.7