Skip to content

Instantly share code, notes, and snippets.

@bgadrian
Created March 16, 2015 17:20
Show Gist options
  • Save bgadrian/2cf08c5c3b89eec4d38c to your computer and use it in GitHub Desktop.
Save bgadrian/2cf08c5c3b89eec4d38c to your computer and use it in GitHub Desktop.
JS log to console multiple parameters,objects,functions etc
/** Console logs all the parameters received. Can handle objects, functions, doms etc
usage : log('myObj = ',obj,'other x = ',x);
*/
function log()
{
buffer = '';
for (var i = 0; i < arguments.length; i++)
{
if (typeof(arguments[i]) == 'object'
|| typeof(arguments[i]) == 'function')
{
if (buffer.length)
console.log(buffer);
buffer = '';
console.log(arguments[i]);
//if you are NOT using CHROME (where objects can be viewed) use
// console.log(JSON.stringify(arguments[i]));
}
else
{
buffer += '[' + arguments[i] + ']';
}
}
if (buffer.length) console.log(buffer);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment