@percy/sdk-utils
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -77,3 +77,9 @@ (function() { | ||
return Object.keys(LOG_LEVELS).reduce((ns, lvl) => Object.assign(ns, { | ||
[lvl]: log.bind(null, namespace, lvl) | ||
[lvl]: function () { | ||
for (var _len = arguments.length, a = new Array(_len), _key = 0; _key < _len; _key++) { | ||
a[_key] = arguments[_key]; | ||
} | ||
return logger.log(namespace, lvl, ...a); | ||
} | ||
}), {}); | ||
@@ -185,4 +191,4 @@ } // Set and/or return the local loglevel | ||
// there was an error connecting, will fallback to minimal logging | ||
log('utils', 'debug', 'Unable to connect to remote logger'); | ||
log('utils', 'debug', err); | ||
logger.log('utils', 'debug', 'Unable to connect to remote logger'); | ||
logger.log('utils', 'debug', err); | ||
} | ||
@@ -189,0 +195,0 @@ }; |
@@ -27,3 +27,3 @@ "use strict"; | ||
return Object.keys(LOG_LEVELS).reduce((ns, lvl) => Object.assign(ns, { | ||
[lvl]: log.bind(null, namespace, lvl) | ||
[lvl]: (...a) => logger.log(namespace, lvl, ...a) | ||
}), {}); | ||
@@ -135,4 +135,4 @@ } // Set and/or return the local loglevel | ||
// there was an error connecting, will fallback to minimal logging | ||
log('utils', 'debug', 'Unable to connect to remote logger'); | ||
log('utils', 'debug', err); | ||
logger.log('utils', 'debug', 'Unable to connect to remote logger'); | ||
logger.log('utils', 'debug', err); | ||
} | ||
@@ -139,0 +139,0 @@ }; |
{ | ||
"name": "@percy/sdk-utils", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"license": "MIT", | ||
@@ -53,3 +53,3 @@ "repository": { | ||
}, | ||
"gitHead": "1232b3fe054c7bd73879fd85ca109a723dbfb5b6" | ||
"gitHead": "05f91ff29b613bde1c740c120c5d23a6722d3606" | ||
} |
@@ -55,2 +55,6 @@ (function() { | ||
async teardown() { | ||
var _utils$logger$log$res, _utils$logger$log; | ||
(_utils$logger$log$res = (_utils$logger$log = utils.logger.log).restore) === null || _utils$logger$log$res === void 0 ? void 0 : _utils$logger$log$res.call(_utils$logger$log); | ||
if (process.env.__PERCY_BROWSERIFIED__) { | ||
@@ -95,17 +99,17 @@ for (let m of ['warn', 'error', 'log']) { | ||
helpers.logger.reset(); | ||
let shouldCaptureLogs = false; | ||
stub(utils.logger, 'log', function () { | ||
shouldCaptureLogs = true; | ||
utils.logger.log.originalValue(...arguments); | ||
shouldCaptureLogs = false; | ||
}); | ||
let capture = err => msg => { | ||
helpers.logger[err ? 'stderr' : 'stdout'].push(sanitizeLog(msg)); | ||
}; | ||
let stubLogs = (ctx, method, err) => stub(ctx, method, msg => { | ||
if (!shouldCaptureLogs) return ctx[method].originalValue.call(ctx, msg);else helpers.logger[err ? 'stderr' : 'stdout'].push(sanitizeLog(msg)); | ||
}); | ||
if (process.env.__PERCY_BROWSERIFIED__) { | ||
// use console[warn|error|log] in browsers | ||
for (let m of ['warn', 'error', 'log']) { | ||
stub(console, m, capture(m !== 'log')); | ||
} | ||
for (let m of ['warn', 'error', 'log']) stubLogs(console, m, m !== 'log'); | ||
} else { | ||
// use process[stdout|stderr].write in node | ||
for (let io of ['stdout', 'stderr']) { | ||
stub(process[io], 'write', capture(io === 'stderr')); | ||
} | ||
for (let io of ['stdout', 'stderr']) stubLogs(process[io], 'write', io === 'stderr'); | ||
} | ||
@@ -115,3 +119,3 @@ }, | ||
reset() { | ||
var _utils$logger$remote$; | ||
var _utils$logger$remote$, _utils$logger$log$res2, _utils$logger$log2; | ||
@@ -123,2 +127,3 @@ (_utils$logger$remote$ = utils.logger.remote.socket) === null || _utils$logger$remote$ === void 0 ? void 0 : _utils$logger$remote$.close(); | ||
helpers.logger.stderr.length = 0; | ||
(_utils$logger$log$res2 = (_utils$logger$log2 = utils.logger.log).reset) === null || _utils$logger$log$res2 === void 0 ? void 0 : _utils$logger$log$res2.call(_utils$logger$log2); | ||
@@ -125,0 +130,0 @@ if (process.env.__PERCY_BROWSERIFIED__) { |
@@ -44,2 +44,4 @@ const utils = require('@percy/sdk-utils'); | ||
async teardown() { | ||
utils.logger.log.restore?.(); | ||
if (process.env.__PERCY_BROWSERIFIED__) { | ||
@@ -72,17 +74,19 @@ for (let m of ['warn', 'error', 'log']) console[m].restore?.(); | ||
let capture = err => msg => { | ||
helpers.logger[err ? 'stderr' : 'stdout'] | ||
.push(sanitizeLog(msg)); | ||
}; | ||
let shouldCaptureLogs = false; | ||
stub(utils.logger, 'log', (...args) => { | ||
shouldCaptureLogs = true; | ||
utils.logger.log.originalValue(...args); | ||
shouldCaptureLogs = false; | ||
}); | ||
let stubLogs = (ctx, method, err) => stub(ctx, method, msg => { | ||
if (!shouldCaptureLogs) return ctx[method].originalValue.call(ctx, msg); | ||
else helpers.logger[err ? 'stderr' : 'stdout'].push(sanitizeLog(msg)); | ||
}); | ||
if (process.env.__PERCY_BROWSERIFIED__) { | ||
// use console[warn|error|log] in browsers | ||
for (let m of ['warn', 'error', 'log']) { | ||
stub(console, m, capture(m !== 'log')); | ||
} | ||
for (let m of ['warn', 'error', 'log']) stubLogs(console, m, m !== 'log'); | ||
} else { | ||
// use process[stdout|stderr].write in node | ||
for (let io of ['stdout', 'stderr']) { | ||
stub(process[io], 'write', capture(io === 'stderr')); | ||
} | ||
for (let io of ['stdout', 'stderr']) stubLogs(process[io], 'write', io === 'stderr'); | ||
} | ||
@@ -98,2 +102,3 @@ }, | ||
helpers.logger.stderr.length = 0; | ||
utils.logger.log.reset?.(); | ||
@@ -100,0 +105,0 @@ if (process.env.__PERCY_BROWSERIFIED__) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54411
1163