log4j 控制台附加程序和日志文件大小

发布于 2024-08-17 22:15:34 字数 743 浏览 4 评论 0原文

我在 Solaris 中使用 Jboss 4.0.2 来运行 web 应用程序。

JBoss 配置为使用出厂默认的 log4j.xml 文件,并且该文件有一个 ConsoleAppender。我正在将 jboss java 进程的标准输出重定向到一个文件。

当我尝试清理这个文件 - jboss.out 时,发生了一些有趣的事情。

这就是我开始的地方。

$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity     458M Jan  8 07:22 jboss.out

然后我清理这个文件。 Jboss仍在运行。

$ >jboss.out
$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity        0 Jan  8 07:24 jboss.out

现在,如果点击我的网络应用程序中的链接,它就会开始记录,但整个文件会再次出现!

$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity     458M Jan  8 07:25 jboss.out

对发生的事情有什么想法吗?

ConsoleAppender 是否正在缓冲数据?我没有足够的内存来容纳 458MB,而且我的磁盘交换区几乎未使用。我也没有看到这么大的临时文件。

I am using Jboss 4.0.2 in Solaris to run a webapp.

JBoss is configured to use the factory default log4j.xml file, and this has a ConsoleAppender. I am redirecting stdout of jboss java process to a file.

Something interesting happens when I try to cleanup this file - jboss.out.

This is where I start.

$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity     458M Jan  8 07:22 jboss.out

Then I clean up this file. Jboss is still running.

$ >jboss.out
$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity        0 Jan  8 07:24 jboss.out

Now if go click on a link in my webapp, it starts logging, but the whole file kind of reappears again!

$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity     458M Jan  8 07:25 jboss.out

Any ideas on whats going on?

Is ConsoleAppender buffering the data? I dont have enough memory to hold 458MB and my disk swap is almost unused. I dont see any temp file this huge either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不会写诗 2024-08-24 22:15:34

这可能是一个稀疏文件,由操作系统在 JBoss 发出写入并将文件指针设置为 +[无论文件的旧大小是什么] 时创建。

检查新文件实际使用的磁盘空间 - 在大多数 unice 上,du -k jboss.out 应该可以工作。如果文件稀疏,您应该会看到明显小于 ls 显示的大小的文件。

一般来说,在写入日志文件时删除它们是很棘手的。为了在捕获标准输出时避免这个问题,我倾向于将标准输出通过管道传输到 cronolog旋转日志而不是直接写入文件。

This is probably a sparse file, created by the OS when JBoss issues a write with the file pointer set to +[whatever the old size of the file was].

Check the disk space actually used by the new file -- on most unices, du -k jboss.out should work. If the file is sparse, you should see something significantly less than the size shown by ls.

Generally, removing log files while they're being written to is tricky. To avoid that issue when capturing stdout, I tend to pipe stdout to a program like cronolog or rotatelogs instead of straight to a file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文