Merge pull request #3791 from eed3si9n/wip/serverLog

Fixes server log hardcoded to debug level
This commit is contained in:
eugene yokota 2017-12-04 13:33:27 -05:00 committed by GitHub
commit 4c435a5adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import java.io.File
import sbt.internal.util.AttributeKey
import sbt.internal.inc.classpath.ClassLoaderCache
import sbt.librarymanagement.ModuleID
import sbt.util.Level
object BasicKeys {
val historyPath = AttributeKey[Option[File]](
@ -38,6 +39,14 @@ object BasicKeys {
"The wire protocol for the server command.",
10000)
// Unlike other BasicKeys, this is not used directly as a setting key,
// and severLog / logLevel is used instead.
private[sbt] val serverLogLevel =
AttributeKey[Level.Value]("serverLogLevel", "The log level for the server.", 10000)
private[sbt] val logLevel =
AttributeKey[Level.Value]("logLevel", "The amount of logging sent to the screen.", 10)
private[sbt] val interactive = AttributeKey[Boolean](
"interactive",
"True if commands are currently being entered from an interactive environment.",

View File

@ -94,7 +94,7 @@ object Keys {
val TraceValues = "-1 to disable, 0 for up to the first sbt frame, or a positive number to set the maximum number of frames shown."
// logging
val logLevel = settingKey[Level.Value]("The amount of logging sent to the screen.").withRank(ASetting)
val logLevel = SettingKey(BasicKeys.logLevel).withRank(ASetting)
val persistLogLevel = settingKey[Level.Value]("The amount of logging sent to a file for persistence.").withRank(CSetting)
val traceLevel = settingKey[Int]("The amount of a stack trace displayed. " + TraceValues).withRank(ASetting)
val persistTraceLevel = settingKey[Int]("The amount of stack trace persisted.").withRank(CSetting)
@ -105,6 +105,7 @@ object Keys {
val logManager = settingKey[LogManager]("The log manager, which creates Loggers for different contexts.").withRank(DSetting)
val logBuffered = settingKey[Boolean]("True if logging should be buffered until work completes.").withRank(CSetting)
val sLog = settingKey[Logger]("Logger usable by settings during project loading.").withRank(CSetting)
val serverLog = taskKey[Unit]("A dummy task to set server log level using Global / serverLog / logLevel.").withRank(CTask)
// Project keys
val autoGeneratedProject = settingKey[Boolean]("If it exists, represents that the project (and name) were automatically created, rather than user specified.").withRank(DSetting)

View File

@ -11,6 +11,7 @@ import java.io.File
import java.net.URI
import java.util.Locale
import Project._
import BasicKeys.serverLogLevel
import Keys.{
stateBuildStructure,
commands,
@ -21,9 +22,11 @@ import Keys.{
shellPrompt,
templateResolverInfos,
serverHost,
serverLog,
serverPort,
serverAuthentication,
serverConnectionType,
logLevel,
watch
}
import Scope.{ Global, ThisScope }
@ -41,7 +44,7 @@ import sbt.internal.util.{ AttributeKey, AttributeMap, Dag, Relation, Settings,
import sbt.internal.util.Types.{ const, idFun }
import sbt.internal.util.complete.DefaultParsers
import sbt.librarymanagement.Configuration
import sbt.util.Show
import sbt.util.{ Show, Level }
import sjsonnew.JsonFormat
import language.experimental.macros
@ -463,6 +466,7 @@ object Project extends ProjectExtra {
val port: Option[Int] = get(serverPort)
val authentication: Option[Set[ServerAuthentication]] = get(serverAuthentication)
val connectionType: Option[ConnectionType] = get(serverConnectionType)
val srvLogLevel: Option[Level.Value] = (logLevel in (ref, serverLog)).get(structure.data)
val commandDefs = allCommands.distinct.flatten[Command].map(_ tag (projectCommand, true))
val newDefinedCommands = commandDefs ++ BasicCommands.removeTagged(s.definedCommands,
projectCommand)
@ -477,6 +481,7 @@ object Project extends ProjectExtra {
.put(historyPath.key, history)
.put(templateResolverInfos.key, trs)
.setCond(shellPrompt.key, prompt)
.setCond(serverLogLevel, srvLogLevel)
s.copy(
attributes = newAttrs,
definedCommands = newDefinedCommands

View File

@ -13,7 +13,14 @@ import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.atomic.AtomicInteger
import scala.collection.mutable.ListBuffer
import scala.annotation.tailrec
import BasicKeys.{ serverHost, serverPort, serverAuthentication, serverConnectionType }
import BasicKeys.{
serverHost,
serverPort,
serverAuthentication,
serverConnectionType,
serverLogLevel,
logLevel
}
import java.net.Socket
import sjsonnew.JsonFormat
import sjsonnew.shaded.scalajson.ast.unsafe._
@ -106,7 +113,10 @@ private[sbt] final class CommandExchange {
case Some(x) => x
case None => ConnectionType.Tcp
}
val serverLogLevel: Level.Value = Level.Debug
lazy val level: Level.Value = (s get serverLogLevel)
.orElse(s get logLevel)
.getOrElse(Level.Warn)
def onIncomingSocket(socket: Socket, instance: ServerInstance): Unit = {
val name = newNetworkName
s.log.info(s"new client connected: $name")
@ -114,7 +124,7 @@ private[sbt] final class CommandExchange {
val log = LogExchange.logger(name, None, None)
LogExchange.unbindLoggerAppenders(name)
val appender = MainAppender.defaultScreen(s.globalLogging.console)
LogExchange.bindLoggerAppenders(name, List(appender -> serverLogLevel))
LogExchange.bindLoggerAppenders(name, List(appender -> level))
log
}
val channel =