jlibs.core.util.logging
Class AnsiFormatter
java.lang.Object
java.util.logging.Formatter
jlibs.core.util.logging.AnsiFormatter
public class AnsiFormatter
- extends Formatter
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.
- Author:
- Santhosh Kumar T
- See Also:
Ansi
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SEVERE
public static final Ansi SEVERE
WARNING
public static final Ansi WARNING
INFO
public static final Ansi INFO
CONFIG
public static final Ansi CONFIG
FINE
public static final Ansi FINE
FINER
public static final Ansi FINER
FINEST
public static final Ansi FINEST
AnsiFormatter
public AnsiFormatter(Formatter delegate)
AnsiFormatter
public AnsiFormatter()
format
public String format(LogRecord record)
- Specified by:
format in class Formatter
Copyright © 2018. All rights reserved.