2022-06-01 16:50:46 +03:00
|
|
|
package sbt.internal.util
|
|
|
|
|
|
|
|
import sbt.internal.LogManager
|
2023-03-11 03:15:58 +03:00
|
|
|
import sbt.internal.util.ConsoleAppender.{noSuppressedMessage, Properties}
|
2022-06-01 16:50:46 +03:00
|
|
|
|
|
|
|
object CustomLogManager {
|
|
|
|
def excludeMsg(msgPrefix: String, level: sbt.Level.Value): LogManager = {
|
2023-03-11 03:15:58 +03:00
|
|
|
sbt.internal.LogManager.withLoggers((_, _) =>
|
|
|
|
new CustomAppender(level, msgPrefix, ConsoleOut.systemOut)
|
|
|
|
)
|
2022-06-01 16:50:46 +03:00
|
|
|
}
|
|
|
|
|
2023-03-11 03:15:58 +03:00
|
|
|
/** Returns a custom ConsoleAppender that will skip log messages starting with a certain prefix.
|
2022-06-01 16:50:46 +03:00
|
|
|
*
|
|
|
|
* The only reason for such appender is to force SBT to keep quiet about certain kind of messages
|
|
|
|
* coming from the analyzing compiler (wrapper around java compiler) when it tries to match class files
|
|
|
|
* to source files. There is absolutely no way to tell SBT that that some sources are being generated from
|
|
|
|
* annotation processors and it will get them during the same compilation round. Nor can we easily
|
|
|
|
* suppress such warning.
|
|
|
|
*
|
|
|
|
* @param excludeLevel level of log message to exclude (together with prefix)
|
|
|
|
* @param prefix prefix of log message to exclude (together with log level)
|
|
|
|
* @param out object representing console output
|
|
|
|
*/
|
2023-03-11 03:15:58 +03:00
|
|
|
final private class CustomAppender(
|
|
|
|
excludeLevel: sbt.Level.Value,
|
|
|
|
prefix: String,
|
|
|
|
out: ConsoleOut
|
|
|
|
) extends ConsoleAppender(
|
|
|
|
"out",
|
|
|
|
Properties
|
|
|
|
.from(out, Terminal.isAnsiSupported, Terminal.isAnsiSupported),
|
|
|
|
noSuppressedMessage
|
|
|
|
) {
|
2022-06-01 16:50:46 +03:00
|
|
|
override def appendLog(level: sbt.Level.Value, message: => String): Unit = {
|
|
|
|
if (excludeLevel != level || !message.startsWith(prefix)) {
|
|
|
|
super.appendLog(level, message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|