🎨 How to use Colors
ColorLogger leverages ANSI escape codes to bring vibrant colors to your console. Depending on your terminal, you can use either common ANSI colors or the extended TrueColor system for more flexibility.
Common ANSI Codes
These colors are supported by virtually all terminals. Here are the available options:
Color | Code | Example |
---|---|---|
Black | \x1b[30m | Black |
Red | \x1b[31m | Red |
Green | \x1b[32m | Green |
Yellow | \x1b[33m | Yellow |
Blue | \x1b[34m | Blue |
Magenta | \x1b[35m | Magenta |
Cyan | \x1b[36m | Cyan |
White | \x1b[37m | White |
TrueColor System
For more precise control, the TrueColor system allows you to define colors with full 24-bit RGB values. Use the
format \x1b[38;2;R;G;Bm
for text color and \x1b[48;2;R;G;Bm
for background color.
Logger.config({
levels: {
info: { color: '\x1b[38;2;0;128;255m', bg: '\x1b[48;2;0;0;0m' }, // Soft blue, black bg
success: { color: '\x1b[38;2;0;255;128m' }, // Lime green
},
});`;
Please note that the browser console will accept true color format, and also the majority of terminals. However the older ones may not display the color correctly (hello old Powershell)
Hex and RGB Support
For convenience, you can use colors in either Hex format or RGB arrays. The Logger will automatically convert these into TrueColor codes.
Examples
// Using Hex
Logger.config({
levels: {
warning: { color: '#FFA500' }, // Orange
},
});
// Using RGB
Logger.config({
levels: {
critical: { color: [255, 0, 255] }, // Magenta
},
});