This is an implementation of
Formatter, to use ansi colors in logging.
Example Usage:
Logger logger = LogManager.getLogManager().getLogger("");
logger.setLevel(Level.FINEST);
Handler handler = logger.getHandlers()[0];
handler.setLevel(Level.FINEST);
handler.setFormatter(new AnsiFormatter());
for(Level level: map.keySet())
logger.log(level, "this is "+level+" message"); *
This class has public final constants to access Ansi instance used for each level.
These constants are made public, so that you can use them any where. for example you can do:
import static jlibs.core.util.logging.AnsiFormatter.*;
SEVERE.out("User authentication failed");
The colors used by AnsiFormatter for any level can be changed to match you taste. To do this you need to create a properties file.
for example:
# myansi.properties
SEVERE=DIM;RED;GREEN
WARNING=BRIGHT;RED;YELLOW
Now use following system property:
-Dansiformatter.default=/path/to/myansi.properties
Each entry in this property file is to be given as below:
LEVEL=Attribute[;Foreground[;Background]]
key is the level name;
value is semicolon(;) separated values, where where tokens are attribute, foreground and background respectively.
if any non-trailing token in value is null, you still need to specify empty value. for example:
SEVERE=DIM;;GREEN # foreground is not specified
In your properties file, you don't need to specify entries for each level. you can specify entries only for those levels that you want to change.