capybara/frontend/logger.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

const loggerOfType = (components, type='log') => (...args) => {
let str = '%c';
const style = 'color: #5e81ac; font-weight: bold;';
for (const i in components) {
const v = components[i];
if (components[i+1] === undefined) {
str += `[${v}]`;
} else {
str += `[${v}] `;
}
}
switch (type) {
case 'log': {
console.log(str, style, ...args);
break;
}
case 'error': {
console.error(str, style, ...args);
break;
}
case 'warn': {
console.warn(str, style, ...args);
break;
}
case 'genmsg': {
return str;
}
default: {
return str;
}
}
};
2022-08-26 22:09:08 +03:00
function logger(components, types=['warn', 'error', 'log']) {
const loggerObj = {};
for (const type of types) {
loggerObj[type] = loggerOfType(components, type);
}
return loggerObj;
}
export function domLog(message) {
document.body.appendChild(document.createTextNode(message));
}
2022-08-26 22:09:08 +03:00
export default logger;