videojs-vast-vpaid
Version:
VAST plugin to use with video.js
103 lines (84 loc) • 1.55 kB
JavaScript
/* jshint unused:false */
let _verbosity = 0;
const _prefix = '[videojs-vast-vpaid] ';
function setVerbosity (v)
{
_verbosity = v;
}
function handleMsg (method, args)
{
if (args.length > 0 && typeof args[0] === 'string')
{
args[0] = _prefix + args[0];
}
if (method.apply)
{
method.apply(console, Array.prototype.slice.call(args));
}
else
{
method(Array.prototype.slice.call(args));
}
}
function debug ()
{
if (_verbosity < 4)
{
return;
}
if (typeof console.debug === 'undefined')
{
// IE 10 doesn't have a console.debug() function
handleMsg(console.log, arguments);
}
else
{
handleMsg(console.debug, arguments);
}
}
function log ()
{
if (_verbosity < 3)
{
return;
}
handleMsg(console.log, arguments);
}
function info ()
{
if (_verbosity < 2)
{
return;
}
handleMsg(console.info, arguments);
}
function warn ()
{
if (_verbosity < 1)
{
return;
}
handleMsg(console.warn, arguments);
}
function error ()
{
handleMsg(console.error, arguments);
}
const consoleLogger = {
setVerbosity: setVerbosity,
debug: debug,
log: log,
info: info,
warn: warn,
error: error
};
if (typeof console === 'undefined' || !console.log)
{
// no console available; make functions no-op
consoleLogger.debug = function () {};
consoleLogger.log = function () {};
consoleLogger.info = function () {};
consoleLogger.warn = function () {};
consoleLogger.error = function () {};
}
module.exports = consoleLogger;