I've been trying to push my scala console application's logs to Application Insights using Application Insights log4j v1.2 appender. It is working as expected, but at the end, the application is not exiting. Is there any connection that I need to close for the application to exit? Can someone please help me with this issue? I cannot use System.exit(0)
or Thread.interrupt()
because this will cause my Spark application to fail on cluster.
Below is my source code:
AILogger.scala:
import org.apache.log4j.{ Logger, Level, MDC }
import java.time.LocalDateTime
import com.microsoft.applicationinsights.log4j.v1_2.ApplicationInsightsAppender
object AILogger {
var rootLogger = Logger.getRootLogger()
var ai = new ApplicationInsightsAppender()
ai.setInstrumentationKey("Insert IKey here")
ai.activateOptions()
@transient lazy val logger = Logger.getLogger(this.getClass)
logger.setLevel(Level.INFO)
rootLogger.addAppender(ai)
rootLogger.setLevel(Level.ERROR)
def info(message: String): Unit = {
logger.info(message)
}
}
AILoggerTest.scala:
import java.time.LocalDateTime
object AILoggerTest {
def main(args: Array[String]) {
AILogger.info("logging to AI " + LocalDateTime.now())
System.out.println("Completed")
}
}
Thanks
JavaEE/Spring MVC applications autowire ThreadPool shutdowns. In your case you have to trigger it yourself when application is supposed to exit:
SDKShutdownActivity.INSTANCE.stopAll()