What is a rollingfile appender ?
I want my jboss to delete logs either exceeding a maximum size or exceeding a certain date.
People on this forum have suggested me to use rollingfile appender.
How do I configure it in jboss-log4j.xml file ?
Here is an example:
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
Btw this is taken from our server's jboss-log4j.xml file - if you check your default server installation, I am fairly sure you find a similar configuration there ;-) Moreover, I guess if you add
<param name="MaxFileSize" value="100KB"/>
to the above, you get it roll over upon reaching the specified size.
For more info on appenders, see the Log4J manual.
Related
Need help with jboss logging.I am new to jboss application server. I am able to start the application server and i do see in the server log that jboss has started. But when i click on the application and surf around the application that i have deployed i dont see any logging and i am wondering why.I have tried doing this in jboss-log4j.xml
<appender-ref ref="CONSOLE"/>
<priority value="INFO" />
<appender-ref ref="FILE"/>
<priority value="INFO" />
You should create a new appender for your application in log4j.xml:
<appender name="MYAPPENDER" class=""org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/filename.log"/>
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
And then specify a category after it:
<category name="com.my.package" additivity="false">
<priority value="DEBUG" />
<appender-ref ref="MYAPPENDER"/>
</category>
Where com.my.package is the (top level) package of your application. All classes in this package and its sub-packages will be logged to MYAPPENDER.
I am running JBoss 4.0.5.GA and--I assume--it's included log4j package, both on OS X Mountain Lion. I have configured ../server/site/conf/log4j.xml to capture startup/shutdown messages in a separate file:
<appender name="SERVER_EVENTS" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server_events.log"/>
<param name="Append" value="false"/>
<param name="ImmediateFlush" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<category name="org.jboss.system.server.Server">
<priority value="INFO" />
<appender-ref ref="SERVER_EVENTS"/>
</category>
This works as far as capturing the startup/shutdown lines. I am using a LaunchAgent to watch that server_events.log file for changes. I have verified that the LaunchAgent loads, and is functional.
The LaunchAgent responds at the following times:
When run.sh kicks off and the server_events.log file is truncated.
On server shutdown, when a group of log entries ends with "Shutdown complete."
The problem I'm having is capturing the "Started in ..." message. After much Googling, I have an idea what the problem is, and I am unsure if a solution even exists. I believe the message is not getting captured because JBoss has "a hold" on the file while it's running. You can see above where I am explicitly requesting that JBoss "ImmediateFlush" the messages. I was under the impression that that is the default, but I can see in Finder that the file is 0 bytes, but watching the file opened in Sublime Text 2 reveals the startup message.
Is there any way to ensure that the startup message be written to disk immediately after it gets sent? Or am I out of luck since I'm running such an old version of JBoss?
How do we enable logging to debug class loading issues in JBoss 5.x. If it is under JBOSS_HOME/server/xxxxx/conf to configure jboss-log4j.xml, should we need to add any piece of code or is there any other way to enable tracing.
You can turn on logging in two places:
In JVM - you should just pass the extra switch -verbose:class. You can put these switch in your run.conf file in JAVA_OPTS variable definition.
Turn logging in jboss-log4j.xml file. You should place in the file such definition:
<category name="org.jboss.classloader">
<priority value="DEBUG"/>
</category>
It worked for me. I did add like below.
<appender name="CLASSLOADING" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value= "${jboss.server.log.dir}/classloading.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %m%n"/>
</layout>
</appender>
<category name="org.jboss.classloading">
<priority value="TRACE"/>
<appender-ref ref="CLASSLOADING"/>
</category>
You can also enable logs in command prompt or pass as parameters to the JBoss server using IDE as:
set "JAVA_OPTS=%JAVA_OPTS% -Xms2048m -Xmx4096m -XX:MaxPermSize=256m
-Dorg.jboss.resolver.warning=true -Dorg.apache.camel.jmx.disabled=true
-Djboss.server.log.threshold=DEBUG -Dsun.rmi.dgc.client.gcInterval=3600000
-Dsun.rmi.dgc.server.gcInterval=3600000"
Here we are also increasing the memory since writing debug results in a file/console increases memory consumption. Sometimes if we do not increase the memory, it causes a permGem error.
I'm working with my first jboss application server and am having some issues with the log files. Currently there is a bug in the software that is constantly streaming errors in the log file, each day I get a 708MB log file, and this quickly fills the HD space of the server.
In the jboss-log4j.xml I have 2 <appender> stanza's, one that rolls the log file each day, and a second that limits the log files to 10MB and keeps only the last 20 logs. Currently only the first stanza seems to be working. Based on this I think I can only have 1 <appender> stanza and need to merge these two....
Am I on the right track? If so can you provide some tips how I can merge these two together?
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- A size based file rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="10MB"/>
<param name="MaxBackupIndex" value="20"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
You can have more than one appender - default is to have a file appender for the log file and another for the console.
It looks like in your code you are writing to the same file in both cases, which probably
does not make much sense and also does not sound like what you want from the description you gave.
It is not possible to have two <appender> nodes writing to the same name='FILE'.
It is also not possible to merge these two <appender>'s into one stanza.
Currently my jboss's console log entries are not dated,
If the log is timely dated with time which will help me to debug some application performance issue.
Can any one give some tips on the same?
The log configuration in JBoss 3.2.7 exists in the log4j.xml file. You can find that file in the conf directory of given configuration.
You can find there such lines:
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
You can just simple comment first definition of ConversionPattern and uncomment the second one. Or just simple create your own conversion pattern, you can find more about it here: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html