/* * ===================================== * Class ErrorService * Source: packages/web/sharedjs/utils/ * ==================================== * LEVELS: OFF The highest possible rank and is intended to turn off logging. FATAL Severe errors that cause premature termination. Expect these to be immediately visible on a status console. ERROR Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. WARN Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily 'wrong'. Expect these to be immediately visible on a status console. INFO Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. DEBUG Detailed information on the flow through the system. Expect these to be written to logs only. TRACE Most detailed information. Expect these to be written to logs only. */ /*globals $, _ */ var AXIS = AXIS || {}; AXIS.ErrorService = function () { }; AXIS.ErrorService.OFF = 'OFF'; AXIS.ErrorService.FATAL = 'FATAL'; AXIS.ErrorService.ERROR = 'ERROR'; AXIS.ErrorService.WARN = 'WARN'; AXIS.ErrorService.INFO = 'INFO'; AXIS.ErrorService.DEBUG = 'DEBUG'; AXIS.ErrorService.TRACE = 'TRACE'; AXIS.ErrorService.history = []; AXIS.ErrorService.log = function (component, message, level, isSilent) { if (level === AXIS.ErrorService.OFF || level === AXIS.ErrorService.FATAL || level === AXIS.ErrorService.ERROR || level === AXIS.ErrorService.WARN || level === AXIS.ErrorService.INFO || level === AXIS.ErrorService.DEBUG || level === AXIS.ErrorService.TRACE) { var historyObject = {time: new Date(), component: component, message: message, level: level}; AXIS.ErrorService.history.push(historyObject); if (isSilent === undefined || isSilent === true) { AXIS.ErrorService.printToConsole(historyObject); } } }; AXIS.ErrorService.logError = function (component, message) { AXIS.ErrorService.log(component, message, AXIS.ErrorService.ERROR); }; AXIS.ErrorService.logDebug = function (component, message) { AXIS.ErrorService.log(component, message, AXIS.ErrorService.DEBUG); }; AXIS.ErrorService.printToConsole = function (historyObject) { if (window.console && window.console.log) { window.console.log(historyObject); } }; AXIS.ErrorService.toString = function (historyObject) { var str = historyObject.time + ' ' + historyObject.level + ' ' + historyObject.message + ' ' + historyObject.component; return str; };