Logger is not working inside spark UDF on cluster

陌路散爱 提交于 2021-02-10 15:54:51

问题


I have placed log.info statements inside my UDF but it is getting failed on cluster. Local working fine. Here is the snippet:

def relType = udf((colValue: String, relTypeV: String) => {
var relValue = "NA"
val relType = relTypeV.split(",").toList
val relTypeMap = relType.map { col =>
  val split = col.split(":")
  (split(0), split(1))

}.toMap

//    val keySet = relTypeMap
relTypeMap.foreach { x =>
  if ((x._1 != null || colValue != null || x._1.trim() != "" || colValue.trim() != "") && colValue.equalsIgnoreCase(x._1)) {
    relValue = relTypeMap.getOrElse(x._1, "NA")
    log.info("testing.........")
  }
}
relValue
})

Also, when i am calling any function inside UDF and using log statements, logs are not printed in cluster and it works fine too.


回答1:


log4j.appender.myConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.myConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.myConsoleAppender.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p %c{1}: %m%n


log4j.appender.RollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppender.File=src//main//resources//spark.log
log4j.appender.RollingAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p %c{1}: %m%n

log4j.appender.RollingAppenderU=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppenderU.File=src//main//resources//sparkU.log
log4j.appender.RollingAppenderU.DatePattern='.'yyyy-MM-dd
log4j.appender.RollingAppenderU.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppenderU.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p %c{1}: %m%n


# By default, everything goes to console and file
log4j.rootLogger=INFO, RollingAppender, myConsoleAppender

# My custom logging goes to another file
log4j.logger.myLogger=INFO, RollingAppenderU

# The noisier spark logs go to file only
log4j.logger.spark.storage=INFO, RollingAppender
log4j.additivity.spark.storage=false
log4j.logger.spark.scheduler=INFO, RollingAppender
log4j.additivity.spark.scheduler=false
log4j.logger.spark.CacheTracker=INFO, RollingAppender
log4j.additivity.spark.CacheTracker=false
log4j.logger.spark.CacheTrackerActor=INFO, RollingAppender
log4j.additivity.spark.CacheTrackerActor=false
log4j.logger.spark.MapOutputTrackerActor=INFO, RollingAppender
log4j.additivity.spark.MapOutputTrackerActor=false
log4j.logger.spark.MapOutputTracker=INFO, RollingAppender
log4j.additivty.spark.MapOutputTracker=false


来源:https://stackoverflow.com/questions/52308209/logger-is-not-working-inside-spark-udf-on-cluster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!