java 如何配置 jboss 7 将日志写入不同的文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9910571/
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 configure jboss 7 to write logs to different folder
提问by Tomer
I'm using Jboss 7.1.1 and I have the following log definition:
我正在使用 Jboss 7.1.1 并且我有以下日志定义:
<subsystem xmlns="urn:jboss:domain:logging:1.1">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE">
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<size-rotating-file-handler name="ACEII">
<level name="DEBUG"/>
<formatter>
<pattern-formatter pattern="%z{utc}%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%c] %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="ACEII.log"/>
<rotate-size value="10M"/>
<max-backup-index value="10"/>
<append value="true"/>
</size-rotating-file-handler>
<logger category="ace2" use-parent-handlers="false">
<level name="DEBUG"/>
<handlers>
<handler name="ACEII"/>
</handlers>
</logger>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.apache.tomcat.util.modeler">
<level name="WARN"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<logger category="jacorb">
<level name="WARN"/>
</logger>
<logger category="jacorb.config">
<level name="ERROR"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
I'd like the ACE log to be written to a different folder, so I tried putting different values in the relative-to attribute but nothing seems to work, any idea on how to do it?
我希望将 ACE 日志写入不同的文件夹,因此我尝试在相对于属性中放置不同的值,但似乎没有任何效果,您知道该怎么做吗?
采纳答案by Tomer
Found the answer :)
找到答案:)
I'm using Java service wrapper to install Jboss as a windows service and that service has a configuration file located in a certain path, so I've noticed that if i remove the relative-to attribute it write the logs to the folder where the configuration file is located.
我正在使用 Java 服务包装器将 Jboss 安装为 Windows 服务,并且该服务的配置文件位于某个路径中,所以我注意到,如果我删除了相对于属性,它将日志写入文件夹中配置文件位于。
All i had to do define it like this:
我所要做的就是这样定义它:
<size-rotating-file-handler name="ACEII">
<level name="DEBUG"/>
<formatter>
<pattern-formatter pattern="%z{utc}%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%c] %s%E%n"/>
</formatter>
**<file path="../Log/ACEII.log"/>**
<rotate-size value="10M"/>
<max-backup-index value="10"/>
<append value="true"/>
</size-rotating-file-handler>
And that did the trick for me.
这对我有用。
回答by James R. Perkins
You need to leave off the relative-to
and enter the absolute path in the path
attribute.
您需要离开relative-to
并在path
属性中输入绝对路径。
<size-rotating-file-handler name="ACEII">
<level name="DEBUG"/>
<formatter>
<pattern-formatter pattern="%z{utc}%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%c] %s%E%n"/>
</formatter>
<file path="/var/log/myLogDir/ACEII.log"/>
<rotate-size value="10M"/>
<max-backup-index value="10"/>
<append value="true"/>
</size-rotating-file-handler>
You can also use your own relative path by adding a path to your configuration.
您还可以通过向配置添加路径来使用自己的相对路径。
In CLI you would just execute: /path=my.log.dir:add(path="/var/log")
在 CLI 中,您只需执行: /path=my.log.dir:add(path="/var/log")
If you just want to edit the xml add the following.
如果您只想编辑 xml,请添加以下内容。
<paths>
<path name="my.log.dir" path="/var/log"/>
</paths>
Paths themselves can have a relative path if you wanted to define specif directories in a default log directory for example.
例如,如果您想在默认日志目录中定义特定目录,则路径本身可以具有相对路径。
Once you have your path defined you can use the name you gave the path in the relative-to
attribute.
一旦定义了路径,就可以使用在relative-to
属性中为路径指定的名称。
回答by Pavel Gutsa
This works just fine for me.
这对我来说很好用。
domain.sh -Djboss.server.log.dir="my custom logs dir"
回答by Dale C
Know this is an older question, but still found it relevant for JBOSS EAP 7
知道这是一个较旧的问题,但仍然发现它与 JBOSS EAP 7 相关
I found James response from here insightful - https://developer.jboss.org/wiki/Wildfly82LogPathChange
我发现 James 的回复很有见地 - https://developer.jboss.org/wiki/Wildfly82LogPathChange
I was able to edit the standalone.conf and specify the custom logging directory there.
我能够编辑 standalone.conf 并在那里指定自定义日志目录。
The is also a domain.conf that can be edited for domain mode.
这也是一个可以为域模式编辑的 domain.conf。
All that is needed it to add the following to the end of the file:
只需将以下内容添加到文件末尾即可:
#Specify the log dir
JAVA_OPTS="$JAVA_OPTS -Djboss.server.log.dir=my custom logs dir"
As I understand it for Windows the .bat files can be updated instead of the .conf files.
据我了解,Windows 可以更新 .bat 文件而不是 .conf 文件。
回答by Dale C
This is what I use; I then handle log rotation with logrotate
:
这就是我使用的;然后我处理日志轮换logrotate
:
<file-handler name="FILE" autoflush="true">
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<append value="true"/>
</file-handler>
Obviously, you can modify this to suit your needs.
显然,您可以修改它以满足您的需要。