UNPKG

typescript-logging

Version:

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

254 lines 9.33 kB
"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