3 exports.__esModule = true;
4 exports.logByType = undefined;
6 var _window = require('global/window');
8 var _window2 = _interopRequireDefault(_window);
10 var _browser = require('./browser');
12 var _obj = require('./obj');
14 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19 * Log messages to the console and history based on the type of message
21 * @param {string} type
22 * The name of the console method to use.
25 * The arguments to be passed to the matching console method.
27 * @param {boolean} [stringify]
28 * By default, only old IEs should get console argument stringification,
29 * but this is exposed as a parameter to facilitate testing.
35 var logByType = exports.logByType = function logByType(type, args) {
36 var stringify = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !!_browser.IE_VERSION && _browser.IE_VERSION < 11;
41 // add the type to the front of the message when it's not "log"
42 args.unshift(type.toUpperCase() + ':');
46 log.history.push(args);
48 // add console prefix after adding to history
49 args.unshift('VIDEOJS:');
51 // If there's no console then don't try to output messages, but they will
52 // still be stored in `log.history`.
54 // Was setting these once outside of this function, but containing them
55 // in the function makes it easier to test cases where console doesn't exist
56 // when the module is executed.
57 var fn = _window2['default'].console && _window2['default'].console[type];
59 // Bail out if there's no console.
64 // IEs previous to 11 log objects uselessly as "[object Object]"; so, JSONify
65 // objects and arrays for those less-capable browsers.
67 args = args.map(function (a) {
68 if ((0, _obj.isObject)(a) || Array.isArray(a)) {
70 return JSON.stringify(a);
76 // Cast to string before joining, so we get null and undefined explicitly
77 // included in output (as we would in a modern console).
82 // Old IE versions do not allow .apply() for console methods (they are
83 // reported as objects rather than functions).
87 fn[Array.isArray(args) ? 'apply' : 'call'](_window2['default'].console, args);
92 * Log plain debug messages
94 * @param {Mixed[]} args
95 * One or more messages or objects that should be logged.
97 log = function log() {
98 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
99 args[_key] = arguments[_key];
102 logByType('log', args);
106 * Keep a history of log messages
115 * @param {Mixed[]} args
116 * One or more messages or objects that should be logged as an error
118 log.error = function () {
119 for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
120 args[_key2] = arguments[_key2];
123 return logByType('error', args);
127 * Log warning messages
129 * @param {Mixed[]} args
130 * One or more messages or objects that should be logged as a warning.
132 log.warn = function () {
133 for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
134 args[_key3] = arguments[_key3];
137 return logByType('warn', args);
140 exports['default'] = log;