UNPKG

1.27 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var pad = require("pad");
4var winston_1 = require("winston");
5var _1 = require(".");
6var util_1 = require("./util");
7var combine = winston_1.format.combine, timestamp = winston_1.format.timestamp, printf = winston_1.format.printf;
8var trimAndPadLeft = function (text, length) {
9 return pad(util_1.trim(text, length, '…'), length);
10};
11var trimAndPadRight = function (text, length) {
12 return pad(length, util_1.trim(text, length, '…'));
13};
14var myFormat = printf(function (info) {
15 return info.timestamp + " | " + trimAndPadLeft(info.scenario || 'no scenario', 15) + " | " + trimAndPadLeft(info.action || 'no action', 15) + " | " + trimAndPadRight("" + info.level.toUpperCase(), 5) + " | " + info.message;
16});
17exports.getLogger = function (scenario) {
18 if (scenario === void 0) { scenario = 'unknown'; }
19 return winston_1.createLogger({
20 level: 'debug',
21 format: combine(timestamp(), myFormat),
22 transports: [
23 new winston_1.transports.Console({ level: 'info' }),
24 new winston_1.transports.File({
25 filename: _1.OUTPUT_DIR() + "/" + scenario + ".log",
26 level: 'debug',
27 }),
28 ],
29 });
30};