Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix(tooling-api): use custom StatusListener for Logback
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Mar 20, 2024
1 parent b7723c9 commit ae1bd6f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
return mBinder
}

override fun onListenerStarted(server: IToolingApiServer, projectProxy: IProject,
errorStream: InputStream) {
override fun onListenerStarted(
server: IToolingApiServer,
projectProxy: IProject,
errorStream: InputStream
) {
startServerOutputReader(errorStream)
this.server = server
Lookup.getDefault().update(BuildService.KEY_PROJECT_PROXY, projectProxy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

package com.itsaky.androidide.tooling.impl;

import ch.qos.logback.core.CoreConstants;
import com.itsaky.androidide.logging.JvmStdErrAppender;
import com.itsaky.androidide.tooling.api.IToolingApiClient;
import com.itsaky.androidide.tooling.api.util.ToolingApiLauncher;
import com.itsaky.androidide.tooling.impl.internal.ProjectImpl;
import com.itsaky.androidide.tooling.impl.logging.ToolingApiAppender;
import com.itsaky.androidide.tooling.impl.progress.ForwardingProgressListener;
import com.itsaky.androidide.tooling.impl.util.LogbackStatusListener;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
Expand All @@ -48,6 +50,8 @@ public static void main(String[] args) {

// disable the JVM std.err appender
System.setProperty(JvmStdErrAppender.PROP_JVM_STDERR_APPENDER_ENABLED, "false");
System.setProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY,
LogbackStatusListener.class.getName());

LOG.debug("Starting Tooling API server...");
final var project = new ProjectImpl();
Expand Down Expand Up @@ -131,6 +135,8 @@ public static void finalizeLauncher(ConfigurableLauncher<?> launcher) {
args.removeIf(String::isBlank);

LOG.debug("Arguments from tooling client: {}", args);
launcher.addJvmArguments("-D" + CoreConstants.STATUS_LISTENER_CLASS_KEY + "="
+ LogbackStatusListener.class.getName());
launcher.addArguments(args);
} catch (Throwable e) {
LOG.error("Unable to get build arguments from tooling client", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/

package com.itsaky.androidide.tooling.impl.util

import ch.qos.logback.core.status.Status
import ch.qos.logback.core.status.StatusListener
import ch.qos.logback.core.util.StatusPrinter
import com.itsaky.androidide.tooling.api.messages.LogMessageParams
import com.itsaky.androidide.tooling.impl.Main

/**
* @author Akash Yadav
*/
class LogbackStatusListener : StatusListener {

companion object {

private fun levelChar(level: Int): Char {
return when (level) {
Status.ERROR -> 'E'
Status.WARN -> 'W'
Status.INFO -> 'I'
else -> 'D'
}
}
}

override fun addStatusEvent(status: Status?) {
status ?: return
val sb = StringBuilder(256)
val client = Main.client
StatusPrinter.buildStr(sb, "", status)

client?.logMessage(
LogMessageParams(
levelChar(status.level),
status.origin.javaClass.simpleName,
sb.toString()
)
)
}
}

0 comments on commit ae1bd6f

Please sign in to comment.