UNPKG

container.ts

Version:
84 lines 3.13 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 container_1 = require("../../container"); var validate_1 = require("../validate"); var Logs = /** @class */ (function (_super) { __extends(Logs, _super); function Logs(options) { var _this = _super.call(this, options) || this; /** Parsed application logs level. */ _this.level = _this.parseLevel(_this.envLevel); // Debug environment variables. _this.debug(Logs.ENV.LEVEL + "=\"" + container_1.ELogLevel[_this.level] + "\""); // Subscribe to container log messages filtered by level. _this.container.filterLogs(_this.level) .subscribe(function (log) { return _this.onMessage(log); }); return _this; } Object.defineProperty(Logs.prototype, "envLevel", { /** Get log level from environment or default to warning. */ get: function () { return validate_1.Validate.isString(this.environment.get(Logs.ENV.LEVEL) || "warning"); }, enumerable: true, configurable: true }); /** Convert environment log level string to level index, defaults to warning. */ Logs.prototype.parseLevel = function (level) { switch ((level || "").toLowerCase()) { case "emerg": case "emergency": { return container_1.ELogLevel.Emergency; } case "alert": { return container_1.ELogLevel.Alert; } case "crit": case "critical": { return container_1.ELogLevel.Critical; } case "err": case "error": { return container_1.ELogLevel.Error; } case "warn": case "warning": { return container_1.ELogLevel.Warning; } case "notice": { return container_1.ELogLevel.Notice; } case "info": case "information": case "informational": { return container_1.ELogLevel.Informational; } case "debug": { return container_1.ELogLevel.Debug; } default: { return container_1.ELogLevel.Warning; } } }; /** Default module name. */ Logs.moduleName = "Logs"; /** Environment variable names. */ Logs.ENV = { /** Application logs level (default warning). */ LEVEL: "LOGS_LEVEL", }; return Logs; }(container_1.Module)); exports.Logs = Logs; //# sourceMappingURL=Logs.js.map