Skip to content

Commit 1e2c06e

Browse files
committed
[query] use log4j-api-scala for string interpolation
1 parent 7df0197 commit 1e2c06e

File tree

82 files changed

+436
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+436
-350
lines changed

hail/build.mill

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ object Deps {
5252
def core: Task[Dep] = Task.Anon(mvn"org.apache.spark::spark-core:${Env.sparkVersion()}")
5353
def mllib: Task[Dep] = Task.Anon(mvn"org.apache.spark::spark-mllib:${Env.sparkVersion()}")
5454
}
55-
55+
5656
object Log4j {
5757
// have to forceVersion for reasons unknown?
5858
val bom = mvn"org.apache.logging.log4j:log4j-bom:2.25.2".forceVersion()
5959
val api = mvn"org.apache.logging.log4j:log4j-api"
6060
val core = mvn"org.apache.logging.log4j:log4j-core"
6161
val slf4j = mvn"org.apache.logging.log4j:log4j-slf4j2-impl"
62+
63+
val scala = mvn"org.apache.logging.log4j::log4j-api-scala:13.1.0"
6264
}
6365

6466
val samtools = mvn"com.github.samtools:htsjdk:3.0.5"
@@ -289,6 +291,7 @@ trait RootHailModule extends CrossScalaModule with HailModule { outer =>
289291
Deps.Asm.core,
290292
Deps.Asm.analysis,
291293
Deps.Asm.util,
294+
Deps.Log4j.scala,
292295
Deps.samtools.excludeOrg("*"),
293296
Deps.jdistlib.excludeOrg("*"),
294297
Deps.freemarker,
@@ -326,7 +329,7 @@ trait RootHailModule extends CrossScalaModule with HailModule { outer =>
326329

327330
override def assemblyRules: Seq[Rule] = super.assemblyRules ++ Seq(
328331
Rule.Exclude("META-INF/INDEX.LIST"),
329-
Rule.ExcludePattern("scala/(?!collection/compat).*"),
332+
Rule.ExcludePattern("^scala/(?!collection/compat).*"),
330333
Rule.AppendPattern("META-INF/services/.*", "\n"),
331334
// Rule.Relocate("scala.collection.compat.**", "is.hail.relocated.@0"),
332335
Rule.Relocate("breeze.**", "is.hail.relocated.@0"),

hail/hail/src/is/hail/annotations/BroadcastValue.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import is.hail.expr.ir.defs.EncodedLiteral
66
import is.hail.io.{BufferSpec, Decoder, TypedCodecSpec}
77
import is.hail.types.physical.{PArray, PStruct, PType}
88
import is.hail.types.virtual.{TBaseStruct, TStruct}
9-
import is.hail.utils.{formatSpace, log, ArrayOfByteArrayOutputStream}
9+
import is.hail.utils.{formatSpace, ArrayOfByteArrayOutputStream}
1010
import is.hail.utils.prettyPrint.ArrayOfByteArrayInputStream
1111

1212
import java.io.InputStream
1313

14+
import org.apache.logging.log4j.scala.Logging
1415
import org.apache.spark.sql.Row
1516

1617
case class SerializableRegionValue(
@@ -36,7 +37,7 @@ object BroadcastRow {
3637
}
3738
}
3839

39-
trait BroadcastRegionValue {
40+
trait BroadcastRegionValue extends Logging {
4041
def ctx: ExecuteContext
4142

4243
def value: RegionValue
@@ -72,7 +73,7 @@ trait BroadcastRegionValue {
7273
if (broadcasted == null) {
7374
val arrays = encodeToByteArrays(theHailClassLoader)
7475
val totalSize = arrays.map(_.length).sum
75-
log.info(
76+
logger.info(
7677
s"BroadcastRegionValue.broadcast: broadcasting ${arrays.length} byte arrays of total size $totalSize (${formatSpace(totalSize.toLong)}"
7778
)
7879
val srv = SerializableRegionValue(arrays, decodedPType, makeDec)

hail/hail/src/is/hail/annotations/Region.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package is.hail.annotations
33
import is.hail.asm4s
44
import is.hail.asm4s.Code
55
import is.hail.types.physical._
6-
import is.hail.utils._
6+
7+
import org.apache.logging.log4j.scala.Logging
78

89
object Region {
910
type Size = Int
@@ -475,7 +476,7 @@ final class Region protected[annotations] (
475476
def totalManagedBytes(): Long = memory.totalManagedBytes()
476477
}
477478

478-
object RegionUtils {
479+
object RegionUtils extends Logging {
479480
def printAddr(off: Long, name: String): String = s"$name: ${"%016x".format(off)}"
480481

481482
def printAddr(off: Code[Long], name: String): Code[String] =
@@ -512,7 +513,7 @@ object RegionUtils {
512513

513514
val nReferenced = region.nReferencedRegions()
514515

515-
info(
516+
logger.info(
516517
s"""
517518
|$header:
518519
| block size: $size

hail/hail/src/is/hail/annotations/RegionPool.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package is.hail.annotations
33
import is.hail.expr.ir.LongArrayBuilder
44
import is.hail.utils._
55

6+
import org.apache.logging.log4j.scala.Logging
7+
68
object RegionPool {
79

810
def apply(strictMemoryCheck: Boolean = false): RegionPool = {
@@ -22,8 +24,8 @@ object RegionPool {
2224
}
2325

2426
final class RegionPool private (strictMemoryCheck: Boolean, threadName: String, threadID: Long)
25-
extends AutoCloseable {
26-
log.info(s"RegionPool: initialized for thread $threadID: $threadName")
27+
extends AutoCloseable with Logging {
28+
logger.info(s"initialized for thread $threadID: $threadName")
2729

2830
protected[annotations] val freeBlocks: Array[LongArrayBuilder] =
2931
Array.fill[LongArrayBuilder](4)(new LongArrayBuilder(8))
@@ -140,7 +142,7 @@ final class RegionPool private (strictMemoryCheck: Boolean, threadName: String,
140142

141143
val freeBlockCounts = freeBlocks.map(_.size)
142144
val usedBlockCounts = blocks.zip(freeBlockCounts).map { case (tot, free) => tot - free }
143-
info(
145+
logger.info(
144146
s"""Region count for $context
145147
| regions: $nRegions active, $nFree free
146148
| blocks: $nBlocks
@@ -152,15 +154,15 @@ final class RegionPool private (strictMemoryCheck: Boolean, threadName: String,
152154
def report(context: String): Unit = {
153155
val inBlocks = bytesInBlocks()
154156

155-
log.info(
157+
logger.info(
156158
s"RegionPool: $context: ${readableBytes(totalAllocatedBytes)} allocated (${readableBytes(inBlocks)} blocks / " +
157159
s"${readableBytes(totalAllocatedBytes - inBlocks)} chunks), regions.size = ${regions.size}, " +
158160
s"$numJavaObjects current java objects, thread $threadID: $threadName"
159161
)
160-
// log.info("-----------STACK_TRACES---------")
162+
// logger.info("-----------STACK_TRACES---------")
161163
// val stacks: String = regions.result().toIndexedSeq.flatMap(r => r.stackTrace.map((r.getTotalChunkMemory(), _))).foldLeft("")((a: String, b) => a + "\n" + b.toString())
162-
// log.info(stacks)
163-
// log.info("---------------END--------------")
164+
// logger.info(stacks)
165+
// logger.info("---------------END--------------")
164166
}
165167

166168
def scopedRegion[T](f: Region => T): T = using(Region(pool = this))(f)
@@ -202,7 +204,7 @@ final class RegionPool private (strictMemoryCheck: Boolean, threadName: String,
202204
if (strictMemoryCheck)
203205
fatal(msg)
204206
else
205-
warn(msg)
207+
logger.warn(msg)
206208
}
207209
}
208210
}

hail/hail/src/is/hail/asm4s/ClassBuilder.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import java.io._
1010
import java.nio.charset.StandardCharsets
1111

1212
import javassist.bytecode.DuplicateMemberException
13+
import org.apache.logging.log4j.scala.Logging
1314
import org.apache.spark.TaskContext
1415
import org.objectweb.asm.ClassReader
1516
import org.objectweb.asm.util.{Textifier, TraceClassVisitor}
@@ -66,7 +67,7 @@ case class StaticField[T] private (lf: lir.StaticField) extends AnyVal {
6667
}
6768
}
6869

69-
class ClassesBytes(classesBytes: Array[(String, Array[Byte])]) extends Serializable {
70+
class ClassesBytes(classesBytes: Array[(String, Array[Byte])]) extends Serializable with Logging {
7071
@transient @volatile var loaded: Boolean = false
7172

7273
def load(hcl: HailClassLoader): Unit = {
@@ -81,7 +82,7 @@ class ClassesBytes(classesBytes: Array[(String, Array[Byte])]) extends Serializa
8182
val buffer = new ByteArrayOutputStream()
8283
FunctionBuilder.bytesToBytecodeString(bytes, buffer)
8384
val classJVMByteCodeAsEscapedStr = buffer.toString(StandardCharsets.UTF_8.name())
84-
log.error(s"Failed to load bytecode $e:\n" + classJVMByteCodeAsEscapedStr)
85+
logger.error(s"Failed to load bytecode $e:\n" + classJVMByteCodeAsEscapedStr)
8586
throw e
8687
}
8788
}

hail/hail/src/is/hail/backend/BackendUtils.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import is.hail.expr.ir.lowering.TableStageDependency
77
import is.hail.io.fs._
88
import is.hail.utils._
99

10+
import org.apache.logging.log4j.scala.Logging
11+
1012
object BackendUtils {
1113
type F = AsmFunction3[Region, Array[Byte], Array[Byte], Array[Byte]]
1214
}
1315

1416
class BackendUtils(
1517
mods: Array[(String, (HailClassLoader, FS, HailTaskContext, Region) => BackendUtils.F)]
16-
) {
18+
) extends Logging {
1719

1820
import BackendUtils.F
1921

@@ -46,7 +48,7 @@ class BackendUtils(
4648
): Array[Array[Byte]] = {
4749

4850
val cachedResults = ctx.executionCache.lookup(semhash)
49-
log.info(s"$stageName: found ${cachedResults.length} entries for $semhash.")
51+
logger.info(s"$stageName: found ${cachedResults.length} entries for $semhash.")
5052

5153
val todo =
5254
contexts
@@ -65,7 +67,7 @@ class BackendUtils(
6567
val results = merge[(Array[Byte], Int)](cachedResults, successes, _._2 < _._2)
6668

6769
ctx.executionCache.put(semhash, results)
68-
log.info(s"$stageName: cached ${results.length} entries for $semhash.")
70+
logger.info(s"$stageName: cached ${results.length} entries for $semhash.")
6971

7072
failureOpt.foreach(throw _)
7173
Array.tabulate[Array[Byte]](results.length)(results(_)._1)
@@ -98,7 +100,7 @@ class BackendUtils(
98100

99101
val elapsed = System.nanoTime() - start
100102
val nTasks = partitions.map(_.length).getOrElse(contexts.length)
101-
log.info(s"$stageName: executed $nTasks tasks in ${formatTime(elapsed)}")
103+
logger.info(s"$stageName: executed $nTasks tasks in ${formatTime(elapsed)}")
102104

103105
r
104106
}

hail/hail/src/is/hail/backend/ExecutionCache.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package is.hail.backend
33
import is.hail.HailFeatureFlags
44
import is.hail.expr.ir.analyses.SemanticHash
55
import is.hail.io.fs.FS
6-
import is.hail.utils.{using, Logging}
6+
import is.hail.utils.using
77

88
import scala.io.Source
99
import scala.util.control.NonFatal
@@ -12,6 +12,8 @@ import java.io.{FileNotFoundException, OutputStream}
1212
import java.util.Base64
1313
import java.util.concurrent.ConcurrentHashMap
1414

15+
import org.apache.logging.log4j.scala.Logging
16+
1517
trait ExecutionCache extends Serializable {
1618
def lookup(s: SemanticHash.Type): IndexedSeq[(Array[Byte], Int)]
1719
def put(s: SemanticHash.Type, r: IndexedSeq[(Array[Byte], Int)]): Unit
@@ -75,7 +77,7 @@ private case class FSExecutionCache(fs: FS, cacheDir: String) extends ExecutionC
7577
IndexedSeq.empty
7678

7779
case NonFatal(t) =>
78-
log.warn(s"Failed to read cache entry for $s", t)
80+
logger.warn(s"Failed to read cache entry for $s", t)
7981
IndexedSeq.empty
8082
}
8183

hail/hail/src/is/hail/backend/HailTaskContext.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import is.hail.utils._
55

66
import java.io.Closeable
77

8+
import org.apache.logging.log4j.scala.Logging
9+
810
class TaskFinalizer {
911
val closeables = new BoxedArrayBuilder[Closeable]()
1012

@@ -18,7 +20,7 @@ class TaskFinalizer {
1820
(0 until closeables.size).foreach(i => closeables(i).close())
1921
}
2022

21-
abstract class HailTaskContext extends AutoCloseable {
23+
abstract class HailTaskContext extends AutoCloseable with Logging {
2224
def stageId(): Int
2325

2426
def partitionId(): Int
@@ -44,7 +46,7 @@ abstract class HailTaskContext extends AutoCloseable {
4446
}
4547

4648
def close(): Unit = {
47-
log.info(
49+
logger.info(
4850
s"TaskReport: stage=${stageId()}, partition=${partitionId()}, attempt=${attemptNumber()}, " +
4951
s"peakBytes=${thePool.getHighestTotalUsage}, peakBytesReadable=${formatSpace(thePool.getHighestTotalUsage)}, " +
5052
s"chunks requested=${thePool.getUsage._1}, cache hits=${thePool.getUsage._2}"

hail/hail/src/is/hail/backend/driver/BatchQueryDriver.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.io.OutputStream
2121
import java.nio.charset.StandardCharsets
2222
import java.nio.file.Path
2323

24+
import org.apache.logging.log4j.scala.Logging
2425
import org.json4s.JsonAST.JValue
2526
import org.json4s.jackson.JsonMethods
2627

@@ -71,13 +72,13 @@ object BatchQueryDriver extends HttpLikeRpc with Logging {
7172
val (shortMessage, expandedMessage, errorId) =
7273
t match {
7374
case t: HailWorkerException =>
74-
log.error(
75+
logger.error(
7576
"A worker failed. The exception was written for Python but we will also throw an exception to fail this driver job.",
7677
t,
7778
)
7879
(t.shortMessage, t.expandedMessage, t.errorId)
7980
case _ =>
80-
log.error(
81+
logger.error(
8182
"An exception occurred in the driver. The exception was written for Python but we will re-throw to fail this driver job.",
8283
t,
8384
)
@@ -134,7 +135,7 @@ object BatchQueryDriver extends HttpLikeRpc with Logging {
134135
val inputURL = argv(5)
135136
val outputURL = argv(6)
136137

137-
log.info(f"${getClass.getName} $HAIL_PRETTY_VERSION")
138+
logger.info(f"${getClass.getName} $HAIL_PRETTY_VERSION")
138139

139140
sys.env.get("HAIL_SSL_CONFIG_DIR").foreach(tls.setSSLConfigFromDir)
140141

hail/hail/src/is/hail/backend/driver/Py4JQueryDriver.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ import java.util
3131
import com.google.api.client.http.HttpStatusCodes
3232
import com.sun.net.httpserver.{HttpExchange, HttpServer}
3333
import org.apache.hadoop.conf.Configuration
34+
import org.apache.logging.log4j.scala.Logging
3435
import org.apache.spark.sql.DataFrame
3536
import org.json4s._
3637
import org.json4s.jackson.{JsonMethods, Serialization}
3738
import sourcecode.Enclosing
3839

39-
final class Py4JQueryDriver(backend: Backend) extends Closeable {
40+
final class Py4JQueryDriver(backend: Backend) extends Closeable with Logging {
4041

4142
private[this] val flags: HailFeatureFlags = HailFeatureFlags.fromEnv()
4243
private[this] val hcl = new HailClassLoader(getClass.getClassLoader)
@@ -77,7 +78,7 @@ final class Py4JQueryDriver(backend: Backend) extends Closeable {
7778
localTmpdir = tmp
7879
backend match {
7980
case s: SparkBackend if tmp != "file://" + s.sc.getConf.get("spark.local.dir", "") =>
80-
log.warn(
81+
logger.warn(
8182
"Cannot modify Spark's local directory at runtime. " +
8283
"Please stop and re-initialize hail with 'spark.local.dir' " +
8384
"in your Spark configuration."
@@ -234,7 +235,7 @@ final class Py4JQueryDriver(backend: Backend) extends Closeable {
234235
def pyReadMultipleMatrixTables(jsonQuery: String): util.List[MatrixIR] =
235236
withExecuteContext(selfContainedExecution = false) { ctx =>
236237
implicit val fmts: Formats = DefaultFormats
237-
log.info("pyReadMultipleMatrixTables: got query")
238+
logger.info("pyReadMultipleMatrixTables: got query")
238239

239240
val kvs = JsonMethods.parse(jsonQuery).extract[Map[String, JValue]]
240241
val paths = kvs("paths").extract[IndexedSeq[String]]
@@ -246,12 +247,12 @@ final class Py4JQueryDriver(backend: Backend) extends Closeable {
246247
val opts = NativeReaderOptions(intervalObjects, intervalPointType)
247248
val matrixReaders: util.List[MatrixIR] =
248249
paths.map { p =>
249-
log.info(s"creating MatrixRead node for $p")
250+
logger.info(s"creating MatrixRead node for $p")
250251
val mnr = MatrixNativeReader(ctx.fs, p, Some(opts))
251252
MatrixRead(mnr.fullMatrixTypeWithoutUIDs, false, false, mnr): MatrixIR
252253
}.asJava
253254

254-
log.info("pyReadMultipleMatrixTables: returning N matrix tables")
255+
logger.info("pyReadMultipleMatrixTables: returning N matrix tables")
255256
matrixReaders
256257
}._1
257258

@@ -293,10 +294,10 @@ final class Py4JQueryDriver(backend: Backend) extends Closeable {
293294

294295
def pyGrepPrint(regex: String, files: Seq[String], maxLines: Int): Unit =
295296
fileAndLineCounts(regex, files, maxLines).foreach { case (file, lines) =>
296-
info(s"$file: ${lines.length} ${plural(lines.length, "match", "matches")}:")
297+
logger.info(s"$file: ${lines.length} ${plural(lines.length, "match", "matches")}:")
297298
lines.map(_.value).foreach { line =>
298299
val (screen, logged) = line.truncatable().strings
299-
log.info("\t" + logged)
300+
logger.info("\t" + logged)
300301
println(s"\t$screen")
301302
}
302303
}

0 commit comments

Comments
 (0)