Skip to content

Instantly share code, notes, and snippets.

@166MMX
Last active December 31, 2015 15:29
Show Gist options
  • Save 166MMX/8006885 to your computer and use it in GitHub Desktop.
Save 166MMX/8006885 to your computer and use it in GitHub Desktop.
//noinspection JSUnusedLocalSymbols
var consoleLog = function consoleLog ()
{
Array.prototype.unshift.call(arguments, 'log');
safeConsoleLog.apply(this, arguments);
};
//noinspection JSUnusedLocalSymbols
var consoleDebug = function consoleDebug ()
{
Array.prototype.unshift.call(arguments, 'debug');
safeConsoleLog.apply(this, arguments);
};
//noinspection JSUnusedLocalSymbols
var consoleInfo = function consoleInfo ()
{
Array.prototype.unshift.call(arguments, 'info');
safeConsoleLog.apply(this, arguments);
};
//noinspection JSUnusedLocalSymbols
var consoleWarn = function consoleWarn ()
{
Array.prototype.unshift.call(arguments, 'warn');
safeConsoleLog.apply(this, arguments);
};
//noinspection JSUnusedLocalSymbols
var consoleError = function consoleError ()
{
Array.prototype.unshift.call(arguments, 'error');
safeConsoleLog.apply(this, arguments);
};
//noinspection JSUnusedLocalSymbols
var consoleException = function consoleException ()
{
Array.prototype.unshift.call(arguments, 'exception');
safeConsoleLog.apply(this, arguments);
};
var safeConsoleLog = function safeConsoleLog (level)
{
var originalArguments = Array.prototype.slice.call(arguments, 1);
var windowConsole = window.console;
if (typeof windowConsole !== 'undefined')
{
var windowConsoleLevel = windowConsole[level];
var isWindowConsoleLevelFunction = typeof windowConsoleLevel === 'function';
try
{
if (isWindowConsoleLevelFunction)
{
windowConsoleLevel.apply(windowConsole, originalArguments);
}
else if (windowConsoleLevel)
{
Function.prototype.apply.apply(windowConsoleLevel, [windowConsole, originalArguments]);
}
}
catch (ex)
{
// NOP
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment