window.msg = (function (defaultConsole) {
return Object.assign({}, defaultConsole, {
log(text) {
defaultConsole.log("%cLOG: %c" + text,
"background-color: #fff; color: #5CB85C; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #5CB85C; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
},
info(text) {
defaultConsole.info("%cINFO: %c" + text,
"background-color: #fff; color: #337AB7; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #337AB7; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
},
warn(text) {
defaultConsole.warn("%cWARN: %c" + text,
"background-color: #fff; color: #F0AD4E; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #F0AD4E; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
},
error(text) {
defaultConsole.error("%cERROR: %c" + text,
"background-color: #fff; color: #D9534F; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #D9534F; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
}
})
}(window.console));
msg.log('Log Message !');
msg.info('Info Message !');
msg.warn('Warn Message !');
msg.error('Error Message !');
msg.debug('Debug Message !');
msg.dir('Dir Message !');
window.msg2 = (function (defaultConsole) {
for (var key in defaultConsole) {
this[key] = defaultConsole[key];
}
this.log = function (text) {
defaultConsole.log("%cLOG: %c" + text,
"background-color: #fff; color: #5cb85c; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #5cb85c; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
};
this.info = function (text) {
defaultConsole.info("%cINFO: %c" + text,
"background-color: #fff; color: #337ab7; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #337ab7; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
};
this.warn = function (text) {
defaultConsole.warn("%cWARN: %c" + text,
"background-color: #fff; color: #f0ad4e; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #f0ad4e; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
};
this.error = function (text) {
defaultConsole.error("%cERROR: %c" + text,
"background-color: #fff; color: #d9534f; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #d9534f; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
}
return this;
}(window.console));
msg2.log('Log Message !');
msg2.info('Info Message !');
msg2.warn('Warn Message !');
msg2.error('Error Message !');
msg2.debug('Debug Message !');
msg2.dir('Dir Message !');
window.msg3 = (function (defaultConsole) {
return {
log: function (text) {
defaultConsole.log("%cLOG: %c" + text,
"background-color: #fff; color: #5CB85C; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #5CB85C; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
},
info: function (text) {
defaultConsole.info("%cINFO: %c" + text,
"background-color: #fff; color: #337AB7; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #337AB7; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
},
warn: function (text) {
defaultConsole.warn("%cWARN: %c" + text,
"background-color: #fff; color: #F0AD4E; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #F0AD4E; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
},
error: function (text) {
defaultConsole.error("%cERROR: %c" + text,
"background-color: #fff; color: #D9534F; font-weight: bold; padding-left: 8px; font-size: 1.2em",
"background-color: #D9534F; color: #fff; font-weight: bold; padding: 0 8px; font-size: 1.2em");
}
};
}(window.console));
msg3.log('Log Message !');
msg3.info('Info Message !');
msg3.warn('Warn Message !');
msg3.error('Error Message !');
msg3.debug('Debug Message !');
msg3.dir('Dir Message !');
console.log
的同时调用不同的函数,以及调用原始的console.log
? - DCoder