Log 4j Html Layout - log4j

I am using log4j (HTML Layout) the file does not get rolled over everyday for the below log4j.xml. I am using log4j extras. If I use log into a simple log file it works fine but does not work for a html layout.
<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<!-- Daily Rolling File Appender that compresses old files -->
<appender name="file" class="org.apache.log4j.rolling.RollingFileAppender" >
<param name="threshold" value="info"/>
<rollingPolicy name="file" class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="${catalina.home}/ApplicationLogs/ApplicationLogs-%d{yyyy-mm-dd}.html"/>
<param name="ActiveFileName" value="${catalina.home}/ApplicationLogs/ApplicationLogs.html"/>
</rollingPolicy>
<layout class="org.apache.log4j.HTMLLayout" >
<param name="LocationInfo" value="true" />
</layout>
</appender>
<root>
<priority value="debug"></priority>
<appender-ref ref="file" />
</root>
</log4j:configuration>

Related

Log4j logging stops intermittently

We're experiencing some stoppages on our log4j(v1.2.8) INFO logs. We're using a WebSphere(8.5.5) clustered server(vertical) with 3 members that runs on a single machine(UNIX). Stoppage is random; no specific file size, time or when about to rollover
We've first suspected that is a volume related problem as we've tested before on a lower volumed server the problem doesn't occur. I've later tested overloading this server but I could not replicate the problem.
Average daily production is 175,000 INFO lines. A workaround is available by just changing the timestamp of the log files to resume logging.
Already looked into the suggested fix on Log4j suddenly stops logging but nothing seemed to work. I'm hoping I could get some advise on were to look. Thank you.
log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<root>
<priority value="INFO" />
<appender-ref ref="TEST" />
</root>
<appender name="TEST" class="org.apache.log4j.RollingFileAppender">
<param name="encoding" value="UTF-8" />
<param name="file" value="$test/directory/logs/test${com.test.log.server.name}.log" />
<param name="MaxFileSize" value="10000KB" />
<param name="MaxBackupIndex" value="50" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%t] [%-12X{username}] [%-12X{servlet}] [%c{1}] %m%n" />
</layout>
</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 %c{1} - %m%n" />
</layout>
</appender>
</log4j:configuration>
The value of ${com.test.log.server.name} is declared in WebSphere JVM custom properties on each application server.
Any help would be greatly appreciated.

Weblogic, log4j and log4jdbc, log in file but not in console

In Weblogic, using log4jdbc, I need to log queries (using org.jdbcdslog.StatementLogger) only in a specific file but not in console.
I tried to start Weblogic with this parameter
-Dlog4j.configuration=file:%LOG4JDBC_HOME%\log4j.xml
This is the content of log4.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG" />
<param name="File" value="./logs/aladin.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss} %-5p %-30.30c %m%n" />
</layout>
</appender>
<category name="org.jdbcdslog.StatementLogger">
<priority value="INFO" />
<appender-ref ref="fileAppender" />
</category>
<category name="org.jdbcdslog.ResultSetLogger">
<priority value="FATAL" />
<appender-ref ref="fileAppender" />
</category>
<root>
<level value="DEBUG" />
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
The problem is that in console I see either org.jdbcdslog.StatementLogger and org.jdbcdslog.ResultSetLogger logged at INFO level, in aladin.log (the only file I'd like to log in) I don't see any log of org.jdbcdslog.StatementLogger and org.jdbcdslog.ResultSetLogger classes.
Is there a way to log these two classes only in aladin.log and not in console?

where to put log4j.xml in netbeans 6.8?

In my case,
I have configured my log4j.xml like this.
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler" />
<param name="File" value="F:/myLogger.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="20000KB" />
<param name="MaxBackupIndex" value="400" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %d{dd MMM yyyy HH:mm:ss.SSS} %-5l - %m%n%n" />
</layout>
</appender>
<!-- Root Logger -->
<root>
<priority value="error" />
<appender-ref ref="FILE" />
</root>
and put log4.xml file in source package.
but logger file is not created at specified folder.Let me know the exact path.
(it may be tha t i am using some external JAR which may have log4j.xml) so how to give priority to root application log4j.xml file.

Why i am getting the Warn Messages also in my logger when configured to get from INFO Level

I have this log4j.xml file which should only log from INFO Level
but i was also getting the WARN Level also in my log .
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender class="org.apache.log4j.RollingFileAppender" name="FILE">
<param value="D:\\RAM\\tst.log" name="File" />
<param value="10" name="MaxBackupIndex" />
<param value="200MB" name="MaxFileSize" />
<layout class="org.apache.log4j.PatternLayout">
<param value="%d[%t] %-5p(%F:<%M>:%L)- %m%n" name="ConversionPattern" />
</layout>
</appender>
<appender class="com.Log4JCustomAppender" name="CUSTAPPEN">
<layout class="org.apache.log4j.PatternLayout">
<param value="%d[%t] %-5p(%F:<%M>:%L)- %m%n" name="ConversionPattern" />
</layout>
</appender>
<appender class="org.apache.log4j.AsyncAppender" name="ASYNC">
<param name="Blocking" value="false"/>
<param name="BufferSize" value="1000"/>
<appender-ref ref="CUSTAPPEN" />
</appender>
<root>
<level value="INFO" />
<appender-ref ref="FILE" />
<appender-ref ref="ASYNC" />
</root>
</log4j:configuration>
This is the output i was getting in my Custom Appender and RollingFileAppender
LOgged One is 2013-06-23 01:05:55,954[main] FATAL(Hi.java:<main>:14)- This is a fatal Message
LOgged One is 2013-06-23 01:05:55,965[main] WARN (Hi.java:<main>:15)- This is a warn Message
please tell me how to avoid this .
This behavior is normal. Setting a logger to a specific level value indicates that you want that level AND all level above.
Levels are :
TRACE
DEBUG
INFO
WARN
ERROR
FATAL
OFF
If you want only the INFO level, you have to use filters on your appenders :
<filter type="org.apache.log4j.varia.LevelMatchFilter">
<acceptOnMatch value="true" />
<levelToMatch value="INFO" />
</filter>
<filter type="org.apache.log4j.varia.DenyAllFilter" />

Using RollingFileAppender ,DailyRollingFileAppender,ConsoleAppender in log4j. Not working

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>

Resources