-
1. Re: My log is not working
jaysensharma Aug 14, 2014 12:38 PM (in response to davidpadilha)Hello,
Can you attach a sample application which demonstrate your issue. I tested with a simple WAR [1] which has a simple servlet with log4j.properties and it is able to log properly in it's own custom log.
The WAR which i used has the following structure.
Log4j2DemoWebApp.war
|-- index.jsp
`-- WEB-INF
|-- classes
| |-- log4j.properties
| |-- MyServlet.java
| `-- servlets
| `-- MyServlet.class
|-- jboss-deployment-structure.xml
|-- lib
| `-- log4j-1.2.16.jar
`-- web.xml
The jboss-deployment-structure.xml is used in order to exclude the log4j APIs which are offered by WildFly and to use the log4j jar which is placed inside the WEB-INF/lib.
<jboss-deployment-structure> <deployment> <exclusions> <module name="org.apache.log4j"/> </exclusions> </deployment> </jboss-deployment-structure>
The log4j.properties us as following:
log4j.rootLogger=INFO, file # Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=${jboss.server.log.dir}/test.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
[1] MiddlewareMagicDemos/Log4j2DemoWebApp.war at master · jaysensharma/MiddlewareMagicDemos · GitHub
-
2. Re: My log is not working
jamezp Aug 14, 2014 7:02 PM (in response to davidpadilha)1 of 1 people found this helpfulI think you're misunderstanding the use-deployment-logging-config attribute. Setting that to false tells the logging subsystem not to scan your deployment for your log4j.properties file. From what it looks like if you were to place your log4j.properties WAR/META-INF or WAR/WEB-INF/classes directory then it should work and leave the use-deployment-logging-config set to true it should work.
Also make sure you're not including log4j in your WAR/WEB-INF/lib directory either.
--
James R. Perkins
-
3. Re: Re: My log is not working
jamezp Aug 14, 2014 7:07 PM (in response to jaysensharma)1 of 1 people found this helpfulYou can now do this in WildFly without having to exclude log4j, though that way still works. See https://docs.jboss.org/author/display/WFLY8/Logging+Configuration#LoggingConfiguration-Attributes and https://docs.jboss.org/author/display/WFLY8/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F for more details.
--
James R. Perkins
-
4. Re: My log is not working
davidpadilha Aug 15, 2014 11:17 AM (in response to jaysensharma)I've done all the process again and now it's working.
I was trying to make it work only using a log4j.properties inside the jar that is a dependency from my war. When i have moved the log4j.properties to war file, everything works.
Thanks for the help.