I am running a spark program scala where I am stuck with this particular scenerio where my log messages with debug severity are not being printed.
Here is my code snippet
object TestLogging{
@transient lazy val log = LogManager.getLogger(getClass().getName())
def main(args:Array[String]): Unit = {
log.debug("printing debug")
log.info("printing info")
log.warn("printing warn")
log.debug("printing debug 2")
log.error("printing error")
log.fatal("printing fatal")
}
Here is my log4j2.properties file
rootLogger.level = debug
rootLogger.appenderRef.stdout.ref = console
appender.console.type = Console
appender.console.name = console
appender.console.target = SYSTEM_ERR
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n%ex
appender.console.threshold = DEBUG
Here is the ouput from console
24/12/05 15:56:13 INFO TestLogging$: printing info
24/12/05 15:56:13 WARN TestLogging$: printing warn
24/12/05 15:56:13 ERROR TestLogging$: printing error
24/12/05 15:56:13 FATAL TestLogging$: printing fatal
Any idea what I am doing wrong.
PS: log4j-core and log4j-api version 2.22.1 are in the pom.xml and this Object is a part of a spark/scala project. Currently I am not doing any spark related stuff but summitting the code with sparkOperator on a kubernetes cluster
Setting spark.driver.extrajavaoptions
and spark.driver.extrajavaoptions
to -Dlog4j2.configurationFile=<path to my log4j2.properties file> -D-Dlog4j2.debug
worked for me. The steps on the page https://logging.apache.org/log4j/2.x/faq.html#troubleshooting are quite helpful.