Replies: 4 comments 1 reply
-
Hi @cagliotto, No, you are not missing anything. The main problem with having a single deployment of The only way to force Note that the behavior of
In order to do that, you need to change context selector. I have written a small set of utilities for Log4j and Tomcat in copernik-eu/log4j-plugins. In the still unreleased 3.0.0 version there is an alternative context selector that might fill your needs. Using Copernik.eu Log4j extensionsThe new <dependency>
<groupId>eu.copernik</groupId>
<artifactId>log4j-tomcat-juli-core</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency> Currently you can download it from the OSSRH snapshot repository. To use the selector:
The selector will select the logger context based on the thread context classloader and will create:
If you choose to use a single configuration file for all contexts, you can profit from the <Configuration>
<Appenders>
<File name="FILE"
fileName="/var/log/tomcat/${tomcat:context.name}"/>
</Appenders>
<Loggers>
<!-- Shorthand for org.apache.catalina.core.ContainerBase.[enginename].[hostname].[appname] -->
<Logger name="${tomcat:context.logger}" level="DEBUG"/>
<Root level="INFO">
<AppenderRef ref="FILE"/>
</Root>
</Loggers>
</Configuration> |
Beta Was this translation helpful? Give feedback.
-
Hi @ppkarwasz , |
Beta Was this translation helpful? Give feedback.
-
I'll be doing a beta release of my extensions one of these weekends. Would you be available to test them? They have an extensive unit test coverage, but I am no longer using Tomcat in my dayjob, so I haven't tested a lot of deployments. |
Beta Was this translation helpful? Give feedback.
-
@ppkarwasz I'll see in the next weeks because this morning we had to close the monthly release so I didn't have time to try or apply what you suggested. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have multiple java web applications running under tomcat (9.0.85 is the exact version).
The logj4 libraries are inside tomcat/lib, not inside each project.
The log4j2.xml files are configured to separate logs between apps so to have dedicated folders.
Log4j2.xml is stored in the root classpath.
Originally, when I had the log4j libs in each project, everything was working smoothly.
By company policies we had to share common libraries so I had to place log4j libs inside tomcat/libs, as stated before.
After that, logs weren't separated correctly since I had all log events written inside the same file.
The first deployed app was the one storing all the logs:
APP1 is configured to store logs inside logs/APP1/app1.log
APP2 is configured to store logs inside logs/APP2/app2.log
APP3 is configured to store logs inside logs/APP3/app3.log
Since APP1 was the first one being deployed, only logs/APP1/app1.log was created and logs of other apps were written there too.
To overcome this problem I added this lines inside every web.xml:
Now the log events occurring inside each classpath are correctly separated but the logs related to external packages (example org.springrframework, org.primefaces, org.ibatis ecc. ecc.) are still only registered in the app1.log, mixing everything together.
I've also noticed something stranger; if I configure only one app to show me external packages logs, I see events of other apps too; I mean, if log4j2.xml of APP1 is configured to show me org.springframeworks events but APP2 and APP3 aren't, I still see events of APP2 and APP3.
Am I missing something? Is there a solution/workaround to have all logs separated correctly?
For the reason explained before, the solution shouldn't be to move back log4j libraries inside each app.
Configuration:
Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions