//For pink background and red textconsole.error("Hello World");
//For yellow background and brown textconsole.warn("Hello World");
//For just a INFO symbol at the beginning of the textconsole.info("Hello World");
//for custom colored textconsole.log('%cHello World','color:blue');//here blue could be replaced by any color code
//for custom colored text with custom background textconsole.log('%cHello World','background:red;color:#fff')
colors = {reset: '\033[0m',
//text color
black: '\033[30m',red: '\033[31m',green: '\033[32m',yellow: '\033[33m',blue: '\033[34m',magenta: '\033[35m',cyan: '\033[36m',white: '\033[37m',
//background color
blackBg: '\033[40m',redBg: '\033[41m',greenBg: '\033[42m',yellowBg: '\033[43m',blueBg: '\033[44m',magentaBg: '\033[45m',cyanBg: '\033[46m',whiteBg: '\033[47m'}
console.log('\033[31m this is red color on text');console.log('\033[0m this is reset');console.log('\033[41m this is red color on background');
var text = 'some text with some {special} formatting on this {keyword} and this {keyword}'var splitText = text.split(' ');var cssRules = [];var styledText = '';_.each(splitText, (split) => {if (/^\{/.test(split)) {cssRules.push('color:blue');} else {cssRules.push('color:inherit')}styledText += `%c${split} `});console.log(styledText , ...cssRules)
console.log('📕: error message');console.log('📙: warning message');console.log('📗: ok status message');console.log('📘: action message');console.log('📓: canceled status message');console.log('📔: Or anything you like and want to recognize immediately by color');
// An example of disabling logging depending on environment:const isLoggingEnabled = process.env.NODE_ENV !== 'production';
// Store the original logging function so we can trigger it laterconst originalConsoleLog = console.log;
// Override logging to perform our own logicconsole.log = (args: any) => {if (!isLoggingEnabled) {return;}
// Define some tokens and their corresponding CSSconst parsing = [{token: '[SUCCESS]',css: 'color: green; font-weight: bold;',},{token: '[ERROR]',css: 'color: red; font-weight: bold;',},{token: '[WARN]',css: 'color: orange; font-weight: bold;',},{token: '[DEBUG]',css: 'color: blue;',},];
// Currently only supports console.log(...) with a single string argument.if (typeof args === 'string') {const message: string = args;let formattedArgs: string[] = [];for (let i = 0; i < parsing.length; i += 1) {const parser = parsing[i];if (args.startsWith(parser.token)) {formattedArgs = [`%c${message.substring(parser.token.length + 1, message.length)}`, parser.css];break;}}originalConsoleLog.apply(console, formattedArgs);} else {originalConsoleLog.apply(console, args);}};