triviality-logger
Version:
Typescript loggers with an interface that support composition
55 lines • 2.29 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 __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, [message].concat(optionalParams)) + this.eol);
return;
}
this.process.stdout.write(util.format.apply(util, [message].concat(optionalParams)) + this.eol);
};
return ProcessLogger;
}(AbstractLogLevelLogger_1.AbstractLogLevelLogger));
exports.ProcessLogger = ProcessLogger;
//# sourceMappingURL=ProcessLogger.js.map