can-log
Version:
Utilities for logging to the console.
39 lines • 1.27 kB
JavaScript
/*can-log@1.0.1#can-log*/
define('can-log', function (require, exports, module) {
'use strict';
exports.warnTimeout = 5000;
exports.logLevel = 0;
exports.warn = function () {
var ll = this.logLevel;
if (ll < 2) {
if (typeof console !== 'undefined' && console.warn) {
this._logger('warn', Array.prototype.slice.call(arguments));
} else if (typeof console !== 'undefined' && console.log) {
this._logger('log', Array.prototype.slice.call(arguments));
}
}
};
exports.log = function () {
var ll = this.logLevel;
if (ll < 1) {
if (typeof console !== 'undefined' && console.log) {
this._logger('log', Array.prototype.slice.call(arguments));
}
}
};
exports.error = function () {
var ll = this.logLevel;
if (ll < 1) {
if (typeof console !== 'undefined' && console.error) {
this._logger('error', Array.prototype.slice.call(arguments));
}
}
};
exports._logger = function (type, arr) {
try {
console[type].apply(console, arr);
} catch (e) {
console[type](arr);
}
};
});