如何清除JBoss中的server.log?
当JBoss 正在运行时,如何清除JBoss 的server.log 文件?当我尝试这样做时,
echo 1 > server.log
我收到错误消息,表明另一个程序(JBoss)正在使用该文件。是否可以使用命令行工具(windows 或 linux(我有 CygWin))或我可以自己编写的应用程序清除该文件?
PS 我不需要该文件有 0kb,但我希望它小于 100MB。
How do I clear JBoss' server.log file when JBoss is running? When I try to do
echo 1 > server.log
I get error msg that the file is being used by another program (JBoss). Is it possible to use a command-line tool (windows or linux(I do have CygWin)) or an application that I can write myself to clear that file?
P.S. I don't need that file to have 0kb, but I want it to have less than 100MB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,JBoss 保持文件锁定,因为它正在向其中写入日志消息。只要 JBoss 正在运行,它就会被锁定,除了停止 JBoss 本身之外,我不知道还有其他方法可以释放它。
为了控制其大小,您可以修改日志配置,默认情况下位于
/conf˛jboss-log4j.xml
中。您可以指定日志文件的最大大小,并定义达到该大小时要执行的操作:滚动到新文件、截断现有文件并重新开始写入等。一个基本示例(未经测试,因此不保证它能正常工作):
此外,使用 maxBackupIndex 参数,您可以定义备份文件的数量(默认为 1)。
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.
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.A basic example (not tested, so no guarantee that it works straight as it is):
Moreover, with the
maxBackupIndex
parameter you may define the number of backup files (default is 1).只要日志记录进程正在运行,JBoss 就会锁定该文件。
如果启用了 JMX 控制台,您可以停止日志记录、删除/修改日志,然后再次启动日志记录服务。
url 应如下所示(对于 log4j):
http://jboss.example.com:8080/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.system%3Atype%3DLog4jService%2Cservice%3DLogging
我测试过这与 JBoss 5 一起使用。
该解决方案也应该是可编写脚本的。
关于您的日志文件大小问题:您应该使用配置方法而不是手动编辑日志文件。
JBoss locks the file as long as the logging process is running.
If you enabled the JMX console you can stop the logging, delete / modify the log, and start the logging service again.
The url should look something like this (for log4j):
http://jboss.example.com:8080/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.system%3Atype%3DLog4jService%2Cservice%3DLogging
I tested this with 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.
要清除 JBoss 中的日志,您可以按照以下步骤操作:
To clear logs in JBoss, you can follow these steps: