0

I have a scala spark application where I am trying to log the start of specific events to a file. Application looks like this:

package com.myApp

import org.apache.logging.log4j.scala.{Logger, Logging}

object someSpark extends Logging {

  def main(args:Array[String] {
    logger.info("The application has started")
    //Do some Spark stuff here//
    logger.info("The application has ended")
  }
}

I have an appender set up in my log4j properties file like this:

log4j.appender.appAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.appAppender.File=./logs/appLog.log
log4j.appender.appAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.appAppender.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

and also have this line:

log4j.logger.com.myApp=ALL, appAppender

As I understand it, this should run any log messages written when executing code in com.myApp to the file ./logs/appLog.log, however, nothing actually gets written there, just an empty file. The messages do show up in the mysterious file in that same location called app.log. I have no idea what is causing that file to be generated nor how I can control what the output looks like. Any insight into what I am doing wrong is appreciated. Also, let me know what other info I can provide.

Thanks.

J Calbreath
  • 2,665
  • 4
  • 22
  • 31
  • I suggest you use log4j.xml instead of log4j.properties, since it allows you greater control over configuration http://stackoverflow.com/questions/14497787/log4j-properties-vs-log4j-xml – radumanolescu Mar 01 '17 at 19:10
  • I suggest you use SLF4J and not Log4J directly, since it allows you to interface to various logging back-ends https://www.slf4j.org/manual.html – radumanolescu Mar 01 '17 at 19:15

0 Answers0