如何使用 Java 中的 Log4j 在 jboss 6.x 中逐步配置日志记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18863630/
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 Step By Step configure logging in jboss 6.x with Log4j in Java
提问by Ashish Jagtap
Hi all I am new to Jboss so I am get confused while setting up an logging in Jboss 6.1 what I does I have download and extract the Jboss (jboss-eap-6.1) on my machine then I follow the steps given in thisarticle but still I not able to see the logging on console or in file
大家好我是新来的Jboss,所以我会感到困惑,而到JBoss 6.1建立一个记录什么,我没有我下载并解压的Jboss(JBoss的-EAP-6.1我的机器上),那么我按照给出的步骤此文章,但我仍然无法在控制台或文件中看到日志记录
the I google it around and come to know that I have to write jboss-deployment-structure.xmlfile under /META-INF/folder and have to add -Dorg.jboss.as.logging.per-deployment=falseto the start-up of the server (which I dont know where I have to set this) from this link
在我周围的谷歌,并会知道,我必须写JBoss的部署,structure.xml下的文件/ META-INF /文件夹,必须添加-Dorg.jboss.as.logging.per部署=假到开始- 从这个链接的服务器(我不知道我必须在哪里设置)
so can any one give me steps to configure logging in jboss 6.x with Log4j or any logging like java.util.logging to log statements on console or in file thanks.
任何人都可以给我一些步骤来配置 jboss 6.x 中的日志记录,或者像 java.util.logging 这样的任何日志记录在控制台或文件中记录语句,谢谢。
回答by Nazia
If you want logging
a. you want to use your own "log4j.jar" place it in lib folder
b. place jboss-deployment-structure.xml in META-INF folder
c. Add log4j.xml in WEB-INF/classes
of your application.
Add this in jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <exclusions> <module name="org.apache.log4j" /> </exclusions> </deployment> </jboss-deployment-structure>
Add this in log4j.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="appender" class="org.apache.log4j.FileAppender"> <param name="File" value="${jboss.server.log.dir}/server.log"/> <param name="Append" value="true"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %p - %m%n"/> </layout> </appender> <root> <priority value ="trace"/> <appender-ref ref="appender"/> </root> </log4j:configuration>
Then you can see logging on console....
如果你想记录
一种。你想用你自己的“log4j.jar”把它放在lib文件夹中
湾 将 jboss-deployment-structure.xml 放在 META-INF 文件夹中
C。在 WEB-INF/classes 中添加 log4j.xml
您的应用程序。
在 jboss-deployment-structure.xml 中添加这个
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <exclusions> <module name="org.apache.log4j" /> </exclusions> </deployment> </jboss-deployment-structure>
在 log4j.xml 中添加这个
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="appender" class="org.apache.log4j.FileAppender"> <param name="File" value="${jboss.server.log.dir}/server.log"/> <param name="Append" value="true"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %p - %m%n"/> </layout> </appender> <root> <priority value ="trace"/> <appender-ref ref="appender"/> </root> </log4j:configuration>
然后你可以看到在控制台上登录....
回答by havelino
You should find the standalone.bat file into the /bin folder of Jboss, then you should edit this file, finding the next line
你应该在Jboss的/bin文件夹中找到standalone.bat文件,然后你应该编辑这个文件,找到下一行
rem Setup JBoss specific properties
set JAVA_OPTS=-Dprogram.??name=%PROGNAME% %JAVA_OPTS%
And replace for this
并替换为这个
set "JAVA_OPTS= -Dorg.jboss.as.logging.per-deployment=false"
set "JAVA_OPTS= -Dorg.jboss.as.logging.per-deployment=false"