From c0ef3afa82c1eaf58ff5efec961540a74b639fd9 Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Sun, 23 Feb 2014 11:40:55 -0800 Subject: SPARK-1071: Tidy logging strategy and use of log4j MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prompted by a recent thread on the mailing list, I tried and failed to see if Spark can be made independent of log4j. There are a few cases where control of the underlying logging is pretty useful, and to do that, you have to bind to a specific logger. Instead I propose some tidying that leaves Spark's use of log4j, but gets rid of warnings and should still enable downstream users to switch. The idea is to pipe everything (except log4j) through SLF4J, and have Spark use SLF4J directly when logging, and where Spark needs to output info (REPL and tests), bind from SLF4J to log4j. This leaves the same behavior in Spark. It means that downstream users who want to use something except log4j should: - Exclude dependencies on log4j, slf4j-log4j12 from Spark - Include dependency on log4j-over-slf4j - Include dependency on another logger X, and another slf4j-X - Recreate any log config that Spark does, that is needed, in the other logger's config That sounds about right. Here are the key changes: - Include the jcl-over-slf4j shim everywhere by depending on it in core. - Exclude dependencies on commons-logging from third-party libraries. - Include the jul-to-slf4j shim everywhere by depending on it in core. - Exclude slf4j-* dependencies from third-party libraries to prevent collision or warnings - Added missing slf4j-log4j12 binding to GraphX, Bagel module tests And minor/incidental changes: - Update to SLF4J 1.7.5, which happily matches Hadoop 2’s version and is a recommended update over 1.7.2 - (Remove a duplicate HBase dependency declaration in SparkBuild.scala) - (Remove a duplicate mockito dependency declaration that was causing warnings and bugging me) Author: Sean Owen Closes #570 from srowen/SPARK-1071 and squashes the following commits: 52eac9f [Sean Owen] Add slf4j-over-log4j12 dependency to core (non-test) and remove it from things that depend on core. 77a7fa9 [Sean Owen] SPARK-1071: Tidy logging strategy and use of log4j --- core/pom.xml | 31 ++++++++++++++++++++++--------- examples/pom.xml | 8 ++++---- external/flume/pom.xml | 5 ----- external/kafka/pom.xml | 9 ++++----- external/mqtt/pom.xml | 5 ----- external/twitter/pom.xml | 5 ----- external/zeromq/pom.xml | 5 ----- pom.xml | 28 ++++++++++++++++------------ project/SparkBuild.scala | 21 +++++++++++---------- repl/pom.xml | 4 ---- streaming/pom.xml | 5 ----- 11 files changed, 57 insertions(+), 69 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index dbcde0f434..5576b0c3b4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -39,6 +39,12 @@ net.java.dev.jets3t jets3t + + + commons-logging + commons-logging + + org.apache.avro @@ -68,6 +74,22 @@ org.slf4j slf4j-api + + org.slf4j + jul-to-slf4j + + + org.slf4j + jcl-over-slf4j + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + com.ning compress-lzf @@ -127,10 +149,6 @@ io.netty netty-all - - log4j - log4j - com.clearspring.analytics stream @@ -190,11 +208,6 @@ junit-interface test - - org.slf4j - slf4j-log4j12 - test - target/scala-${scala.binary.version}/classes diff --git a/examples/pom.xml b/examples/pom.xml index 874bbd803f..12a11821a4 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -115,6 +115,10 @@ org.jboss.netty netty + + commons-logging + commons-logging + @@ -161,10 +165,6 @@ jline jline - - log4j - log4j - org.apache.cassandra.deps avro diff --git a/external/flume/pom.xml b/external/flume/pom.xml index cdb9bef8e2..a0e8b84514 100644 --- a/external/flume/pom.xml +++ b/external/flume/pom.xml @@ -74,11 +74,6 @@ junit-interface test - - org.slf4j - slf4j-log4j12 - test - target/scala-${scala.binary.version}/classes diff --git a/external/kafka/pom.xml b/external/kafka/pom.xml index 630bbed5eb..fb37cd7988 100644 --- a/external/kafka/pom.xml +++ b/external/kafka/pom.xml @@ -61,6 +61,10 @@ net.sf.jopt-simple jopt-simple + + org.slf4j + slf4j-simple + @@ -78,11 +82,6 @@ junit-interface test - - org.slf4j - slf4j-log4j12 - test - target/scala-${scala.binary.version}/classes diff --git a/external/mqtt/pom.xml b/external/mqtt/pom.xml index eff3e7809b..cfa1870e98 100644 --- a/external/mqtt/pom.xml +++ b/external/mqtt/pom.xml @@ -89,11 +89,6 @@ junit-interface test - - org.slf4j - slf4j-log4j12 - test - target/scala-${scala.binary.version}/classes diff --git a/external/twitter/pom.xml b/external/twitter/pom.xml index cde495cac4..077f88dc59 100644 --- a/external/twitter/pom.xml +++ b/external/twitter/pom.xml @@ -70,11 +70,6 @@ junit-interface test - - org.slf4j - slf4j-log4j12 - test - target/scala-${scala.binary.version}/classes diff --git a/external/zeromq/pom.xml b/external/zeromq/pom.xml index 04f9fbfd5b..4c68294b7b 100644 --- a/external/zeromq/pom.xml +++ b/external/zeromq/pom.xml @@ -70,11 +70,6 @@ junit-interface test - - org.slf4j - slf4j-log4j12 - test - target/scala-${scala.binary.version}/classes diff --git a/pom.xml b/pom.xml index f94685652a..3a530685b8 100644 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ 0.13.0 org.spark-project.akka 2.2.3-shaded-protobuf - 1.7.2 + 1.7.5 1.2.17 1.0.4 2.4.1 @@ -185,6 +185,17 @@ jul-to-slf4j ${slf4j.version} + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + + log4j + log4j + ${log4j.version} + com.ning compress-lzf @@ -346,23 +357,12 @@ scala-library ${scala.version} - - log4j - log4j - ${log4j.version} - org.scalatest scalatest_${scala.binary.version} 1.9.1 test - - org.mockito - mockito-all - test - 1.8.5 - commons-io commons-io @@ -424,6 +424,10 @@ org.sonatype.sisu.inject * + + commons-logging + commons-logging + diff --git a/project/SparkBuild.scala b/project/SparkBuild.scala index 74bad66cfd..f0d2e74148 100644 --- a/project/SparkBuild.scala +++ b/project/SparkBuild.scala @@ -86,7 +86,7 @@ object SparkBuild extends Build { case None => DEFAULT_YARN case Some(v) => v.toBoolean } - lazy val hadoopClient = if (hadoopVersion.startsWith("0.20.") || hadoopVersion == "1.0.0") "hadoop-core" else "hadoop-client" + lazy val hadoopClient = if (hadoopVersion.startsWith("0.20.") || hadoopVersion == "1.0.0") "hadoop-core" else "hadoop-client" // Conditionally include the yarn sub-project lazy val yarnAlpha = Project("yarn-alpha", file("yarn/alpha"), settings = yarnAlphaSettings) dependsOn(core) @@ -236,13 +236,15 @@ object SparkBuild extends Build { publishLocalBoth <<= Seq(publishLocal in MavenCompile, publishLocal).dependOn ) ++ net.virtualvoid.sbt.graph.Plugin.graphSettings ++ ScalaStyleSettings - val slf4jVersion = "1.7.2" + val slf4jVersion = "1.7.5" val excludeCglib = ExclusionRule(organization = "org.sonatype.sisu.inject") val excludeJackson = ExclusionRule(organization = "org.codehaus.jackson") val excludeNetty = ExclusionRule(organization = "org.jboss.netty") val excludeAsm = ExclusionRule(organization = "asm") val excludeSnappy = ExclusionRule(organization = "org.xerial.snappy") + val excludeCommonsLogging = ExclusionRule(organization = "commons-logging") + val excludeSLF4J = ExclusionRule(organization = "org.slf4j") def coreSettings = sharedSettings ++ Seq( name := "spark-core", @@ -257,6 +259,8 @@ object SparkBuild extends Build { "log4j" % "log4j" % "1.2.17", "org.slf4j" % "slf4j-api" % slf4jVersion, "org.slf4j" % "slf4j-log4j12" % slf4jVersion, + "org.slf4j" % "jul-to-slf4j" % slf4jVersion, + "org.slf4j" % "jcl-over-slf4j" % slf4jVersion, "commons-daemon" % "commons-daemon" % "1.0.10", // workaround for bug HADOOP-9407 "com.ning" % "compress-lzf" % "1.0.0", "org.xerial.snappy" % "snappy-java" % "1.0.5", @@ -268,9 +272,9 @@ object SparkBuild extends Build { "it.unimi.dsi" % "fastutil" % "6.4.4", "colt" % "colt" % "1.2.0", "org.apache.mesos" % "mesos" % "0.13.0", - "net.java.dev.jets3t" % "jets3t" % "0.7.1", + "net.java.dev.jets3t" % "jets3t" % "0.7.1" excludeAll(excludeCommonsLogging), "org.apache.derby" % "derby" % "10.4.2.0" % "test", - "org.apache.hadoop" % hadoopClient % hadoopVersion excludeAll(excludeJackson, excludeNetty, excludeAsm, excludeCglib), + "org.apache.hadoop" % hadoopClient % hadoopVersion excludeAll(excludeJackson, excludeNetty, excludeAsm, excludeCglib, excludeCommonsLogging, excludeSLF4J), "org.apache.avro" % "avro" % "1.7.4", "org.apache.avro" % "avro-ipc" % "1.7.4" excludeAll(excludeNetty), "org.apache.zookeeper" % "zookeeper" % "3.4.5" excludeAll(excludeNetty), @@ -300,18 +304,15 @@ object SparkBuild extends Build { name := "spark-examples", libraryDependencies ++= Seq( "com.twitter" %% "algebird-core" % "0.1.11", - "org.apache.hbase" % "hbase" % "0.94.6" excludeAll(excludeNetty, excludeAsm), - "org.apache.hbase" % "hbase" % HBASE_VERSION excludeAll(excludeNetty, excludeAsm), + "org.apache.hbase" % "hbase" % HBASE_VERSION excludeAll(excludeNetty, excludeAsm, excludeCommonsLogging), "org.apache.cassandra" % "cassandra-all" % "1.2.6" exclude("com.google.guava", "guava") exclude("com.googlecode.concurrentlinkedhashmap", "concurrentlinkedhashmap-lru") exclude("com.ning","compress-lzf") exclude("io.netty", "netty") exclude("jline","jline") - exclude("log4j","log4j") exclude("org.apache.cassandra.deps", "avro") - excludeAll(excludeSnappy) - excludeAll(excludeCglib) + excludeAll(excludeSnappy, excludeCglib, excludeSLF4J) ) ) ++ assemblySettings ++ extraAssemblySettings @@ -416,7 +417,7 @@ object SparkBuild extends Build { exclude("com.sun.jdmk", "jmxtools") exclude("com.sun.jmx", "jmxri") exclude("net.sf.jopt-simple", "jopt-simple") - excludeAll(excludeNetty) + excludeAll(excludeNetty, excludeSLF4J) ) ) diff --git a/repl/pom.xml b/repl/pom.xml index 143b009f3c..73597f635b 100644 --- a/repl/pom.xml +++ b/repl/pom.xml @@ -72,10 +72,6 @@ org.slf4j jul-to-slf4j - - org.slf4j - slf4j-log4j12 - org.scalatest scalatest_${scala.binary.version} diff --git a/streaming/pom.xml b/streaming/pom.xml index d31ee60e4e..acc1d23c7d 100644 --- a/streaming/pom.xml +++ b/streaming/pom.xml @@ -79,11 +79,6 @@ junit-interface test - - org.slf4j - slf4j-log4j12 - test - commons-io commons-io -- cgit v1.2.3