Different applications writing to same log4j log file

流过昼夜 提交于 2020-01-03 19:05:10

问题


I have 4 java/Java EE applications- Two are server based j2ee applications running in WebSphere. Other two are standalone java applications. My logging framework is log4j using log4j.properties.

Question 1: Can I have a same log file for logging from all the applications. Will it cause any file writing issues even if all the applications are writing at the same time?

Question 2: If all the applications can write without any issues, how can I pre-append the application name to each of the log statement?


回答1:


Question 1:

I believe by default it will NOT work.

If you are using SLF4J, consider switching to LogBack. In LogBack's File Appender, there is a prudent mode that allow multiple FileAppenders in different JVMs to write to same log file (of course, all of them need to have prudent mode turned on)

http://logback.qos.ch/manual/appenders.html#prudent

Question 2: You should NEVER make the log message different by manually logging your app name.

There are quite some way to do. The easiest way is: As you are having two different applications, you can have different logging config files for them. Just add corresponding app name information in the log pattern used by the appender will serve what you want.



来源:https://stackoverflow.com/questions/14352520/different-applications-writing-to-same-log4j-log-file

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