Log4j logging doesn't work on wildfly-10.1.0.Final, even logfile is not created. Application seems to be working
my 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="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/local/icm/iban-konverter/logs/iban-konverter-log.txt"/>
<param name="Encoding" value="ISO-8859-1"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="3"/><!-- define how many backup files to keep -->
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<logger name="com.bsbanksysteme">
<level value="debug"/>
</logger>
<root>
<priority value ="error"/>
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>
Related
I am using weblogic 10.3.6 and Iam trying to use log4j1.2 for logging purposes.
I have created log4j.xml in src/main/resources.
But log4j is not creating any file or nor even logging on console.
I tried giving jvm property -Dlog4j.debug=true but even that is not printing anything on console.
Any pointers?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<!-- Console Appender -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
</layout>
</appender>
<!-- Info Log File Appender -->
<appender name="info-log" class="org.apache.log4j.FileAppender">
<param name="File" value="C:\\Users\\rajan.d.panchal\\Desktop\\newlog\\info.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="debug" />
<param name="LevelMax" value="info" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender>
<!-- Error Log File Appender -->
<appender name="error-log" class="org.apache.log4j.FileAppender">
<param name="Append" value="false" />
<param name="File" value="C:\\Users\\abc\\Desktop\\newlog\\error.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="warn" />
<param name="LevelMax" value="fatal" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender>
<logger name="com.jcg.log4j.example" additivity="false">
<appender-ref ref="info-log" />
<appender-ref ref="error-log" />
</logger>
<root>
<level value="debug" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
Ok. So I was using JRebel and It was not creating any logs. After disabling JRebel it worked.
I get this error "log4j:ERROR Failed to rename" in my tomcat server log.
I have multiple DailyRollingFileAppender in my log4j XML. And each appender points to different file. Only once instance of the application is running.
I used Handle utility and run the command (with log file name as parameter)
handle -f ams-app.log
and the result is
Tomcat7.exe pid: 5032 type: File 54C: E:\apps\ams\logs\ams-app.log
From this I assume there is only one lock on the file.
My environment Windows Server 2008, tomcat 7.0 and Java 6 and slf4j-log4j12(1.5.6)
This problem was not happening when same application hosted on AIX server.
I googled this problem and it seems to be windows specfic.
Also I am not keen to use DatedFileAppenders or any forked log4j.
Does logback solve such issues.
Any suggestions on how to solve this problem is appreciated.
Thanks
here my log4j xml
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CONSOLE_APPENDER" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m %n"/>
</layout>
</appender>
<appender name="APP_APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="datePattern" value="yyyy-MM-dd"/>
<param name="file" value="E:/apps/ams/logs/ams-app.log"/>
<param name="append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m %n"/>
</layout>
</appender>
<appender name="SQL_APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="datePattern" value="yyyy-MM-dd"/>
<param name="file" value="E:/apps/ams/logs/ams-sql.log"/>
<param name="append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m %n"/>
</layout>
</appender>
<appender name="Quartz_APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="datePattern" value="yyyy-MM-dd"/>
<param name="file" value="E:/apps/ams/logs/ams-Quartz.log"/>
<param name="append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m %n"/>
</layout>
</appender>
<logger name="org.springframework"><level value="WARN"/></logger>
<logger name="flex.messaging.log.ServletLogTarget"><level value="WARN" /></logger>
<logger name="net.sf.jasperreports"><level value="WARN" /></logger>
<logger name="net.sf.jasperreports.engine.fill"><level value="WARN" /></logger>
<logger name="org.apache.commons.beanutils"><level value="WARN" /></logger>
<logger name="jdbc.sqltiming" additivity="false"><level value="DEBUG"/><appender-ref ref="SQL_APPENDER"/></logger>
<logger name="org.quartz" additivity="false"><level value="WARN" /><appender-ref ref="Quartz_APPENDER"/></logger>
<logger name="org.quartz.SchedulerException"><level value="ERROR" /><appender-ref ref="MAIL_APPENDER"/></logger>
<logger name="org.hmil.ams.BatchDAO" additivity="false"><level value="INFO"/><appender-ref ref="Quartz_APPENDER"/></logger>
<root>
<priority value="debug"></priority>
<appender-ref ref="APP_APPENDER" />
<appender-ref ref="CONSOLE_APPENDER"/>
</root>
It appears that if you're running windows this is a known bug:
see here:
http://do.whileloop.org/2014/02/14/log4j-rolling-file-appenders-in-windows/
See here:
https://issues.apache.org/bugzilla/show_bug.cgi?id=29726
And also here:
http://www.coderanch.com/t/424837/java/java/Log-log-file-rolled-day
I had the same issue and fixed it by updating log4j to version 1.2.15 as per this discussion
My requirement is to log the messages to 3 separate log files.
I am using 3 appenders in a JBOSS server.
Three of them need to work in the way such as
1.RollingFileAppender, consoleAppender work for 'INFO' and 'ERROR' modes.
2.DailyRollingFileAppender for 'ERROR' mode and for a specific category only.
I have tried lots of combinations like changing the priority value and the categories, but I have so far found no way in which all the three work simulatneously. Either fileAppender and ConsoleAppender work(logging both ERRROR and INFO) and the DailyRollingFileAppender does not or DailyRollingFileAppender does but the other two log only ERRORS not INFO.
Please tell me a way so that the three of them work.
Below mentioned is the log4j.xml I am using.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- -->
<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- file appender -->
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="C:/logs/mdmWSServer.log" />
<param name="MaxBackupIndex" value="5" />
<param name="MaxFileSize" value="5MB" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}] [%t] [%-5p][ %c:] %m%n"/>
</layout>
</appender>
<appender name="dailyFileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="C:/logs/dailyApp.log"/>
<param name="MaxBackupIndex" value="5" />
<param name="MaxFileSize" value="5MB" />
<param name="DatePattern" value="'.'yyyy-MM-dd-HH" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}] [%t] [%-5p][%c:] %m%n"/>
</layout>
</appender>
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}] [%t] %m%n"/>
</layout>
</appender>
<category name="com">
<priority value="INFO"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="consoleAppender"/>
</category>
<category name="com.gsk">
<priority value="ERROR"/>
<appender-ref ref="dailyFileAppender"/>
</category>
<category name="org.apache">
<priority value="INFO"/>
<appender-ref ref="fileAppender"/>
</category>
<root>
<priority value="DEBUG"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="consoleAppender"/>
</root>
</log4j:configuration>
You can restrict an appender to only log a certain level by using filter class specifying which level you would want to log . See the sample code below
<appender name="TRACE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%t] %-5p %c - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG" />
<param name="levelMax" value="DEBUG" />
</filter>
</appender>
I am not sure how to log bean validation messages when using log4j and hibernate validator.
I tried using a "org.hibernate.validator" category in log4j resulting in a runtime exception...
I also tried using "javax.validation" category in log4j; however nothing gets logged.
Can anyone please help?
Regards,
Edit: Here is my log4j config:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d: %5p (%F:%L) %m%n"/>
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="output.log"/>
<param name="MaxFileSize" value="2000KB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c - %m%n"/>
</layout>
</appender>
<category name="org.apache.tapestry5">
<priority value="INFO"/>
</category>
<category name="com.bignibou">
<priority value="DEBUG"/>
</category>
<category name="org.hibernate.validator.engine.ValidatorImpl">
<priority value="TRACE"/>
</category>
<root>
<priority value="WARN"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
Do you have the log4j binding for sl4f on your classpath? You might also have a look at the log4j.properties file used for tests in Hibernate Validator.
I have a class which events I want to log. Say, there are 2 levels: debug and error. How can I log errors to an errorFile and debug info to a debugFile?
So that I use log4j.xml there is a filter mechanism, but it seems to work only for different categories not inside one class.
Please, help to newbie. =)
You have to define and use two appender with different Threshold like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Error -->
<appender name="ErrorFile"
class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="error"/>
<param name="file" value="log.err" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d %C.%M (%L) - %m%n" />
</layout>
</appender>
<appender name="LogFile"
class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="debug"/>
<param name="file" value="log.log" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d %C.%M (%L) - %m%n" />
</layout>
</appender>
<logger name="foo.bar" additivity="false">
<level value="debug" />
<appender-ref ref="LogFile" />
<appender-ref ref="ErrorFile" />
</logger>
<root>
<priority value="warn" />
<appender-ref ref="ErrorFile"/>
</root>
</log4j:configuration>
This question is also answered in the log4j FAQs.
Just found the LogToAppenderByLevel solution (here) which may be also helpful for you.