• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

WebServlet 3 with log4j2 threaded logging  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Been a lurker for a while, so this is my first time to say 'hi'.

I've come across a really 'stubborn' problem i can't resolve.

I'm building a webservlet 3 app with hibernate on jdk 8 with apache tomee 1.7.4.

The problem i have come across came up i tried to implement logging for a specific functionality.
The functionality requires me to create a log for each user where the write path for the log is determined by the username (obtained from the active user session).
I've reviewed a ton of documentation & implementation for the common logging libs for java.

The common problem for all different implementations, however, is that whenever user1) and user2) have to both log an event at the exact same time,
the messages maintain to be unique for them, but the path is not preserved, so for example the message for /opt/weblog/user1/web.log goes to
/opt/weblog/user2/web.log instead.
Having this said, imagine what happens with 50 users.

I've been trying to solve this in so many different ways, im not sure i can even list them all.

Right now what im doing some something like:

Conf(looks like this for debugging purposes & definitely is not the final version):

By documentation, the async appender shown as an example here: https://logging.apache.org/log4j/2.x/manual/webapp.html
works incredibly slowly & the api has been changed since the docs were last updated, so effectively the shown implementation is not possible in log4j2 2.11.

Can anyone demonstrate an implementation with any logging lib, where this issue does not happen, or just maybe explain whats wrong with this one?
Posts: 1845
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know if you are still encountering this problem, but have you looked at using LogBack?
They seem to have a solution for this: https://logback.qos.ch/manual/appenders.html#SiftingAppender covers this exact use case.

Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Become a Java guru with IntelliJ IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!