Skip to content

Instantly share code, notes, and snippets.

@jherskow
Created February 25, 2025 16:19
Show Gist options
  • Save jherskow/35cfee5e60f67e7572110bce12a9c01a to your computer and use it in GitHub Desktop.
Save jherskow/35cfee5e60f67e7572110bce12a9c01a to your computer and use it in GitHub Desktop.
const colorize = (color: string, message: string) => {
const ansiColors: Record<string, string> = {
green: '\x1b[32m',
orange: '\x1b[33m', // Yellow (closest to orange in ANSI)
red: '\x1b[31m',
redBG: '\x1b[41m', // Red background
blue: '\x1b[34m',
blueBG: '\x1b[44m', // Blue background
pink: '\x1b[35m', // Magenta (closest to pink)
pinkBG: '\x1b[45m', // Magenta background
reset: '\x1b[0m',
};
if (color.endsWith('BG')) {
return [`${ansiColors[color]} ${message} ${ansiColors.reset}`];
}
return [`${ansiColors[color] ?? ''}${message}${ansiColors.reset}`];
};
export const jconsole = {
log: (...args: any[]) => {
console.log(...colorize('blueBG', '[JLOG]'), ...args);
},
warn: (...args: any[]) => {
console.warn(...colorize('pinkBG', '[JWARN]'), ...args);
},
error: (...args: any[]) => {
console.error(...colorize('redBG', '[JERROR]'), ...args);
},
info: (...args: any[]) => {
console.info(...colorize('green', '[JINFO]'), ...args);
},
debug: (...args: any[]) => {
console.debug(...colorize('blue', '[JDEBUG]'), ...args);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment