diff options
author | Patrick Wendell <pwendell@gmail.com> | 2013-12-29 20:29:29 -0800 |
---|---|---|
committer | Patrick Wendell <pwendell@gmail.com> | 2013-12-29 23:14:33 -0800 |
commit | cffe1c1d5c0abfbb463fa91e8b340a9c535532fe (patch) | |
tree | 884ee12344cd7fa046029c7aecec5d17f34a2a2d /core/src | |
parent | 72a17b69f517ad7149d3bcd3a89e2cf715a2f65f (diff) | |
download | spark-cffe1c1d5c0abfbb463fa91e8b340a9c535532fe.tar.gz spark-cffe1c1d5c0abfbb463fa91e8b340a9c535532fe.tar.bz2 spark-cffe1c1d5c0abfbb463fa91e8b340a9c535532fe.zip |
SPARK-1008: Logging improvments
1. Adds a default log4j file that gets loaded if users haven't specified a log4j file.
2. Isolates use of the tools assembly jar. I found this produced SLF4J warnings
after building with SBT (and I've seen similar warnings on the mailing list).
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/resources/org/apache/spark/default-log4j.properties | 8 | ||||
-rw-r--r-- | core/src/main/scala/org/apache/spark/Logging.scala | 18 |
2 files changed, 23 insertions, 3 deletions
diff --git a/core/src/main/resources/org/apache/spark/default-log4j.properties b/core/src/main/resources/org/apache/spark/default-log4j.properties new file mode 100644 index 0000000000..d72dbadc39 --- /dev/null +++ b/core/src/main/resources/org/apache/spark/default-log4j.properties @@ -0,0 +1,8 @@ +# Set everything to be logged to the console +log4j.rootCategory=INFO, console +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n + +# Ignore messages below warning level from Jetty, because it's a bit verbose +log4j.logger.org.eclipse.jetty=WARN diff --git a/core/src/main/scala/org/apache/spark/Logging.scala b/core/src/main/scala/org/apache/spark/Logging.scala index 6a973ea495..a8892737fa 100644 --- a/core/src/main/scala/org/apache/spark/Logging.scala +++ b/core/src/main/scala/org/apache/spark/Logging.scala @@ -17,8 +17,8 @@ package org.apache.spark -import org.slf4j.Logger -import org.slf4j.LoggerFactory +import org.apache.log4j.{LogManager, PropertyConfigurator} +import org.slf4j.{Logger, LoggerFactory} /** * Utility trait for classes that want to log data. Creates a SLF4J logger for the class and allows @@ -91,5 +91,17 @@ trait Logging { // Method for ensuring that logging is initialized, to avoid having multiple // threads do it concurrently (as SLF4J initialization is not thread safe). - protected def initLogging() { log } + protected def initLogging() { + // If Log4j doesn't seem initialized, load a default properties file + def log4jInitialized = LogManager.getRootLogger.getAllAppenders.hasMoreElements + if (!log4jInitialized) { + val defaultLogProps = "org/apache/spark/default-log4j.properties" + val classLoader = this.getClass.getClassLoader + Option(classLoader.getResource(defaultLogProps)) match { + case Some(url) => PropertyConfigurator.configure(url) + case None => System.err.println(s"Spark was unable to load $defaultLogProps") + } + } + log + } } |