/// <reference path="./util/LogViewer.ts" /> /// <reference path="./econdaConfig.ts" /> /** * Provides some basic debugging functions * <p>This api will not output any messages (including errors) as long as debug mode * is not enabled!</p> * <p>During development, we strongly recommend to enable debug mode. This will output * debug messages, warning and errors on browser console.</p> * * // somewhere before you use the tracking api * var econdaConfig = { debug: true }; * * // debug messages will be logged to browser console. * // you can add the id of a div element to log messages to this div element too * econdaConfig.debugOutputContainer = "id-of-div-element"; * * It's ok to setup debug configuration before or after the library was loaded. * * @class econda.debug * @static */ var econda; (function (econda) { var debug = (function () { function debug() { } /** * Enable debug mode for current page. * * @method * @static * @param {Boolean} enabled */ debug.setEnabled = function (enabled) { econdaConfig.debug = enabled; return this; }; /** * Get status, returns true if enabled * * @method * @static * @return {Boolean} True if debug mode is enabled */ debug.getEnabled = function () { return econdaConfig.debug; }; debug.setExceptionsOnError = function (enabled) { econdaConfig.exceptionsOnError = enabled; return this; }; debug.getExceptionsOnError = function () { return econdaConfig.exceptionsOnError || false; }; /** * Set div element where to write the log output * @method * @static */ debug.setOutputContainer = function (htmlElement) { econdaConfig.debugOutputContainer = htmlElement; this.logViewerInstance = null; return this; }; /** * Writes error message to console if debug mode is enabled * @method * @static * @param {String} message * @param {Array} data additional information */ debug.error = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } if (econdaConfig.debug != true) { return this; } var data = []; for (var n = 1; n < arguments.length; n++) { data.push(arguments[n]); } if (typeof console != 'undefined' && console.error) { console.error("[ec] " + arguments[0], data); } if (econdaConfig.debugOutputContainer != null) { this.setupLogViewer(); this.logViewerInstance.error(arguments[0], data); } if (econdaConfig.exceptionsOnError) { throw new Error(arguments[0]); } return this; }; /** * Writes warning to console if debug mode is enabled * @method * @static * @param {String} message * @param {Array} data additional information */ debug.warn = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } if (econdaConfig.debug != true) { return this; } var data = []; for (var n = 1; n < arguments.length; n++) { data.push(arguments[n]); } if (typeof console != 'undefined' && console.warn) { console.warn("[ec] " + arguments[0], data); } if (econdaConfig.debugOutputContainer != null) { this.setupLogViewer(); this.logViewerInstance.warn(arguments[0], data); } return this; }; /** * Writes debug message to console if debug mode is enabled * @method * @static * @param {String} message * @param {Array} data additional information */ debug.log = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } if (econdaConfig.debug != true) { return this; } var data = []; for (var n = 1; n < arguments.length; n++) { data.push(arguments[n]); } if (typeof console != 'undefined' && console.log) { (data.length > 0) ? console.log("[ec] " + arguments[0], data) : console.log("[ec] " + arguments[0]); } if (econdaConfig.debugOutputContainer != null) { this.setupLogViewer(); this.logViewerInstance.log(arguments[0], data); } return this; }; debug.setupLogViewer = function () { if (this.logViewerInstance == null) { this.logViewerInstance = new econda.util.LogViewer(); this.logViewerInstance.container = econdaConfig.debugOutputContainer; } }; /** * LogViewer instance * @private */ debug.logViewerInstance = null; return debug; }()); econda.debug = debug; })(econda || (econda = {}));