Log4j记录到一个共享的日志文件中[英] Log4j Logging to a Shared Log File

本文是小编为大家收集整理的关于Log4j记录到一个共享的日志文件中的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

是否可以将Log4J记录事件写入日志文件,该日志文件也正在由其他应用程序编写.其他应用程序可以是非Java应用程序.有什么缺点?锁定问题?格式?

推荐答案

log4j有一个套接字应用程序,它将将事件发送到服务,您可以实现自己或使用与log4j捆绑的简单实现.

它还支持syslogd和Windows事件日志,这对于尝试将日志输出与非Java应用程序的事件统一可能很有用.

如果性能是一个问题,您希望单个服务编写日志文件,而不是试图协调各种日志记录应用程序之间的一致锁定策略.

其他推荐答案

您最好的选择可能是单独让每个应用程序日志,然后根据时间将计划的作业放在适当的位置,以将文件"拉链"在一起.如果您需要真正最新访问完整日志,则可以每小时进行此操作.

其他推荐答案

我有以下两种方法的经验:

  1. 使用数据库来记录而不是纯文本文件 - 由于性能问题,它可能会过时,另一方面,很容易分析日志,创建报告.数据库要注意所有并发问题.
  2. 另一种方法涉及使用JBOSS服务器,可用于读取其他来源的记录信息. JBoss可以以最小的配置运行,并且由于它确实很轻(2秒的启动时间).详细信息可以在此处找到 -Guide/en/html/logging.html (登录到单独的服务器). log4j照顾所有锁定/并发问题.

如果您不打算使用JBOSS,则可以将第二种方法用作您自己的日志记录解决方案的基础.

本文地址:https://www.itbaoku.cn/post/1574780.html

问题描述

Is there a way to write log4j logging events to a log file that is also being written to by other applications. The other applications could be non-java applications. What are the drawbacks? Locking issues? Formatting?

推荐答案

Log4j has a SocketAppender, which will send events to a service, which you can implement yourself or use the simple implementation bundled with Log4j.

It also supports syslogd and the Windows event log, which may be useful in trying to unify your log output with events from non-Java applications.

If performance is an issue at all, you want a single service writing the log file, rather than trying to coordinate a consistent locking strategy among diverse logging applications.

其他推荐答案

Your best bet might be to let each application log separately, then put a scheduled job in place to 'zipper' the files together based on time. If you need really up-to-date access to the full log, you could have this run every hour.

其他推荐答案

I have a experience with the following two approaches:

  1. Use database for logging instead of plain text file - it can be prohibitive because of performance issues, on the other hand it is very easy to analyze logs, create reports. Database takes care for all concurrency problems.
  2. The other approach involves usage of JBoss server, which can be used to read logging information from other sources. JBoss can be run in the minimal configuration and thanks to that it is really lightweight (2 seconds startup time). Details can be found here http://docs.jboss.org/process-guide/en/html/logging.html (Logging to a Seperate Server). Log4J takes care of all locking/concurrency issues.

If you are not planning to use JBoss you can use the second approach as a base of your own logging solution.