Permalink
Browse files

Add compatibility with Scala 2.13.0-M5

  • Loading branch information...
sarahgerweck committed Jan 30, 2019
1 parent f7627cf commit 3e2519ec65d3666f69b6ac8ecdfa362884bb537d
@@ -78,3 +78,8 @@ changes to how it's coded or built, see the Git history.
not benefit Log4s's runtime performance because it doesn't make use of
string interpolation. (It won't hurt performance either.) Compile-time
performance may be slightly better.

## 1.7

* Add Scala support for 2.13.0-M5
* Update Scala.js to 0.6.26
@@ -92,7 +92,17 @@ lazy val core = (crossProject(JSPlatform, JVMPlatform) in file ("core"))
case _ =>
Seq(baseDirectory.value / ".." / "shared" / "src" / "main" / "scala-2.11")
}
},

unmanagedSourceDirectories in Compile ++= {
scalaBinaryVersion.value match {
case "2.10" | "2.11" | "2.12" =>
Seq(baseDirectory.value / ".." / "shared" / "src" / "main" / "scala-oldcoll")
case _ =>
Seq(baseDirectory.value / ".." / "shared" / "src" / "main" / "scala-newcoll")
}
}

)
.jvmSettings(
libraryDependencies += "org.scala-js" %% "scalajs-stubs" % scalaJSVersion % "provided",
@@ -2,7 +2,7 @@ package org.log4s
package log4sjs

import scala.annotation.tailrec
import scala.collection.{ breakOut, mutable, immutable }
import scala.collection.{ mutable, immutable }
import scala.math.Ordered._

import scala.scalajs.js
@@ -140,11 +140,11 @@ object Log4sConfig extends Log4sConfig { thisConfig =>

@JSExportTopLevel("Config.setLoggerAppenders")
def setLoggerAppendersDynamic(name: String, additive: Boolean, appenders: js.Array[Log4sAppender.DynamicType]): Unit = {
setLoggerAppenders(name, additive, appenders)
setLoggerAppenders(name, additive, appenders.toSeq)
}

def setLoggerAppenders[A: Log4sAppender.Provider](name: String, additive: Boolean, appenders: Seq[A]): Unit = {
val appenderSeq: immutable.Seq[Log4sAppender] = appenders.map(Log4sAppender.from(_))(breakOut)
val appenderSeq: immutable.Seq[Log4sAppender] = appenders.map(Log4sAppender.from(_)).toList
logger(name, appenders = Some(Some(AppenderSetting(appenderSeq, additive))))
}

@@ -15,10 +15,10 @@ private object LoggerParserSpec {
object select
final class select(val cat: String) extends AnyVal {
def logger(s: String*): Assertion = {
catParser(cat) should equal (s.to[ISeq])
catParser(cat) should equal (s.toList)
}
@inline
def logger(s: ISeq[String]): Assertion = this.logger(s: _*)
def loggerOf(s: ISeq[String]): Assertion = this.logger(s: _*)
}

implicit final class LoggerString(val cat: String) extends AnyVal {
@@ -75,13 +75,13 @@ class LoggerParserSpec extends FlatSpec with PropertyChecks {
it should "handle simple alphanumeric paths" in {
forAll(simpleLoggerPath) { cat =>
val loggerName = makePath(cat)
loggerName should select logger cat
loggerName should select loggerOf cat
}
}
it should "handle complicated arbitrary paths" in {
forAll(complexLoggerPath) { cat =>
val loggerName = makePath(cat)
loggerName should select logger cat
loggerName should select loggerOf cat
}
}
}
@@ -0,0 +1,78 @@
package org.log4s

import java.util.{ Map => JMap }
import java.util.Collections.EMPTY_MAP

import scala.collection.JavaConverters._

import org.slf4j.{ MDC => JMDC }

/** A singleton used for accessing the mapped diagnostic context of your
* loggers. This acts like a regular map, except that the values are different
* in every thread.
*
* Getting and setting single values and clearing the map are fast operations
* operations, but other operations, including getting the size, requires
* making a copy of the MDC.
*/
object MDC extends collection.mutable.Map[String,String] {
@inline private[this] final def copyMap: JMap[String,String] = {
val mdcMap = JMDC.getCopyOfContextMap()
if (mdcMap != null)
mdcMap
else
EMPTY_MAP.asInstanceOf[JMap[String,String]]
}

final def addOne(kv: (String,String)): this.type = {
val (key, value) = kv
JMDC.put(key, value)
this
}

final def subtractOne(key: String): this.type = {
JMDC.remove(key)
this
}

override final def clear() = { JMDC.clear() }

final def get(key: String): Option[String] = Option(JMDC.get(key))

/** Get an iterator over the values of this map. This requires making a copy of
* the map, so it may cause performance problems if called frequently.
*/
final def iterator: Iterator[(String,String)] = copyMap.asScala.iterator

/** Get the size of this map This requires making a copy of the map, so it may
* cause performance problems if called frequently.
*/
override final def size: Int = copyMap.size

/** Execute a block of code with MDC variables set. After the block completes,
* any variables you've set will be returned to their previous values.
*/
def withCtx[A](kvs: (String,String)*)(v: => A): A = {
val old =
( for {
(a,b) <- kvs.toMap
} yield {
val tmp = (a, get(a))
this(a) = b
tmp
}
).toMap

try { v }
finally {
for {
(a, o) <- old
} {
o match {
case None => this -= a
case Some(v) => this(a) = v
}
}
}
}
}
@@ -4,10 +4,11 @@ import Keys._
object Dependencies {
final val slf4jVersion = "1.7.25"
final val logbackVersion = "1.2.3"
final val scalacheckVersion = "1.13.5"
final val scalacheckVersion = "1.14.0"

val scalatestVersion = Def.map(scalaBinaryVersion) {
case "2.13.0-M3" => "3.0.5-M1"
case "2.13.0-M5" => "3.0.6-SNAP6"
case other => "3.0.5"
}

@@ -15,8 +15,8 @@ trait ProjectSettings
override final val githubOrganization = "Log4s"
override final val githubProject = "log4s"

override final val buildScalaVersion = "2.12.6"
override final val extraScalaVersions = Seq("2.10.7", "2.11.12", "2.13.0-M2", "2.13.0-M3")
override final val buildScalaVersion = "2.12.8"
override final val extraScalaVersions = Seq("2.10.7", "2.11.12", "2.13.0-M5")
override final val minimumJavaVersion = "1.7"
override final val defaultOptimize = true
override final val defaultOptimizeGlobal = true

0 comments on commit 3e2519e

Please sign in to comment.