Reputation: 331
I am working on a java services which handles multiple requests at a time. I'm using log4j without any extra configuration. So basically all the logs are going to the same file so it is very difficult to debug any issue regarding a particular request.
I still want all the logs in the same file(i'll use DailyRollingFileAppender to make my life easier) but I want the logs in a way that all the logs from a thread should be appended at once. With that arrangement I can find the logs for a request at one place.
So what should be done in order to achieve this.
Thanks
Upvotes: 1
Views: 212
Reputation: 748
Log4J allows the message that get output to the log file to have certain pattern and it is normally provided as part of the log4j.xml (or .properties) file.
Using message pattern we can have the thread name to be output to the log file. This is done by adding %t in the message pattern.
But I am not sure if Log4J would be designed to dump all the logs for a thread at one place. This is because in web applications, the threads run by the server last for a long time. So the same server thread that handled User-1's request might be serving User-2's request. So, if you assumed that a thread would be generated for each request, I am afraid it is not the case.
But you can have different appenders and loggers in log4j.xml for different application modules so that you would find logs for certain important modules at one place.
Upvotes: 1