0

I'm having an EAR project, consisting from 3 modules/projects: WEB, EJB and JPA. In WEB project, i have added log4j2 for logging. Therefore i've putted log4j2.xml file into WebContent/WEB-INF/ direcotry.

Now, i have made two projects out of one: the developer version and the test version. The differs mainly in project name. They also have different file location configured in log4j2.xml file, to which to write logs.

When i deploy only one project (for instance developer version), everything works fine. However, when im deploying both projects, then, both of them are logging to the same file (it is always the file configured in log4j2 from the project that was deployed first). My Glassfish version is 3.1.2.2 and Log4j2 version is 2.0.2.

Does any one konws how to solve it?

Szarpul
  • 1,531
  • 11
  • 21

1 Answers1

0

The log4j2 manual has details on configuration for web applications.

Are the log4j2 jar files also in the WebProject1/WEB-INF/lib and WebProject2/WEB-INF/lib folders (and not in some shared location)? That way the log4j2 classes will be loaded by separate webapp class loaders and they can have separate configurations.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • Libs are in WebProject1/WEB-INF/lib and WebProject2/WEB-INF/lib. I also have log4j2 libs in glassfish/domains/domain1/lib. When i remove libs from glassfish/domains/domain1/lib directory, the problem is solved. However, if I do not keep log4j2 libs in glassfish/domains/domain1/lib, after a few deployments i get PerGen Error described here : [Dealing with “java.lang.OutOfMemoryError: PermGen space” error](http://stackoverflow.com/questions/88235/dealing-with-java-lang-outofmemoryerror-permgen-space-error) – Szarpul Jan 13 '15 at 08:23
  • Hmm... I believe removing log4j2 libs from the glassfish/domains/domain1/lib directory is the only way to allow separate configurations for separate web apps. Did you try any of the solutions to the PermGen space error that were mentioned in the StackOverflow question you linked to? – Remko Popma Jan 14 '15 at 00:39
  • Yep, i added `-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled` to jvm options, but nothing has changed. The profiler still shows growing PermGen memory size and number of classes. Im working on finding "dead cows" as its written here: [GF memory leak error](http://www.franke.ms/#glassfish-memory-leak.wiki), but its not that easy. Putting log4j2 jars in glassfish domain libs directory was the solution, but know i have to find another one since i have two projects. – Szarpul Jan 15 '15 at 12:16