Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
It's Christmas time again. That means setting up your Christmas decorators. Let's get those console logs of yours spruced up.
/*
Lets have a little Christmas fun in the console.
From the Wisdom team
https://GetWisdom.io
*/
(function ChristmasConsole (){
function getRandEmoji() {
const EMOJIES = ['🦌🦌🦌', '🎅', '🎄🎄'];
return EMOJIES[ Math.random() * EMOJIES.length |0 ];
}
function getRandStyle() {
const randColor = Math.random() > 0.5 ? '#CC172B' : '#0E5818';
return 'color: '+randColor+';';
}
const log = window.console.log;
window.console.log = function() {
const args = Array.prototype.slice.call(arguments);
const style = getRandStyle();
args.push(getRandEmoji());
if (window.navigator && window.navigator.vendor === 'Google Inc.') {
var formatting = '';
const valueArgs = [];
args.forEach(x => {
let formatter;
if (typeof x === 'object') {
formatter = '%o ';
}
else if (typeof x === 'number') {
formatter = '%c%f ';
valueArgs.push('color: blue;');
}
else {
formatter = '%c%s ';
valueArgs.push(style);
}
formatting += formatter;
valueArgs.push(x);
});
return log.apply(window.console, [].concat([formatting], valueArgs));
}
else {
return log.apply(window.console, args);
}
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.