不同的应用程序写入相同的log4j日志文件 [英] Different applications writing to same log4j log file

查看:211
本文介绍了不同的应用程序写入相同的log4j日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个java / Java EE应用程序 -
两个是在WebSphere中运行的基于服务器的j2ee应用程序。
其他两个是独立的Java应用程序。
我的日志框架是使用log4j.properties的log4j。

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.

问题1:我是否可以使用相同的日志文件来记录所有应用程序。即使所有应用程序同时写入,它是否会导致文件写入问题?

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?

问题2:如果所有应用程序都可以写没有任何问题,我该怎么办?将应用程序名称预先附加到每个日志语句?

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:

我相信默认情况下它不起作用。

I believe by default it will NOT work.

如果您使用的是SLF4J,请考虑切换到LogBack。在LogBack的File Appender中,有一种谨慎模式,允许不同JVM中的多个FileAppender写入相同的日志文件(当然,所有这些都需要打开谨慎模式)

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

问题2:
您不应该通过手动记录您的应用名称来使日志消息不同。

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

有很多方法可以做。最简单的方法是:由于您有两个不同的应用程序,因此可以为它们提供不同的日志配置文件。只需在appender使用的日志模式中添加相应的应用程序名称信息即可满足您的需求。

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.

这篇关于不同的应用程序写入相同的log4j日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆