All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.gkutiel.log.LogServerHandler Maven / Gradle / Ivy

There is a newer version: 0.1-RELEASE
Show newest version
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();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy