testplane
Version:
Tests framework based on mocha and wdio
39 lines • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.error = exports.warn = exports.log = exports.withLogOptions = void 0;
const strftime_1 = __importDefault(require("strftime"));
const LOG_OPTIONS = Symbol("logOptions");
function withLogOptions(opts) {
return { [LOG_OPTIONS]: opts };
}
exports.withLogOptions = withLogOptions;
const withTimestampPrefix = (logFnName) => (...args) => {
const lastArg = args[args.length - 1];
const options = lastArg && typeof lastArg === "object" && LOG_OPTIONS in lastArg
? args.pop()[LOG_OPTIONS]
: undefined;
const shouldTimestamp = options?.timestamp !== false;
let transformedArgs = args;
if (options?.prefixEachLine) {
transformedArgs = transformedArgs.map(arg => {
return String(arg)
.split("\n")
.map(line => `${options.prefixEachLine}${line}`)
.join("\n");
});
}
if (shouldTimestamp) {
const timestamp = (0, strftime_1.default)("%H:%M:%S %z");
console[logFnName](`[${timestamp}]`, ...transformedArgs);
}
else {
console[logFnName](...transformedArgs);
}
};
exports.log = withTimestampPrefix("log");
exports.warn = withTimestampPrefix("warn");
exports.error = withTimestampPrefix("error");
//# sourceMappingURL=logger.js.map