@@ -26,6 +26,8 @@ import scala.concurrent.{Await, Promise}
2626import scala .sys .process .{Process , ProcessLogger }
2727import scala .util .{Random , Try }
2828
29+ import com .google .common .base .Charsets .UTF_8
30+ import com .google .common .io .Files
2931import org .apache .hadoop .hive .conf .HiveConf .ConfVars
3032import org .apache .hive .jdbc .HiveDriver
3133import 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