Skip to content

Commit a75ff8f

Browse files
author
Andrew Or
committed
Fix hive-thrift server log4j problem
This is the equivalent of 5cd6a63 and 4782e13 in master.
1 parent f782edd commit a75ff8f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import scala.concurrent.{Await, Promise}
2626
import scala.sys.process.{Process, ProcessLogger}
2727
import scala.util.{Random, Try}
2828

29+
import com.google.common.base.Charsets.UTF_8
30+
import com.google.common.io.Files
2931
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
3032
import org.apache.hive.jdbc.HiveDriver
3133
import org.apache.hive.service.auth.PlainSaslHelper
@@ -286,6 +288,24 @@ abstract class HiveThriftServer2Test extends SparkFunSuite with BeforeAndAfterAl
286288
ConfVars.HIVE_SERVER2_THRIFT_HTTP_PORT
287289
}
288290

291+
val driverClassPath = {
292+
// Writes a temporary log4j.properties and prepend it to driver classpath, so that it
293+
// overrides all other potential log4j configurations contained in other dependency jar files.
294+
val tempLog4jConf = Utils.createTempDir().getCanonicalPath
295+
296+
Files.write(
297+
"""log4j.rootCategory=INFO, console
298+
|log4j.appender.console=org.apache.log4j.ConsoleAppender
299+
|log4j.appender.console.target=System.err
300+
|log4j.appender.console.layout=org.apache.log4j.PatternLayout
301+
|log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n
302+
""".stripMargin,
303+
new File(s"$tempLog4jConf/log4j.properties"),
304+
UTF_8)
305+
306+
tempLog4jConf + File.pathSeparator + sys.props("java.class.path")
307+
}
308+
289309
s"""$startScript
290310
| --master local
291311
| --hiveconf hive.root.logger=INFO,console
@@ -295,6 +315,8 @@ abstract class HiveThriftServer2Test extends SparkFunSuite with BeforeAndAfterAl
295315
| --hiveconf ${ConfVars.HIVE_SERVER2_TRANSPORT_MODE}=$mode
296316
| --hiveconf $portConf=$port
297317
| --driver-class-path ${sys.props("java.class.path")}
318+
| --driver-class-path $driverClassPath
319+
| --driver-java-options -Dlog4j.debug
298320
| --conf spark.ui.enabled=false
299321
""".stripMargin.split("\\s+").toSeq
300322
}

0 commit comments

Comments
 (0)