~damien/jedit-lsp

bcb231b4390d614453730f53058f743541352e84 — Damien Radtke a month ago 64441f4
Reduce verbosity of logging by default
M src/main/java/lsp/Log.java => src/main/java/lsp/Log.java +17 -50
@@ 1,87 1,54 @@
package lsp;

import java.util.concurrent.atomic.AtomicInteger;

// TODO: keep track of the size of activity.log, and stop adding messages
// when it gets too big.

public class Log {
	private static AtomicInteger logCount = new AtomicInteger();
	private static int maxLogCount = 10000;
	private static boolean TRACE_ENABLED = false;

	private static boolean canLog() {
		int newLogCount = logCount.incrementAndGet();
		if (newLogCount >= maxLogCount) {
			if (newLogCount == maxLogCount) {
				org.gjt.sp.util.Log.log(
						org.gjt.sp.util.Log.WARNING,
						Log.class,
						"Maximum LSP log count of " + maxLogCount
								+ "has been reached. Disabling further logging to preserve space.");
			}
			return false;
		} else {
			return true;
	// trace() is just like debug(), except it is disabled by default. This is because
	// it normally logs messages that are quite large, and can easily take up a huge
	// amount of disk space.
	public static void trace(Object source, Object message) {
		if (TRACE_ENABLED) {
			debug(source, message);
		}
	}

	public static void debug(Object source, Object message) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.DEBUG, source, message);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.DEBUG, source, message);
	}

	public static void debug(Object source, Object message, Throwable exception) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.DEBUG, source, message, exception);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.DEBUG, source, message, exception);
	}

	public static void error(Object source, Object message) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.ERROR, source, message);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.ERROR, source, message);
	}

	public static void error(Object source, Object message, Throwable exception) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.ERROR, source, message, exception);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.ERROR, source, message, exception);
	}

	public static void message(Object source, Object message) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.MESSAGE, source, message);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.MESSAGE, source, message);
	}

	public static void message(Object source, Object message, Throwable exception) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.MESSAGE, source, message, exception);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.MESSAGE, source, message, exception);
	}

	public static void notice(Object source, Object message) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.NOTICE, source, message);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.NOTICE, source, message);
	}

	public static void notice(Object source, Object message, Throwable exception) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.NOTICE, source, message, exception);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.NOTICE, source, message, exception);
	}

	public static void warning(Object source, Object message) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.WARNING, source, message);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.WARNING, source, message);
	}

	public static void warning(Object source, Object message, Throwable exception) {
		if (canLog()) {
			org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.WARNING, source, message, exception);
		}
		org.gjt.sp.util.Log.log(org.gjt.sp.util.Log.WARNING, source, message, exception);
	}
}

M src/main/java/lsp/Server.java => src/main/java/lsp/Server.java +4 -0
@@ 699,6 699,10 @@ public class Server {
		}));
	}

	public void trace(Object message) {
		Log.trace(this, message);
	}

	public void debug(Object message) {
		Log.debug(this, message);
	}

M src/main/java/lsp/jEditLanguageClient.java => src/main/java/lsp/jEditLanguageClient.java +3 -4
@@ 107,7 107,7 @@ public class jEditLanguageClient implements LanguageClient {
		View view = jEdit.getActiveView();

		final String uri = params.getUri();
		Log.debug(this, "Diagnostics: " + params.toString());
		Log.trace(this, "Diagnostics: " + params.toString());
		this.diagnostics.put(uri, params.getDiagnostics());

		// Don't paint or send diagnostic errors if a completion popup is open.


@@ 267,7 267,7 @@ public class jEditLanguageClient implements LanguageClient {
	public void notifyProgress(ProgressParams params) {
		// It would be nice to show better messages here, but throwing
		// UnsupportedOperationException results in a very noisy activity log.
		Log.debug(this, params.toString());
		Log.trace(this, params.toString());

		if (params.getValue().isRight()) {
			Object value = params.getValue().getRight();


@@ 295,7 295,6 @@ public class jEditLanguageClient implements LanguageClient {
				default:
					Log.warning(this, "Progress sent unknown kind: " + notification.getKind());
			}
			Log.debug(this, "notification: " + notification.getKind());
		} else {
			Log.warning(this, "notifyProgress: neither left nor right");
		}


@@ 303,7 302,7 @@ public class jEditLanguageClient implements LanguageClient {

	@Override
	public CompletableFuture<List<Object>> configuration(ConfigurationParams params) {
		Log.debug(this, "configuration: " + params.toString());
		Log.trace(this, "configuration: " + params.toString());
		CompletableFuture<List<Object>> future = new CompletableFuture<>();
		ThreadUtilities.runInBackground(() -> {
			List<Object> config = new ArrayList<>(params.getItems().size());