@triviality/logger
Version:
Typescript loggers with an interface that support composition
75 lines • 2.95 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var LoggerInterface_1 = require("./LoggerInterface");
var AbstractLogLevelLogger_1 = require("./AbstractLogLevelLogger");
var os = __importStar(require("os"));
var util = __importStar(require("util"));
/**
* With format option like console. Handy if you want to control eol.
*
* https://nodejs.org/api/util.html#util_util_format_format_args
*/
var ProcessLogger = /** @class */ (function (_super) {
__extends(ProcessLogger, _super);
function ProcessLogger(process, eol) {
if (eol === void 0) { eol = os.EOL; }
var _this = _super.call(this) || this;
_this.process = process;
_this.eol = eol;
return _this;
}
ProcessLogger.prototype.log = function (type, message) {
var optionalParams = [];
for (var _i = 2; _i < arguments.length; _i++) {
optionalParams[_i - 2] = arguments[_i];
}
if (type === LoggerInterface_1.LogLevel.error) {
this.process.stderr.write(util.format.apply(util, __spread([message], optionalParams)) + this.eol);
return;
}
this.process.stdout.write(util.format.apply(util, __spread([message], optionalParams)) + this.eol);
};
return ProcessLogger;
}(AbstractLogLevelLogger_1.AbstractLogLevelLogger));
exports.ProcessLogger = ProcessLogger;
//# sourceMappingURL=ProcessLogger.js.map