UNPKG

typescript-logging

Version:

Library for logging, written in typescript, can be used by normal es5+ javascript as well.

52 lines 2.15 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var AbstractLogger_1 = require("./AbstractLogger"); /** * Logger which buffers all messages, use with care due to possible high memory footprint. * Can be convenient in some cases. Call toString() for full output, or cast to this class * and call getMessages() to do something with it yourself. */ var MessageBufferLoggerImpl = (function (_super) { __extends(MessageBufferLoggerImpl, _super); function MessageBufferLoggerImpl(name, logGroupRuntimeSettings) { var _this = _super.call(this, name, logGroupRuntimeSettings) || this; _this.messages = []; return _this; } MessageBufferLoggerImpl.prototype.close = function () { this.messages = []; _super.prototype.close.call(this); }; MessageBufferLoggerImpl.prototype.getMessages = function () { return this.messages; }; MessageBufferLoggerImpl.prototype.toString = function () { return this.messages.map(function (msg) { return msg; }).join("\n"); }; MessageBufferLoggerImpl.prototype.doLog = function (message) { var messageFormatter = this._getMessageFormatter(); var fullMsg; if (messageFormatter === null) { fullMsg = this.createDefaultLogMessage(message); } else { fullMsg = messageFormatter(message); } this.messages.push(fullMsg); }; return MessageBufferLoggerImpl; }(AbstractLogger_1.AbstractLogger)); exports.MessageBufferLoggerImpl = MessageBufferLoggerImpl; //# sourceMappingURL=MessageBufferLoggerImpl.js.map