3
votes

I am dumping log files (log4j) under /logs/MyApp directory on my linux server and its working fine. Application (EAR) is built using Jenkins and I am writing junit test cases for that. The problem is log4j file appender's location won't be pointing to jenkins server filesystem and is relative to my linux server.

Log4j.appender.App.File = /logs/MyApp/AppLogs.log

This is resulting in errors when test cases are executed from jenkins as log4j file location is not present.

log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: /logs/MyApp/Applogs.log (No such file or directory)

How can i configure log4j to work with jenkins without changing current configurations that are already setup for my production environment.

1

1 Answers

2
votes

There are a few ways of fixing this:

  1. Create the directory in your Jenkins master/slaves. Not sustainable if there is a new slave.
  2. Change the log4j config so that you have different log4j configurations - one for your production, one for local testing and one for Jenkins. (This is what Play framework does and for different profiles you got different log files)
  3. You can pass this is as a parameter for Jenkins job (or set it in env var ) and use it in Jenkins.
  4. Don't use an absolute path in the log4j config if possible.