mirror of
https://github.com/Netflix/dial-reference.git
synced 2026-06-10 11:39:57 +00:00
ability to write logs of test run to a file for nodejs tests
This commit is contained in:
@@ -2,19 +2,63 @@
|
||||
|
||||
const colors = require("colors/safe");
|
||||
const sprintf = require("sprintf-js").sprintf;
|
||||
const winston = require("winston");
|
||||
const moment = require("moment");
|
||||
|
||||
function printTestInfo(test, msg) {
|
||||
return console.log(sprintf("%-20s : %-s\n%-20s : %-s", "Test", test, "Description", msg));
|
||||
const levels = { error: 0, warn: 1, info: 2, verbose: 3, debug: 4 };
|
||||
const transports = [
|
||||
new (winston.transports.Console)({
|
||||
level: "info",
|
||||
formatter: consoleFormatter
|
||||
}),
|
||||
new (winston.transports.File)({
|
||||
level: "debug",
|
||||
name: "log_file",
|
||||
filename: "log.txt",
|
||||
json: false,
|
||||
formatter: fileFormatter,
|
||||
options: { flags: "w" }
|
||||
}),
|
||||
];
|
||||
|
||||
winston.configure({ levels: levels, transports: transports });
|
||||
|
||||
function consoleFormatter(options) {
|
||||
let str = options.message;
|
||||
|
||||
switch (options.level) {
|
||||
case "error": return colors.red(str);
|
||||
case "warn": return colors.yellow(str);
|
||||
case "debug": return colors.blue(str);
|
||||
case "info":
|
||||
default: return str;
|
||||
}
|
||||
}
|
||||
|
||||
function fileFormatter(options) {
|
||||
let str = options.message;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
function printTestInfo(testFile, description) {
|
||||
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "TEST", testFile));
|
||||
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "DESCRIPTION", description));
|
||||
}
|
||||
|
||||
function printTestSuccess() {
|
||||
return console.log(colors.green("TEST PASSED\n"));
|
||||
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "RESULT", "TEST PASSED\n"));
|
||||
}
|
||||
|
||||
function printTestFailure(err) {
|
||||
return console.log(colors.red(sprintf("%-20s : %-s\n", "TEST FAILED", err)));
|
||||
winston.error(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "RESULT", "TEST FAILED " + err + "\n"));
|
||||
}
|
||||
|
||||
function printDebug(msg) {
|
||||
winston.debug(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "DEBUG", msg));
|
||||
}
|
||||
|
||||
module.exports.printTestInfo = printTestInfo;
|
||||
module.exports.printTestSuccess = printTestSuccess;
|
||||
module.exports.printTestFailure = printTestFailure;
|
||||
module.exports.printDebug = printDebug;
|
||||
|
||||
Reference in New Issue
Block a user