Merge pull request #4232 from eed3si9n/wip/run-logging

Fixes the stacktrace of run
This commit is contained in:
eugene yokota 2018-06-27 12:58:10 -04:00 committed by GitHub
commit a46c07d5f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 4 deletions

View File

@ -302,7 +302,7 @@ lazy val runProj = (project in file("run"))
exclude[DirectMissingMethodProblem]("sbt.OutputStrategy#LoggedOutput.copy$default$*"), exclude[DirectMissingMethodProblem]("sbt.OutputStrategy#LoggedOutput.copy$default$*"),
) )
) )
.configure(addSbtIO, addSbtUtilLogging, addSbtCompilerClasspath) .configure(addSbtIO, addSbtUtilLogging, addSbtUtilControl, addSbtCompilerClasspath)
val sbtProjDepsCompileScopeFilter = val sbtProjDepsCompileScopeFilter =
ScopeFilter(inDependencies(LocalProject("sbtProj"), includeRoot = false), inConfigurations(Compile)) ScopeFilter(inDependencies(LocalProject("sbtProj"), includeRoot = false), inConfigurations(Compile))

View File

@ -154,6 +154,8 @@ object Defaults extends BuildCommon {
classpathEntryDefinesClass :== FileValueCache(Locate.definesClass _).get, classpathEntryDefinesClass :== FileValueCache(Locate.definesClass _).get,
traceLevel in run :== 0, traceLevel in run :== 0,
traceLevel in runMain :== 0, traceLevel in runMain :== 0,
traceLevel in bgRun :== 0,
traceLevel in fgRun :== 0,
traceLevel in console :== Int.MaxValue, traceLevel in console :== Int.MaxValue,
traceLevel in consoleProject :== Int.MaxValue, traceLevel in consoleProject :== Int.MaxValue,
autoCompilerPlugins :== true, autoCompilerPlugins :== true,

View File

@ -198,13 +198,19 @@ object LogManager {
val scope = task.scope val scope = task.scope
val screenLevel = getOr(logLevel.key, data, scope, state, Level.Info) val screenLevel = getOr(logLevel.key, data, scope, state, Level.Info)
val backingLevel = getOr(persistLogLevel.key, data, scope, state, Level.Debug) val backingLevel = getOr(persistLogLevel.key, data, scope, state, Level.Debug)
val screenTrace = getOr(traceLevel.key, data, scope, state, 0)
val execOpt = state.currentCommand val execOpt = state.currentCommand
val loggerName: String = s"bg-${task.key.label}-${generateId.incrementAndGet}" val loggerName: String = s"bg-${task.key.label}-${generateId.incrementAndGet}"
val channelName: Option[String] = execOpt flatMap (_.source map (_.channelName)) val channelName: Option[String] = execOpt flatMap (_.source map (_.channelName))
// val execId: Option[String] = execOpt flatMap { _.execId } // val execId: Option[String] = execOpt flatMap { _.execId }
val log = LogExchange.logger(loggerName, channelName, None) val log = LogExchange.logger(loggerName, channelName, None)
LogExchange.unbindLoggerAppenders(loggerName) LogExchange.unbindLoggerAppenders(loggerName)
val consoleOpt = consoleLocally(state, console) val consoleOpt = consoleLocally(state, console) map {
case a: ConsoleAppender =>
a.setTrace(screenTrace)
a
case a => a
}
LogExchange.bindLoggerAppenders( LogExchange.bindLoggerAppenders(
loggerName, loggerName,
(consoleOpt.toList map { _ -> screenLevel }) ::: (relay -> backingLevel) :: Nil (consoleOpt.toList map { _ -> screenLevel }) ::: (relay -> backingLevel) :: Nil

View File

@ -12,6 +12,7 @@ import java.lang.reflect.{ Method, Modifier }
import Modifier.{ isPublic, isStatic } import Modifier.{ isPublic, isStatic }
import sbt.internal.inc.classpath.ClasspathUtilities import sbt.internal.inc.classpath.ClasspathUtilities
import sbt.internal.inc.ScalaInstance import sbt.internal.inc.ScalaInstance
import sbt.internal.util.MessageOnlyException
import sbt.io.Path import sbt.io.Path
@ -29,7 +30,9 @@ class ForkRun(config: ForkOptions) extends ScalaRun {
if (exitCode == 0) Success(()) if (exitCode == 0) Success(())
else else
Failure( Failure(
new RuntimeException(s"""Nonzero exit code returned from $label: $exitCode""".stripMargin) new MessageOnlyException(
s"""Nonzero exit code returned from $label: $exitCode""".stripMargin
)
) )
val process = fork(mainClass, classpath, options, log) val process = fork(mainClass, classpath, options, log)
def cancel() = { def cancel() = {
@ -124,6 +127,6 @@ object Run {
if (exitCode == 0) { if (exitCode == 0) {
log.debug("Exited with code 0") log.debug("Exited with code 0")
Success(()) Success(())
} else Failure(new RuntimeException("Nonzero exit code: " + exitCode)) } else Failure(new MessageOnlyException("Nonzero exit code: " + exitCode))
} }
} }