Single log file for multiple webapps

感情迁移 提交于 2019-12-25 02:52:40

问题


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:

  1. I have three webapps A, B, C having logs files as A.log, B.log and C.log.
  2. I made two calls. 1st one to A (that internally calls C) and 2nd to B (that internally calls C).
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!