Different log4j config for jenkins and production server

I dump the log files (log4j) in a directory /logs/MyApp

on my Linux server and it works fine. The app (EAR) is built using Jenkins and I am writing tests for Junit. The problem is that the location of the log4j file will not point to the jenkins server filesystem and relative to my linux server.

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

      

This leads to errors when test cases are run from jenkins as the location of the log4j file is missing.

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

How do I set up log4j to work with jenkins without changing the current configurations that are already set up for my production environment.

+3


source to share


1 answer


There are several ways to fix this:



  • Create directory in master / slave Jenkins. Not stable if there is a new subordinate.
  • 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 works in the Play platform and you got different log files for different profiles)
  • You can pass this as a parameter to Jenkins job (or set it to env var) and use it in Jenkins.
  • Don't use an absolute path in your log4j config, if possible.
+2


source







All Articles