问题
In my tomcat there are multiple webapps deployed and they communicate with each other. Currently they all have their own log file. But when there is some issue comes from call I have to 1st check with the app to whom I made a call and check log file of respective apps involved in the call. So I want that, as all apps is deployed in same tomcat and sharing a common log4j, if a call made to any app then all logs should be in a single log file and no matters how my webapps are involved all error comes from any webapp during the call should be in a single log file.
I have no idea how can I achieve this. So any help is appreciable.
Edited:
I think my question is not cleared so updated with use case:
- I have three webapps A, B, C having logs files as A.log, B.log and C.log.
- I made two calls. 1st one to A (that internally calls C) and 2nd to B (that internally calls C).
- Now logging of first call must be in A.log (with the logs of every step performed inside the webapp c) and second call must be in B.log (with the logs of every step performed inside the webapp c).
回答1:
I'd rather recommend that you leave your log files as they are and use a separate log collector service. Then you can just search using that service what you want to know. As an additional bonus, you get filters and other nifty features.
LogStash is one I've heard good things about. Haven't had the time to take it into use yet, though, but I think that's the direction one should go to. There's a presentation about it on the front page and getting started material here.
Disclaimer: I'm no way affiliated with them, I just think that's the direction log analysis should go to.
回答2:
Log4j's FileAppender does not allow write from multiple applications to the same file. If you try, you'll get a corrupt log file. However, logback can do that take a look at http://logback.qos.ch/manual/appenders.html#prudent
回答3:
It would be easier if you use java.util.Logging
instead of log4j.
The deployed web apps, using java logging, uses the app server logging.properties by default. So all the web apps will refer the same logging.properties file and will log in the same place.
Normally, this is considered as a hindrance of java logging framework, but your usecase suits just fine.
You will find plenty of examples in the net for java.util.logging.
来源:https://stackoverflow.com/questions/23882995/single-log-file-for-multiple-webapps