IJPL-166435 IJent: change log level of the server-side app in runtime

(cherry picked from commit 582b8d52d52c4776188f1fc22fe896d9fb40c9e4)

IJ-CR-148991

GitOrigin-RevId: 762baeed11b0785d735943d22a8e662a7a33ce50
This commit is contained in:
Vladimir Lagunov
2024-11-08 16:16:33 +01:00
committed by intellij-monorepo-bot
parent a992979edb
commit ad9bc79cb7
3 changed files with 18 additions and 13 deletions

View File

@@ -3,9 +3,7 @@
package com.intellij.platform.ijent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.registry.Registry
import com.intellij.util.containers.map2Array
/**
@@ -17,23 +15,12 @@ fun getIjentGrpcArgv(
selfDeleteOnExit: Boolean = false,
usrBinEnv: String = "/usr/bin/env",
): List<String> {
val debuggingLogLevel = when {
LOG.isTraceEnabled &&
(ApplicationManager.getApplication()?.isUnitTestMode == true || System.getProperty("ijent.trace.all") == "true") ->
"trace-all"
LOG.isTraceEnabled -> "trace"
LOG.isDebugEnabled -> "debug"
else -> "info"
}
return listOfNotNull(
usrBinEnv,
*additionalEnv.entries.map2Array { (k, v) -> "$k=$v" },
// "gdbserver", "0.0.0.0:12345", // https://sourceware.org/gdb/onlinedocs/gdb/Connecting.html
remotePathToIjent,
"grpc-stdio-server",
"--log-level", debuggingLogLevel,
if (selfDeleteOnExit) "--self-delete-on-exit" else null,
)
}

View File

@@ -3,7 +3,9 @@ package com.intellij.diagnostic.logs
import com.intellij.openapi.components.*
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.extensions.ExtensionPointName
import kotlinx.serialization.Serializable
import org.jetbrains.annotations.ApiStatus.Internal
import java.util.logging.Level
/**
@@ -28,6 +30,20 @@ class LogLevelConfigurationManager : SerializablePersistentStateComponent<LogLev
fun getInstance(): LogLevelConfigurationManager = service()
}
@Internal
interface Listener {
/**
* Instead of sending changes diff,
* it is supposed that implementations look at [com.intellij.openapi.diagnostic.Logger.isDebugEnabled] themselves.
*/
fun onCategoriesChanged()
companion object {
@JvmField
val EP_NAME: ExtensionPointName<Listener> = ExtensionPointName.create("com.intellij.logLevelConfigurationListener")
}
}
private val customizedLoggers = mutableListOf<java.util.logging.Logger>()
private val lock = Object()
@@ -41,6 +57,7 @@ class LogLevelConfigurationManager : SerializablePersistentStateComponent<LogLev
updateState {
it.copy(categories = appliedCategories)
}
Listener.EP_NAME.forEachExtensionSafe { it.onCategoriesChanged() }
}
private fun String.toTrimmed(): String = trimStart('#')

View File

@@ -600,5 +600,6 @@
interface="com.intellij.auth.GenericAuthProviderExtension" dynamic="true"/>
<extensionPoint name="findInDirectoryScopeProvider" interface="com.intellij.find.impl.FindInDirectoryScopeProvider" dynamic="true"/>
<extensionPoint name="logLevelConfigurationListener" interface="com.intellij.diagnostic.logs.LogLevelConfigurationManager$Listener" dynamic="true"/>
</extensionPoints>
</idea-plugin>