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

Commit ae1bd6f

Browse files
committed
fix(tooling-api): use custom StatusListener for Logback
1 parent b7723c9 commit ae1bd6f

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

app/src/main/java/com/itsaky/androidide/services/builder/GradleBuildService.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,
226226
return mBinder
227227
}
228228

229-
override fun onListenerStarted(server: IToolingApiServer, projectProxy: IProject,
230-
errorStream: InputStream) {
229+
override fun onListenerStarted(
230+
server: IToolingApiServer,
231+
projectProxy: IProject,
232+
errorStream: InputStream
233+
) {
231234
startServerOutputReader(errorStream)
232235
this.server = server
233236
Lookup.getDefault().update(BuildService.KEY_PROJECT_PROXY, projectProxy)

subprojects/tooling-api-impl/src/main/java/com/itsaky/androidide/tooling/impl/Main.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
package com.itsaky.androidide.tooling.impl;
1919

20+
import ch.qos.logback.core.CoreConstants;
2021
import com.itsaky.androidide.logging.JvmStdErrAppender;
2122
import com.itsaky.androidide.tooling.api.IToolingApiClient;
2223
import com.itsaky.androidide.tooling.api.util.ToolingApiLauncher;
2324
import com.itsaky.androidide.tooling.impl.internal.ProjectImpl;
2425
import com.itsaky.androidide.tooling.impl.logging.ToolingApiAppender;
2526
import com.itsaky.androidide.tooling.impl.progress.ForwardingProgressListener;
27+
import com.itsaky.androidide.tooling.impl.util.LogbackStatusListener;
2628
import java.io.ByteArrayInputStream;
2729
import java.nio.charset.StandardCharsets;
2830
import java.util.HashSet;
@@ -48,6 +50,8 @@ public static void main(String[] args) {
4850

4951
// disable the JVM std.err appender
5052
System.setProperty(JvmStdErrAppender.PROP_JVM_STDERR_APPENDER_ENABLED, "false");
53+
System.setProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY,
54+
LogbackStatusListener.class.getName());
5155

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

133137
LOG.debug("Arguments from tooling client: {}", args);
138+
launcher.addJvmArguments("-D" + CoreConstants.STATUS_LISTENER_CLASS_KEY + "="
139+
+ LogbackStatusListener.class.getName());
134140
launcher.addArguments(args);
135141
} catch (Throwable e) {
136142
LOG.error("Unable to get build arguments from tooling client", e);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.itsaky.androidide.tooling.impl.util
19+
20+
import ch.qos.logback.core.status.Status
21+
import ch.qos.logback.core.status.StatusListener
22+
import ch.qos.logback.core.util.StatusPrinter
23+
import com.itsaky.androidide.tooling.api.messages.LogMessageParams
24+
import com.itsaky.androidide.tooling.impl.Main
25+
26+
/**
27+
* @author Akash Yadav
28+
*/
29+
class LogbackStatusListener : StatusListener {
30+
31+
companion object {
32+
33+
private fun levelChar(level: Int): Char {
34+
return when (level) {
35+
Status.ERROR -> 'E'
36+
Status.WARN -> 'W'
37+
Status.INFO -> 'I'
38+
else -> 'D'
39+
}
40+
}
41+
}
42+
43+
override fun addStatusEvent(status: Status?) {
44+
status ?: return
45+
val sb = StringBuilder(256)
46+
val client = Main.client
47+
StatusPrinter.buildStr(sb, "", status)
48+
49+
client?.logMessage(
50+
LogMessageParams(
51+
levelChar(status.level),
52+
status.origin.javaClass.simpleName,
53+
sb.toString()
54+
)
55+
)
56+
}
57+
}

0 commit comments

Comments
 (0)