mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(tooling-api): use custom StatusListener for Logback
This commit is contained in:
@@ -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)
|
||||
|
||||
+6
@@ -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;
|
||||
@@ -48,6 +50,8 @@ public class Main {
|
||||
|
||||
// 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();
|
||||
@@ -131,6 +135,8 @@ public class Main {
|
||||
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);
|
||||
|
||||
+57
@@ -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()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user