UNPKG

1.75 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5var colors_1 = __importDefault(require("colors"));
6var winston_1 = __importDefault(require("winston"));
7var time_stamp_1 = __importDefault(require("time-stamp"));
8var color_support_1 = __importDefault(require("color-support"));
9function hasFlag(flag) {
10 return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1));
11}
12function addColor(str) {
13 if (hasFlag('no-color')) {
14 return str;
15 }
16 if (hasFlag('color')) {
17 return colors_1.default.gray(str);
18 }
19 if (color_support_1.default()) {
20 return colors_1.default.gray(str);
21 }
22 return str;
23}
24function getTimestamp() {
25 return '[' + addColor(time_stamp_1.default('HH:mm:ss')) + ']';
26}
27// create winston logger format
28var logFmt = winston_1.default.format.printf(function (info) {
29 return getTimestamp() + " " + info.level + ": " + info.message;
30});
31var Log = /** @class */ (function () {
32 function Log() {
33 this.logger = winston_1.default.createLogger({
34 level: 'error',
35 transports: [new winston_1.default.transports.Console()],
36 format: winston_1.default.format.combine(winston_1.default.format.colorize({ all: true }), logFmt)
37 });
38 }
39 Log.prototype.setVerbosity = function (v) {
40 this.logger.configure({
41 level: v,
42 transports: [new winston_1.default.transports.Console()],
43 format: winston_1.default.format.combine(winston_1.default.format.colorize({ all: true }), logFmt)
44 });
45 };
46 return Log;
47}());
48module.exports = Log;
49//# sourceMappingURL=logger.js.map
\No newline at end of file