How do I implement log4j in a multi-module Maven project? Do I add a “log4j.properties” file to the src/main/resources directory of every submodule? If so, do I have to specify a different output file for each file appender? Or is there a way to have one overarching log4j.properties file for the whole project, without having a configuration nightmare. Which approach (many log4j.properties files versus one) is more common and better practice? Thanks for all feedback in advance.
Share
It depends on how you intend to deploy and run this project. For hierarchical multi-module projects, we generally included a log4j config file in the module with the
mainmethod that would launch the program.For example, consider a simplified setup with projects
clientandserverwhich both rely onframeworkfor common classes (RMI interfaces, domain objects, etc). Client is run as a desktop application, has its ownmainentry point, and thus gets its own log4j.properties file under src/main/resources. So does the server module. Framework, however, does not get a properties file — its logger calls will be handled by whichever loggers have been configured by its calling module.