UNPKG

typescript-logging

Version:

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

1,537 lines (1,468 loc) 297 kB
var TSL = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // identity function for calling harmony imports with the correct context /******/ __webpack_require__.i = function(value) { return value; }; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 30); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Log level for a logger. */ var LogLevel; (function (LogLevel) { LogLevel[LogLevel["Trace"] = 0] = "Trace"; LogLevel[LogLevel["Debug"] = 1] = "Debug"; LogLevel[LogLevel["Info"] = 2] = "Info"; LogLevel[LogLevel["Warn"] = 3] = "Warn"; LogLevel[LogLevel["Error"] = 4] = "Error"; LogLevel[LogLevel["Fatal"] = 5] = "Fatal"; })(LogLevel = exports.LogLevel || (exports.LogLevel = {})); /* tslint:disable:no-namespace */ (function (LogLevel) { /** * Returns LogLevel based on string representation * @param val Value * @returns {LogLevel}, Error is thrown if invalid. */ function fromString(val) { if (val == null) { throw new Error("Argument must be set"); } switch (val.toLowerCase()) { case "trace": return LogLevel.Trace; case "debug": return LogLevel.Debug; case "info": return LogLevel.Info; case "warn": return LogLevel.Warn; case "error": return LogLevel.Error; case "fatal": return LogLevel.Fatal; default: throw new Error("Unsupported value for conversion: " + val); } } LogLevel.fromString = fromString; })(LogLevel = exports.LogLevel || (exports.LogLevel = {})); /* tslint:disable:enable-namespace */ /** * Where to log to? Pick one of the constants. Custom requires a callback to be present, see LFService.createLoggerFactory(...) * where this comes into play. */ var LoggerType; (function (LoggerType) { LoggerType[LoggerType["Console"] = 0] = "Console"; LoggerType[LoggerType["MessageBuffer"] = 1] = "MessageBuffer"; LoggerType[LoggerType["Custom"] = 2] = "Custom"; })(LoggerType = exports.LoggerType || (exports.LoggerType = {})); /** * Defines several date enums used for formatting a date. */ var DateFormatEnum; (function (DateFormatEnum) { /** * Displays as: year-month-day hour:minute:second,millis -> 1999-02-12 23:59:59,123 * Note the date separator can be set separately. */ DateFormatEnum[DateFormatEnum["Default"] = 0] = "Default"; /** * Displays as: year-month-day hour:minute:second -> 1999-02-12 23:59:59 * Note the date separator can be set separately. */ DateFormatEnum[DateFormatEnum["YearMonthDayTime"] = 1] = "YearMonthDayTime"; /** * Displays as: year-day-month hour:minute:second,millis -> 1999-12-02 23:59:59,123 * Note the date separator can be set separately. */ DateFormatEnum[DateFormatEnum["YearDayMonthWithFullTime"] = 2] = "YearDayMonthWithFullTime"; /** * Displays as: year-day-month hour:minute:second -> 1999-12-02 23:59:59 * Note the date separator can be set separately. */ DateFormatEnum[DateFormatEnum["YearDayMonthTime"] = 3] = "YearDayMonthTime"; })(DateFormatEnum = exports.DateFormatEnum || (exports.DateFormatEnum = {})); /* tslint:disable:no-namespace */ (function (DateFormatEnum) { /** * Returns LogLevel based on string representation * @param val Value * @returns {LogLevel}, Error is thrown if invalid. */ function fromString(val) { if (val == null) { throw new Error("Argument must be set"); } switch (val.toLowerCase()) { case "default": return DateFormatEnum.Default; case "yearmonthdayTime": return DateFormatEnum.YearMonthDayTime; case "yeardaymonthwithfulltime": return DateFormatEnum.YearDayMonthWithFullTime; case "yeardaymonthtime": return DateFormatEnum.YearDayMonthTime; default: throw new Error("Unsupported value for conversion: " + val); } } DateFormatEnum.fromString = fromString; })(DateFormatEnum = exports.DateFormatEnum || (exports.DateFormatEnum = {})); /* tslint:disable:enable-namespace */ /** * DateFormat class, stores data on how to format a date. */ var DateFormat = (function () { /** * Constructor to define the dateformat used for logging, can be called empty as it uses defaults. * @param formatEnum DateFormatEnum, use one of the constants from the enum. Defaults to DateFormatEnum.Default * @param dateSeparator Separator used between dates, defaults to - */ function DateFormat(formatEnum, dateSeparator) { if (formatEnum === void 0) { formatEnum = DateFormatEnum.Default; } if (dateSeparator === void 0) { dateSeparator = "-"; } this._formatEnum = formatEnum; this._dateSeparator = dateSeparator; } Object.defineProperty(DateFormat.prototype, "formatEnum", { get: function () { return this._formatEnum; }, set: function (value) { this._formatEnum = value; }, enumerable: true, configurable: true }); Object.defineProperty(DateFormat.prototype, "dateSeparator", { get: function () { return this._dateSeparator; }, set: function (value) { this._dateSeparator = value; }, enumerable: true, configurable: true }); DateFormat.prototype.copy = function () { return new DateFormat(this._formatEnum, this._dateSeparator); }; return DateFormat; }()); exports.DateFormat = DateFormat; /** * Information about the log format, what will a log line look like? */ var LogFormat = (function () { /** * Constructor to create a LogFormat. Can be created without parameters where it will use sane defaults. * @param dateFormat DateFormat (what needs the date look like in the log line) * @param showTimeStamp Show date timestamp at all? * @param showLoggerName Show the logger name? */ function LogFormat(dateFormat, showTimeStamp, showLoggerName) { if (dateFormat === void 0) { dateFormat = new DateFormat(); } if (showTimeStamp === void 0) { showTimeStamp = true; } if (showLoggerName === void 0) { showLoggerName = true; } this._showTimeStamp = true; this._showLoggerName = true; this._dateFormat = dateFormat; this._showTimeStamp = showTimeStamp; this._showLoggerName = showLoggerName; } Object.defineProperty(LogFormat.prototype, "dateFormat", { get: function () { return this._dateFormat; }, enumerable: true, configurable: true }); Object.defineProperty(LogFormat.prototype, "showTimeStamp", { get: function () { return this._showTimeStamp; }, set: function (value) { this._showTimeStamp = value; }, enumerable: true, configurable: true }); Object.defineProperty(LogFormat.prototype, "showLoggerName", { get: function () { return this._showLoggerName; }, set: function (value) { this._showLoggerName = value; }, enumerable: true, configurable: true }); return LogFormat; }()); exports.LogFormat = LogFormat; /** * Information about the log format, what will a log line look like? */ var CategoryLogFormat = (function () { /** * Create an instance defining the category log format used. * @param dateFormat Date format (uses default), for details see DateFormat class. * @param showTimeStamp True to show timestamp in the logging, defaults to true. * @param showCategoryName True to show category name in the logging, defaults to true. */ function CategoryLogFormat(dateFormat, showTimeStamp, showCategoryName) { if (dateFormat === void 0) { dateFormat = new DateFormat(); } if (showTimeStamp === void 0) { showTimeStamp = true; } if (showCategoryName === void 0) { showCategoryName = true; } this._dateFormat = dateFormat; this._showTimeStamp = showTimeStamp; this._showCategoryName = showCategoryName; } Object.defineProperty(CategoryLogFormat.prototype, "dateFormat", { get: function () { return this._dateFormat; }, set: function (value) { this._dateFormat = value; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogFormat.prototype, "showTimeStamp", { get: function () { return this._showTimeStamp; }, set: function (value) { this._showTimeStamp = value; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogFormat.prototype, "showCategoryName", { get: function () { return this._showCategoryName; }, set: function (value) { this._showCategoryName = value; }, enumerable: true, configurable: true }); CategoryLogFormat.prototype.copy = function () { return new CategoryLogFormat(this._dateFormat.copy(), this._showTimeStamp, this._showCategoryName); }; return CategoryLogFormat; }()); exports.CategoryLogFormat = CategoryLogFormat; //# sourceMappingURL=LoggerOptions.js.map /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var LinkedNode = (function () { function LinkedNode(value) { this._previous = null; this._next = null; this._value = value; } Object.defineProperty(LinkedNode.prototype, "previous", { get: function () { return this._previous; }, set: function (value) { this._previous = value; }, enumerable: true, configurable: true }); Object.defineProperty(LinkedNode.prototype, "next", { get: function () { return this._next; }, set: function (value) { this._next = value; }, enumerable: true, configurable: true }); Object.defineProperty(LinkedNode.prototype, "value", { get: function () { return this._value; }, enumerable: true, configurable: true }); return LinkedNode; }()); /** * Double linkedlist implementation. */ var LinkedList = (function () { function LinkedList() { this.head = null; this.size = 0; } LinkedList.prototype.addHead = function (value) { if (!this.createHeadIfNeeded(value)) { if (this.head != null) { var nextNode = this.head.next; var newHeadNode = new LinkedNode(value); if (nextNode != null) { nextNode.previous = newHeadNode; newHeadNode.next = nextNode; } this.head = newHeadNode; } else { throw new Error("This should never happen, list implementation broken"); } } this.size++; }; LinkedList.prototype.addTail = function (value) { if (!this.createHeadIfNeeded(value)) { var oldTailNode = this.getTailNode(); if (oldTailNode != null) { var newTailNode = new LinkedNode(value); oldTailNode.next = newTailNode; newTailNode.previous = oldTailNode; } else { throw new Error("List implementation broken"); } } this.size++; }; LinkedList.prototype.clear = function () { this.head = null; this.size = 0; }; LinkedList.prototype.getHead = function () { if (this.head != null) { return this.head.value; } return null; }; LinkedList.prototype.removeHead = function () { if (this.head != null) { var oldHead = this.head; var value = oldHead.value; this.head = oldHead.next; this.size--; return value; } return null; }; LinkedList.prototype.getTail = function () { var node = this.getTailNode(); if (node != null) { return node.value; } return null; }; LinkedList.prototype.removeTail = function () { var node = this.getTailNode(); if (node != null) { if (node === this.head) { this.head = null; } else { var previousNode = node.previous; if (previousNode != null) { previousNode.next = null; } else { throw new Error("List implementation is broken"); } } this.size--; return node.value; } return null; }; LinkedList.prototype.getSize = function () { return this.size; }; LinkedList.prototype.filter = function (f) { var recurse = function (fn, node, values) { if (fn(node.value)) { values.push(node.value); } var nextNode = node.next; if (nextNode != null) { recurse(fn, nextNode, values); } }; var result = []; var currentNode = this.head; if (currentNode != null) { recurse(f, currentNode, result); } return result; }; LinkedList.prototype.createHeadIfNeeded = function (value) { if (this.head == null) { this.head = new LinkedNode(value); return true; } return false; }; LinkedList.prototype.getTailNode = function () { if (this.head == null) { return null; } var node = this.head; while (node.next != null) { node = node.next; } return node; }; return LinkedList; }()); exports.LinkedList = LinkedList; /** * Map implementation keyed by string (always). */ var SimpleMap = (function () { function SimpleMap() { this.array = {}; } SimpleMap.prototype.put = function (key, value) { this.array[key] = value; }; SimpleMap.prototype.get = function (key) { return this.array[key]; }; SimpleMap.prototype.exists = function (key) { var value = this.array[key]; return (typeof value !== "undefined"); }; SimpleMap.prototype.remove = function (key) { var value = this.array[key]; if (typeof value !== "undefined") { delete this.array[key]; } return value; }; SimpleMap.prototype.keys = function () { var keys = []; for (var key in this.array) { // To prevent random stuff to appear if (this.array.hasOwnProperty(key)) { keys.push(key); } } return keys; }; SimpleMap.prototype.values = function () { var values = []; for (var key in this.array) { // To prevent random stuff to appear if (this.array.hasOwnProperty(key)) { values.push(this.get(key)); } } return values; }; SimpleMap.prototype.size = function () { return this.keys().length; }; SimpleMap.prototype.isEmpty = function () { return this.size() === 0; }; SimpleMap.prototype.clear = function () { this.array = {}; }; SimpleMap.prototype.forEach = function (cbFunction) { var count = 0; for (var key in this.array) { // To prevent random stuff to appear if (this.array.hasOwnProperty(key)) { var value = this.array[key]; cbFunction(key, value, count); count++; } } }; SimpleMap.prototype.forEachValue = function (cbFunction) { var count = 0; for (var key in this.array) { // To prevent random stuff to appear if (this.array.hasOwnProperty(key)) { var value = this.array[key]; cbFunction(value, count); count++; } } }; return SimpleMap; }()); exports.SimpleMap = SimpleMap; /** * Tuple to hold two values. */ var TuplePair = (function () { function TuplePair(x, y) { this._x = x; this._y = y; } Object.defineProperty(TuplePair.prototype, "x", { get: function () { return this._x; }, set: function (value) { this._x = value; }, enumerable: true, configurable: true }); Object.defineProperty(TuplePair.prototype, "y", { get: function () { return this._y; }, set: function (value) { this._y = value; }, enumerable: true, configurable: true }); return TuplePair; }()); exports.TuplePair = TuplePair; /** * Utility class to build up a string. */ var StringBuilder = (function () { function StringBuilder() { this.data = []; } StringBuilder.prototype.append = function (line) { if (line === undefined || line == null) { throw new Error("String must be set, cannot append null or undefined"); } this.data.push(line); return this; }; StringBuilder.prototype.appendLine = function (line) { this.data.push(line + "\n"); return this; }; StringBuilder.prototype.isEmpty = function () { return this.data.length === 0; }; StringBuilder.prototype.clear = function () { this.data = []; }; StringBuilder.prototype.toString = function (separator) { if (separator === void 0) { separator = ""; } return this.data.join(separator); }; return StringBuilder; }()); exports.StringBuilder = StringBuilder; //# sourceMappingURL=DataStructures.js.map /***/ }), /* 2 */ /***/ (function(module, exports) { /* -*- Mode: js; js-indent-level: 2; -*- */ /* * Copyright 2011 Mozilla Foundation and contributors * Licensed under the New BSD license. See LICENSE or: * http://opensource.org/licenses/BSD-3-Clause */ /** * This is a helper function for getting values from parameter/options * objects. * * @param args The object we are extracting values from * @param name The name of the property we are getting. * @param defaultValue An optional value to return if the property is missing * from the object. If this is not specified and the property is missing, an * error will be thrown. */ function getArg(aArgs, aName, aDefaultValue) { if (aName in aArgs) { return aArgs[aName]; } else if (arguments.length === 3) { return aDefaultValue; } else { throw new Error('"' + aName + '" is a required argument.'); } } exports.getArg = getArg; var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; var dataUrlRegexp = /^data:.+\,.+$/; function urlParse(aUrl) { var match = aUrl.match(urlRegexp); if (!match) { return null; } return { scheme: match[1], auth: match[2], host: match[3], port: match[4], path: match[5] }; } exports.urlParse = urlParse; function urlGenerate(aParsedUrl) { var url = ''; if (aParsedUrl.scheme) { url += aParsedUrl.scheme + ':'; } url += '//'; if (aParsedUrl.auth) { url += aParsedUrl.auth + '@'; } if (aParsedUrl.host) { url += aParsedUrl.host; } if (aParsedUrl.port) { url += ":" + aParsedUrl.port } if (aParsedUrl.path) { url += aParsedUrl.path; } return url; } exports.urlGenerate = urlGenerate; /** * Normalizes a path, or the path portion of a URL: * * - Replaces consecutive slashes with one slash. * - Removes unnecessary '.' parts. * - Removes unnecessary '<dir>/..' parts. * * Based on code in the Node.js 'path' core module. * * @param aPath The path or url to normalize. */ function normalize(aPath) { var path = aPath; var url = urlParse(aPath); if (url) { if (!url.path) { return aPath; } path = url.path; } var isAbsolute = exports.isAbsolute(path); var parts = path.split(/\/+/); for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { part = parts[i]; if (part === '.') { parts.splice(i, 1); } else if (part === '..') { up++; } else if (up > 0) { if (part === '') { // The first part is blank if the path is absolute. Trying to go // above the root is a no-op. Therefore we can remove all '..' parts // directly after the root. parts.splice(i + 1, up); up = 0; } else { parts.splice(i, 2); up--; } } } path = parts.join('/'); if (path === '') { path = isAbsolute ? '/' : '.'; } if (url) { url.path = path; return urlGenerate(url); } return path; } exports.normalize = normalize; /** * Joins two paths/URLs. * * @param aRoot The root path or URL. * @param aPath The path or URL to be joined with the root. * * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a * scheme-relative URL: Then the scheme of aRoot, if any, is prepended * first. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion * is updated with the result and aRoot is returned. Otherwise the result * is returned. * - If aPath is absolute, the result is aPath. * - Otherwise the two paths are joined with a slash. * - Joining for example 'http://' and 'www.example.com' is also supported. */ function join(aRoot, aPath) { if (aRoot === "") { aRoot = "."; } if (aPath === "") { aPath = "."; } var aPathUrl = urlParse(aPath); var aRootUrl = urlParse(aRoot); if (aRootUrl) { aRoot = aRootUrl.path || '/'; } // `join(foo, '//www.example.org')` if (aPathUrl && !aPathUrl.scheme) { if (aRootUrl) { aPathUrl.scheme = aRootUrl.scheme; } return urlGenerate(aPathUrl); } if (aPathUrl || aPath.match(dataUrlRegexp)) { return aPath; } // `join('http://', 'www.example.com')` if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { aRootUrl.host = aPath; return urlGenerate(aRootUrl); } var joined = aPath.charAt(0) === '/' ? aPath : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); if (aRootUrl) { aRootUrl.path = joined; return urlGenerate(aRootUrl); } return joined; } exports.join = join; exports.isAbsolute = function (aPath) { return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); }; /** * Make a path relative to a URL or another path. * * @param aRoot The root path or URL. * @param aPath The path or URL to be made relative to aRoot. */ function relative(aRoot, aPath) { if (aRoot === "") { aRoot = "."; } aRoot = aRoot.replace(/\/$/, ''); // It is possible for the path to be above the root. In this case, simply // checking whether the root is a prefix of the path won't work. Instead, we // need to remove components from the root one by one, until either we find // a prefix that fits, or we run out of components to remove. var level = 0; while (aPath.indexOf(aRoot + '/') !== 0) { var index = aRoot.lastIndexOf("/"); if (index < 0) { return aPath; } // If the only part of the root that is left is the scheme (i.e. http://, // file:///, etc.), one or more slashes (/), or simply nothing at all, we // have exhausted all components, so the path is not relative to the root. aRoot = aRoot.slice(0, index); if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { return aPath; } ++level; } // Make sure we add a "../" for each component we removed from the root. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); } exports.relative = relative; var supportsNullProto = (function () { var obj = Object.create(null); return !('__proto__' in obj); }()); function identity (s) { return s; } /** * Because behavior goes wacky when you set `__proto__` on objects, we * have to prefix all the strings in our set with an arbitrary character. * * See https://github.com/mozilla/source-map/pull/31 and * https://github.com/mozilla/source-map/issues/30 * * @param String aStr */ function toSetString(aStr) { if (isProtoString(aStr)) { return '$' + aStr; } return aStr; } exports.toSetString = supportsNullProto ? identity : toSetString; function fromSetString(aStr) { if (isProtoString(aStr)) { return aStr.slice(1); } return aStr; } exports.fromSetString = supportsNullProto ? identity : fromSetString; function isProtoString(s) { if (!s) { return false; } var length = s.length; if (length < 9 /* "__proto__".length */) { return false; } if (s.charCodeAt(length - 1) !== 95 /* '_' */ || s.charCodeAt(length - 2) !== 95 /* '_' */ || s.charCodeAt(length - 3) !== 111 /* 'o' */ || s.charCodeAt(length - 4) !== 116 /* 't' */ || s.charCodeAt(length - 5) !== 111 /* 'o' */ || s.charCodeAt(length - 6) !== 114 /* 'r' */ || s.charCodeAt(length - 7) !== 112 /* 'p' */ || s.charCodeAt(length - 8) !== 95 /* '_' */ || s.charCodeAt(length - 9) !== 95 /* '_' */) { return false; } for (var i = length - 10; i >= 0; i--) { if (s.charCodeAt(i) !== 36 /* '$' */) { return false; } } return true; } /** * Comparator between two mappings where the original positions are compared. * * Optionally pass in `true` as `onlyCompareGenerated` to consider two * mappings with the same original source/line/column, but different generated * line and column the same. Useful when searching for a mapping with a * stubbed out mapping. */ function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { var cmp = mappingA.source - mappingB.source; if (cmp !== 0) { return cmp; } cmp = mappingA.originalLine - mappingB.originalLine; if (cmp !== 0) { return cmp; } cmp = mappingA.originalColumn - mappingB.originalColumn; if (cmp !== 0 || onlyCompareOriginal) { return cmp; } cmp = mappingA.generatedColumn - mappingB.generatedColumn; if (cmp !== 0) { return cmp; } cmp = mappingA.generatedLine - mappingB.generatedLine; if (cmp !== 0) { return cmp; } return mappingA.name - mappingB.name; } exports.compareByOriginalPositions = compareByOriginalPositions; /** * Comparator between two mappings with deflated source and name indices where * the generated positions are compared. * * Optionally pass in `true` as `onlyCompareGenerated` to consider two * mappings with the same generated line and column, but different * source/name/original line and column the same. Useful when searching for a * mapping with a stubbed out mapping. */ function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { var cmp = mappingA.generatedLine - mappingB.generatedLine; if (cmp !== 0) { return cmp; } cmp = mappingA.generatedColumn - mappingB.generatedColumn; if (cmp !== 0 || onlyCompareGenerated) { return cmp; } cmp = mappingA.source - mappingB.source; if (cmp !== 0) { return cmp; } cmp = mappingA.originalLine - mappingB.originalLine; if (cmp !== 0) { return cmp; } cmp = mappingA.originalColumn - mappingB.originalColumn; if (cmp !== 0) { return cmp; } return mappingA.name - mappingB.name; } exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; function strcmp(aStr1, aStr2) { if (aStr1 === aStr2) { return 0; } if (aStr1 > aStr2) { return 1; } return -1; } /** * Comparator between two mappings with inflated source and name strings where * the generated positions are compared. */ function compareByGeneratedPositionsInflated(mappingA, mappingB) { var cmp = mappingA.generatedLine - mappingB.generatedLine; if (cmp !== 0) { return cmp; } cmp = mappingA.generatedColumn - mappingB.generatedColumn; if (cmp !== 0) { return cmp; } cmp = strcmp(mappingA.source, mappingB.source); if (cmp !== 0) { return cmp; } cmp = mappingA.originalLine - mappingB.originalLine; if (cmp !== 0) { return cmp; } cmp = mappingA.originalColumn - mappingB.originalColumn; if (cmp !== 0) { return cmp; } return strcmp(mappingA.name, mappingB.name); } exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var CategoryService_1 = __webpack_require__(7); var LoggerOptions_1 = __webpack_require__(0); var MessageUtils_1 = __webpack_require__(6); var ExtensionHelper = (function () { function ExtensionHelper() { // Private constructor } /** * Enables the window event listener to listen to messages (from extensions). * Can be registered/enabled only once. */ ExtensionHelper.register = function () { if (!ExtensionHelper.registered) { var listener = function (evt) { var msg = evt.data; if (msg !== null) { ExtensionHelper.processMessageFromExtension(msg); } }; if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined" && typeof window.addEventListener !== "undefined") { window.removeEventListener("message", listener); window.addEventListener("message", listener); ExtensionHelper.registered = true; } } }; ExtensionHelper.processMessageFromExtension = function (msg) { if (!ExtensionHelper.registered) { return; } /* tslint:disable:no-console */ if (msg.from === "tsl-extension") { var data = msg.data; switch (data.type) { case "register": ExtensionHelper.enableExtensionIntegration(); break; case "request-change-loglevel": var valueRequest = data.value; var catsApplied = ExtensionHelper.applyLogLevel(valueRequest.categoryId, valueRequest.logLevel, valueRequest.recursive); if (catsApplied.length > 0) { // Send changes back ExtensionHelper.sendCategoriesRuntimeUpdateMessage(catsApplied); } break; default: console.log("Unknown command to process message from extension, command was: " + data.type); break; } } /* tslint:enable:no-console */ }; ExtensionHelper.sendCategoryLogMessage = function (msg) { if (!ExtensionHelper.registered) { return; } var categoryIds = msg.categories.map(function (cat) { return cat.id; }); var content = { type: "log-message", value: { categories: categoryIds, errorAsStack: msg.errorAsStack, formattedMessage: MessageUtils_1.MessageFormatUtils.renderDefaultMessage(msg, false), logLevel: LoggerOptions_1.LogLevel[msg.level].toString(), message: msg.messageAsString, resolvedErrorMessage: msg.isResolvedErrorMessage } }; var message = { data: content, from: "tsl-logging", }; ExtensionHelper.sendMessage(message); }; ExtensionHelper.sendCategoriesRuntimeUpdateMessage = function (categories) { if (!ExtensionHelper.registered) { return; } var service = CategoryService_1.CategoryServiceImpl.getInstance(); var catLevels = { categories: Array() }; categories.forEach(function (cat) { var catSettings = service.getCategorySettings(cat); if (catSettings != null) { catLevels.categories.push({ id: cat.id, logLevel: LoggerOptions_1.LogLevel[catSettings.logLevel].toString() }); } }); var content = { type: "categories-rt-update", value: catLevels, }; var message = { data: content, from: "tsl-logging" }; ExtensionHelper.sendMessage(message); }; ExtensionHelper.sendRootCategoriesToExtension = function () { if (!ExtensionHelper.registered) { return; } var categories = CategoryService_1.CategoryServiceImpl.getInstance().getRootCategories().map(function (cat) { return ExtensionHelper.getCategoryAsJSON(cat); }); var content = { type: "root-categories-tree", value: categories }; var message = { data: content, from: "tsl-logging" }; ExtensionHelper.sendMessage(message); }; /** * If extension integration is enabled, will send the root categories over to the extension. * Otherwise does nothing. */ ExtensionHelper.getCategoryAsJSON = function (cat) { var childCategories = cat.children.map(function (child) { return ExtensionHelper.getCategoryAsJSON(child); }); return { children: childCategories, id: cat.id, logLevel: LoggerOptions_1.LogLevel[cat.logLevel].toString(), name: cat.name, parentId: (cat.parent != null ? cat.parent.id : null), }; }; ExtensionHelper.applyLogLevel = function (categoryId, logLevel, recursive) { var cats = []; var category = CategoryService_1.CategoryServiceImpl.getInstance().getCategoryById(categoryId); if (category != null) { ExtensionHelper._applyLogLevelRecursive(category, LoggerOptions_1.LogLevel.fromString(logLevel), recursive, cats); } else { /* tslint:disable:no-console */ console.log("Could not change log level, failed to find category with id: " + categoryId); /* tslint:enable:no-console */ } return cats; }; ExtensionHelper._applyLogLevelRecursive = function (category, logLevel, recursive, cats) { var categorySettings = CategoryService_1.CategoryServiceImpl.getInstance().getCategorySettings(category); if (categorySettings != null) { categorySettings.logLevel = logLevel; cats.push(category); if (recursive) { category.children.forEach(function (child) { ExtensionHelper._applyLogLevelRecursive(child, logLevel, recursive, cats); }); } } }; ExtensionHelper.getAllCategories = function () { var cats = []; var addCats = function (cat, allCats) { allCats.push(cat); cat.children.forEach(function (catChild) { addCats(catChild, allCats); }); }; CategoryService_1.CategoryServiceImpl.getInstance().getRootCategories().forEach(function (cat) { addCats(cat, cats); }); return cats; }; ExtensionHelper.sendMessage = function (msg) { if (!ExtensionHelper.registered) { return; } if (typeof window !== "undefined" && typeof window.postMessage !== "undefined") { window.postMessage(msg, "*"); } }; /** * Extension framework will call this to enable the integration between two, * after this call the framework will respond with postMessage() messages. */ ExtensionHelper.enableExtensionIntegration = function () { if (!ExtensionHelper.registered) { return; } var instance = CategoryService_1.CategoryServiceImpl.getInstance(); instance.enableExtensionIntegration(); // Send over all categories ExtensionHelper.sendRootCategoriesToExtension(); // Send over the current runtime levels var cats = ExtensionHelper.getAllCategories(); ExtensionHelper.sendCategoriesRuntimeUpdateMessage(cats); }; ExtensionHelper.registered = false; return ExtensionHelper; }()); exports.ExtensionHelper = ExtensionHelper; //# sourceMappingURL=ExtensionHelper.js.map /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var DataStructures_1 = __webpack_require__(1); var MessageUtils_1 = __webpack_require__(6); var LoggerOptions_1 = __webpack_require__(0); var CategoryLogMessageImpl = (function () { function CategoryLogMessageImpl(message, error, categories, date, level, logFormat, ready) { this._resolvedErrorMessage = false; this._errorAsStack = null; this._message = message; this._error = error; this._categories = categories; this._date = date; this._level = level; this._logFormat = logFormat; this._ready = ready; } Object.defineProperty(CategoryLogMessageImpl.prototype, "message", { get: function () { return this._message; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "error", { get: function () { return this._error; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "categories", { get: function () { return this._categories; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "date", { get: function () { return this._date; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "level", { get: function () { return this._level; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "logFormat", { get: function () { return this._logFormat; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "isMessageLogData", { get: function () { return typeof (this._message) !== "string"; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "messageAsString", { get: function () { if (typeof (this._message) === "string") { return this._message; } return this._message.msg; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "logData", { get: function () { var result = null; if (typeof (this._message) !== "string") { result = this.message; } return result; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "isResolvedErrorMessage", { get: function () { return this._resolvedErrorMessage; }, enumerable: true, configurable: true }); Object.defineProperty(CategoryLogMessageImpl.prototype, "errorAsStack", { get: function () { return this._errorAsStack; }, set: function (stack) { this._errorAsStack = stack; }, enumerable: true, configurable: true }); CategoryLogMessageImpl.prototype.isReady = function () { return this._ready; }; CategoryLogMessageImpl.prototype.setReady = function (value) { this._ready = value; }; Object.defineProperty(CategoryLogMessageImpl.prototype, "resolvedErrorMessage", { get: function () { return this._resolvedErrorMessage; }, set: function (value) { this._resolvedErrorMessage = value; }, enumerable: true, configurable: true }); return CategoryLogMessageImpl; }()); /** * Abstract category logger, use as your base class for new type of loggers (it * saves you a lot of work) and override doLog(CategoryLogMessage). The message argument * provides full access to anything related to the logging event. * If you just want the standard line of logging, call: this.createDefaultLogMessage(msg) on * this class which will return you the formatted log message as string (e.g. the * default loggers all use this). */ var AbstractCategoryLogger = (function () { function AbstractCategoryLogger(rootCategory, runtimeSettings) { this.allMessages = new DataStructures_1.LinkedList(); this.rootCategory = rootCategory; this.runtimeSettings = runtimeSettings; } AbstractCategoryLogger.prototype.trace = function (msg) { var categories = []; for (var _i = 1; _i < arguments.length; _i++) { categories[_i - 1] = arguments[_i]; } this._log.apply(this, [LoggerOptions_1.LogLevel.Trace, msg, null, false].concat(categories)); }; AbstractCategoryLogger.prototype.debug = function (msg) { var categories = []; for (var _i = 1; _i < arguments.length; _i++) { categories[_i - 1] = arguments[_i]; } this._log.apply(this, [LoggerOptions_1.LogLevel.Debug, msg, null, false].concat(categories)); }; AbstractCategoryLogger.prototype.info = function (msg) { var categories = []; for (var _i = 1; _i < arguments.length; _i++) { categories[_i - 1] = arguments[_i]; } this._log.apply(this, [LoggerOptions_1.LogLevel.Info, msg, null, false].concat(categories)); }; AbstractCategoryLogger.prototype.warn = function (msg) { var categories = []; for (var _i = 1; _i < arguments.length; _i++) { categories[_i - 1] = arguments[_i]; } this._log.apply(this, [LoggerOptions_1.LogLevel.Warn, msg, null, false].concat(categories)); }; AbstractCategoryLogger.prototype.error = function (msg, error) { var categories = []; for (var _i = 2; _i < arguments.length; _i++) { categories[_i - 2] = arguments[_i]; } this._log.apply(this, [LoggerOptions_1.LogLevel.Error, msg, error, false].concat(categories)); }; AbstractCategoryLogger.prototype.fatal = function (msg, error) { var categories = []; for (var _i = 2; _i < arguments.length; _i++) { categories[_i - 2] = arguments[_i]; } this._log.apply(this, [LoggerOptions_1.LogLevel.Fatal, msg, error, false].concat(categories)); }; AbstractCategoryLogger.prototype.resolved = function (msg, error) { var categories = []; for (var _i = 2; _i < arguments.length; _i++) { categories[_i - 2] = arguments[_i]; } this._log.apply(this, [LoggerOptions_1.LogLevel.Error, msg, error, true].concat(categories)); }; AbstractCategoryLogger.prototype.log = function (level, msg, error) { var categories = []; for (var _i = 3; _i < arguments.length; _i++) { categories[_i - 3] = arguments[_i]; } this._log.apply(this, [level, msg, error, false].concat(categories)); }; AbstractCategoryLogger.prototype.getRootCategory = function () { return this.rootCategory; }; AbstractCategoryLogger.prototype.createDefaultLogMessage = function (msg) { return MessageUtils_1.MessageFormatUtils.renderDefaultMessage(msg, true); }; /** * Return optional message formatter. All LoggerTypes (except custom) will see if * they have this, and if so use it to log. * @returns {((message:CategoryLogMessage)=>string)|null} */ AbstractCategoryLogger.prototype._getMessageFormatter = function () { var categorySettings = this.runtimeSettings.getCategorySettings(this.rootCategory); // Should not happen but make ts happy if (categorySettings === null) { throw new Error("Did not find CategorySettings for rootCategory: " + this.rootCategory.name); } return categorySettings.formatterLogMessage; }; AbstractCategoryLogger.prototype._log = function (level, msg, error, resolved) { if (error === void 0) { error = null; } if (resolved === void 0) { resolved = false; } var categories = []; for (var _i = 4; _i < arguments.length; _i++) { categories[_i - 4] = arguments[_i]; } // this._logInternal(level, () => msg, () => error, resolved, ...categories); var functionMessage = function () { if (typeof msg === "function") { return msg(); } return msg; }; var functionError = function () { if (typeof error === "function") { return error(); } return error; }; this._logInternal.apply(this, [level, functionMessage, functionError, resolved].concat(categories)); }; AbstractCategoryLogger.prototype._logInternal = function (level, msg, error, resolved) { var _this = this; var categories = []; for (var _i = 4; _i < arguments.length; _i++) { categories[_i - 4] = arguments[_i]; } var logCategories = [this.rootCategory]; // Log root category by default if none present if (typeof categories !== "undefined" && categories.length > 0) { logCategories = logCategories.concat(categories.filter(function (c) { return c !== _this.rootCategory; })); } var _loop_1 = function (i) { var category = logCategories[i]; if (category === null) { throw new Error("Cannot have a null element within categories, at index=" + i); } var settings = this_1.runtimeSettings.getCategorySettings(category); if (settings === null) { throw new Error("Category with path: " + category.getCategoryPath() + " is not registered with this logger, maybe " + "you registered it with a different root logger?"); } if (settings.logLevel <= level) { var actualError = error !== null ? error() : null; if (actualError === null) { var logMessage = new CategoryLogMessageImpl(msg(), actualError, logCategories, new Date(), level, settings.logFormat, true); logMessage.resolvedErrorMessage = resolved; this_1.allMessages.addTail(logMessage); this_1.processMessages(); } else {