@oat-sa/tao-core-sdk
Version:
Core libraries of TAO
69 lines (60 loc) • 2.57 kB
JavaScript
define(['lodash', 'module', 'core/logger/api'], function (_, module, loggerFactory) { 'use strict';
_ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
module = module && Object.prototype.hasOwnProperty.call(module, 'default') ? module['default'] : module;
loggerFactory = loggerFactory && Object.prototype.hasOwnProperty.call(loggerFactory, 'default') ? loggerFactory['default'] : loggerFactory;
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2017-2019 (original work) Open Assessment Technologies SA;
*
*/
/**
* The default configuration if nothing
* is found on the module config
*/
const defaultConfig = {
level: loggerFactory.levels.warn,
loggers: {
'core/logger/console': {
level: 'warn'
}
}
};
//the logger providers are configured through the AMD module config
const config = _.defaults(module.config() || {}, defaultConfig);
const logger = loggerFactory('core/logger');
loggerFactory.setDefaultLevel(config.level);
loggerFactory.load(config.loggers);
/**
* Catch uncaught errors
* @param {string} msg - error message
* @param {string} url - current url
* @param {number} line - line number
* @param {number} col - column number
* @return {boolean}
*/
window.onerror = function onError(msg, url, line, col) {
logger.error(`Caught[via window.onerror]: '${msg}' from ${url}:${line}:${col}`);
};
/**
* Expose explicitely an direct way to activate log levels
* @param {String|Number} level - the new log level
* @returns {String} the defined level
*/
window.setTaoLogLevel = function setTaoLogLevel(level) {
return loggerFactory.setDefaultLevel(level);
};
return loggerFactory;
});