com.github.gkutiel.log.LogServerHandler Maven / Gradle / Ivy
package com.github.gkutiel.log;
import java.io.IOException;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import com.github.gkutiel.util.Url;
import com.ning.http.client.AsyncHttpClient;
public class LogServerHandler extends Handler {
private static String info(final Throwable e) {
return e == null ? "" : e.getMessage();
}
private final String host;
AsyncHttpClient http = new AsyncHttpClient();
public LogServerHandler(final String host, final Level level) {
this.host = host;
setLevel(level);
}
@Override public void close() throws SecurityException {}
@Override public void flush() {}
@SuppressWarnings("unused") @Override public void publish(final LogRecord logRecord) {
try {
final String url = new Url(host + "/log") {
String info = info(logRecord.getThrown());
Level level = logRecord.getLevel();
String msg = logRecord.getMessage();
}.asString();
http.prepareGet(url).execute();
} catch (final IOException e) {
throw new RuntimeException();
}
}
}