|
| 1 | +/// <reference path="ref.ts" /> |
| 2 | + |
| 3 | +/** |
| 4 | + * @class LogLevel |
| 5 | + * @brief Available levels of log |
| 6 | + */ |
| 7 | +enum LogLevel { |
| 8 | + Debug = 0, // all messages |
| 9 | + Test = 1, // only inform, warnings & errors |
| 10 | + Production = 2, // only warnings & erros |
| 11 | + Opaque = 3 // only errors |
| 12 | +} |
| 13 | + |
| 14 | +/** |
| 15 | + * @class Log |
| 16 | + * @brief Simple log |
| 17 | + */ |
| 18 | +class Log { |
| 19 | + //region Fields |
| 20 | + |
| 21 | + /** |
| 22 | + * Current level of log. Default value to Debug |
| 23 | + */ |
| 24 | + private static _currentLevel : LogLevel = LogLevel.Debug; |
| 25 | + |
| 26 | + //endregion Fields |
| 27 | + |
| 28 | + //region Constructors |
| 29 | + |
| 30 | + //endregion Constructors |
| 31 | + |
| 32 | + //region Methods |
| 33 | + |
| 34 | + //region Private Methods |
| 35 | + |
| 36 | + //endregion Private Methods |
| 37 | + |
| 38 | + //region Public Methods |
| 39 | + |
| 40 | + /** |
| 41 | + * Sets current level of log |
| 42 | + * @param {LogLevel} level Desired level |
| 43 | + */ |
| 44 | + static setLevel(level : LogLevel) : void { |
| 45 | + Log._currentLevel = level; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Prints a debug message |
| 50 | + * @param {string} msg Message |
| 51 | + */ |
| 52 | + static debug(msg : string) : void { |
| 53 | + if (this._currentLevel <= LogLevel.Debug) { |
| 54 | + console.log('DEBUG: ' + msg); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Prints information |
| 60 | + * @param {string} msg Message |
| 61 | + */ |
| 62 | + static inform(msg : string) : void { |
| 63 | + if (this._currentLevel <= LogLevel.Test) { |
| 64 | + console.log('%cINFORM: ' + msg, 'color: DeepSkyBlue;'); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Prints warning |
| 70 | + * @param {string} msg Message |
| 71 | + */ |
| 72 | + static warn(msg : string) : void { |
| 73 | + if (this._currentLevel <= LogLevel.Production) { |
| 74 | + console.log('%cWARN: ' + msg, 'color: orange;'); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Prints an error |
| 80 | + * @param {Exception} error Exception |
| 81 | + */ |
| 82 | + static error(error : Exception) : void { |
| 83 | + console.error('Error: ' + error.toString()); |
| 84 | + } |
| 85 | + |
| 86 | + //endregion Public Methods |
| 87 | + |
| 88 | + //endregion Methods |
| 89 | +} |
0 commit comments