You can intercept a logging operation just before it is flushed to the console or file. That will be useful if you for example want to implement a log server or send your logs to syslog. See the example below:
public class TestInterceptor implements Interceptor { @Override public boolean onLogBuffer(ByteBuffer bb, Log level) { // do whatever you want to do with the bytebuffer containing the log contents // you can also know if this is a level log by the level parameter passed (it can be null if this interceptor is intecepting a custom logger that is not a level) // then you can return true, so the logging operation continues // or false if you want to abort the logging operation after you have done what you want with the buffer return true; } }
Then to add the interceptor you can do:
// Then you just add the interceptor Interceptor interceptor = new TestInterceptor(); // to all levels: Log.add(interceptor); // to a single level: Warn.addInterceptor(interceptor); // to any logger you have created: logger.addInterceptor(interceptor);