Linux 如何清除 JBoss 中的 server.log?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4603394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear server.log in JBoss?
提问by IAdapter
How do I clear JBoss' server.log file when JBoss is running? When I try to do
如何在JBoss 运行时清除 JBoss 的 server.log 文件?当我尝试做
echo 1 > server.log
I get error msg that the file is being usedby another program (JBoss). Is it possible to use a command-line tool (windowsor linux(I do have CygWin)) or an application that I can write myself to clear that file?
我收到错误消息,该文件正被另一个程序 (JBoss) 使用。是否可以使用命令行工具(windows或linux(我有CygWin))或我可以自己编写的应用程序来清除该文件?
P.S. I don't need that file to have 0kb, but I want it to have less than 100MB.
PS 我不需要那个文件有 0kb,但我希望它小于 100MB。
采纳答案by Péter T?r?k
By default JBoss keeps the file locked, since it is writing log messages into it. It is locked as long as JBoss is running and I don't know of other way to release it than stopping JBoss itself.
默认情况下,JBoss 保持文件锁定,因为它正在向其中写入日志消息。只要 JBoss 正在运行,它就会被锁定,除了停止 JBoss 本身,我不知道还有其他方法可以释放它。
To keep its size under control, you can modify your log configuration, which is by default in <server>/conf?jboss-log4j.xml
. You can specify the maximum size of a log file, and define what to do when that size is reached: roll over to a new file, truncate the existing one and start writing over it again, etc.
为了控制其大小,您可以修改您的日志配置,默认情况下在<server>/conf?jboss-log4j.xml
. 您可以指定日志文件的最大大小,并定义达到该大小时要执行的操作:滚动到新文件、截断现有文件并重新开始写入等。
A basic example (not tested, so no guarantee that it works straight as it is):
一个基本示例(未经测试,因此不能保证它可以直接正常工作):
<appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender">
...
<param name="maxFileSize" value="100MB" />
...
</appender>
Moreover, with the maxBackupIndex
parameter you may define the number of backup files (default is 1).
此外,maxBackupIndex
您可以使用该参数定义备份文件的数量(默认为 1)。
回答by hennr
JBoss locks the file as long as the logging process is running.
只要日志记录进程正在运行,JBoss 就会锁定文件。
If you enabled the JMX console you can stop the logging, delete / modify the log, and start the logging service again.
如果您启用了 JMX 控制台,您可以停止日志记录、删除/修改日志并重新启动日志记录服务。
The url should look something like this (for log4j):
网址应如下所示(对于 log4j):
I tested this with JBoss 5.
我用 JBoss 5 对此进行了测试。
This solution should be scriptable as well.
这个解决方案也应该是可编写脚本的。
Regarding your log file size problem: You should use a configuration approach instead of editing the log file manually.
关于您的日志文件大小问题:您应该使用配置方法而不是手动编辑日志文件。