Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Be more aggressive when checking if a log message should be sent to the underlying logger #131

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: scala
jdk: oraclejdk8

scala:
- 2.11.11
- 2.12.3
- 2.11.12
- 2.12.4

script:
- sbt -Dfile.encoding=UTF8 -J-XX:ReservedCodeCacheSize=256M "++$TRAVIS_SCALA_VERSION" mimaReportBinaryIssues scalafmt::test test:scalafmt::test test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package sbt.internal.util

import sbt.util._
import sbt.util.{ Level, _ }
import org.apache.logging.log4j.{ Logger => XLogger }
import org.apache.logging.log4j.message.ObjectMessage
import sjsonnew.JsonFormat

import scala.reflect.runtime.universe.TypeTag
import sbt.internal.util.codec.JsonProtocol._

Expand All @@ -19,10 +20,12 @@ class ManagedLogger(
override def trace(t: => Throwable): Unit =
logEvent(Level.Error, TraceEvent("Error", t, channelName, execId))
override def log(level: Level.Value, message: => String): Unit = {
xlogger.log(
ConsoleAppender.toXLevel(level),
new ObjectMessage(StringEvent(level.toString, message, channelName, execId))
)
if (shouldLog(level)) {
xlogger.log(
ConsoleAppender.toXLevel(level),
new ObjectMessage(StringEvent(level.toString, message, channelName, execId))
)
}
}

// send special event for success since it's not a real log level
Expand All @@ -38,18 +41,24 @@ class ManagedLogger(
final def infoEvent[A: JsonFormat: TypeTag](event: => A): Unit = logEvent(Level.Info, event)
final def warnEvent[A: JsonFormat: TypeTag](event: => A): Unit = logEvent(Level.Warn, event)
final def errorEvent[A: JsonFormat: TypeTag](event: => A): Unit = logEvent(Level.Error, event)

def logEvent[A: JsonFormat: TypeTag](level: Level.Value, event: => A): Unit = {
val v: A = event
val tag = StringTypeTag[A]
LogExchange.getOrElseUpdateJsonCodec(tag.key, implicitly[JsonFormat[A]])
// println("logEvent " + tag.key)
val entry: ObjectEvent[A] = ObjectEvent(level, v, channelName, execId, tag.key)
xlogger.log(
ConsoleAppender.toXLevel(level),
new ObjectMessage(entry)
)
if (shouldLog(level)) {
val v: A = event
val tag = StringTypeTag[A]
LogExchange.getOrElseUpdateJsonCodec(tag.key, implicitly[JsonFormat[A]])
// println("logEvent " + tag.key)
val entry: ObjectEvent[A] = ObjectEvent(level, v, channelName, execId, tag.key)
xlogger.log(
ConsoleAppender.toXLevel(level),
new ObjectMessage(entry)
)
}
}

private def shouldLog(level: Level.Value) =
xlogger.getLevel.isMoreSpecificThan(ConsoleAppender.toXLevel(level))

@deprecated("No longer used.", "1.0.0")
override def ansiCodesSupported = ConsoleAppender.formatEnabledInEnv
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ abstract class AbstractLogger extends Logger {
/** Defined in terms of other methods in Logger and should not be called from them. */
final def log(event: LogEvent): Unit = {
event match {
case s: Success => success(s.msg)
case l: Log => log(l.level, l.msg)
case t: Trace => trace(t.exception)
case s: Success => if (successEnabled) success(s.msg)
case l: Log => if (atLevel(l.level)) log(l.level, l.msg)
case t: Trace => if (traceEnabled) trace(t.exception)
case setL: SetLevel => setLevel(setL.newLevel)
case setT: SetTrace => setTrace(setT.level)
case setS: SetSuccess => setSuccessEnabled(setS.enabled)
Expand Down
6 changes: 3 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import sbt.contraband.ContrabandPlugin.autoImport._

object Dependencies {
val scala210 = "2.10.6"
val scala211 = "2.11.11"
val scala212 = "2.12.3"
val scala211 = "2.11.12"
val scala212 = "2.12.4"

private val ioVersion = "1.0.0"
private val ioVersion = "1.0.2"

private val sbtIO = "org.scala-sbt" %% "io" % ioVersion

Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scala-sbt" % "sbt-houserules" % "0.3.3")
addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.0")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.17")
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.10")
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.14")