JBoss6 : jboss-6.0.0.Final/server/default/deploy/jboss-logging.xml

Pour une application spécifique & "additivity" remplacé par "use-parent-handlers"

Le paramètre "additivity" est remplacé par "use-parent-handlers", le mettre a false permet de ne pas logguer plusieurs fois la même chose.

<!-- 
   Le paramètre "additivity" est remplacé par "use-parent-handlers"
   <logger category="com.placeoweb.ws" additivity="false">
-->
   <logger category="com.placeoweb.ws" use-parent-handlers="false">
     <level name="TRACE" />
     <handlers>
         <handler-ref name="PLACEOWEB_WS"/>
     </handlers>
   </logger>

Comment faire tourner ses log JBoss datée de minuit à minuit au lieu de midi à midi, et pour ne pas saturer le disque dur de logs

Community > JBoss AS > Installation, Configuration & Deployment > Discussions > periodic-rotating-file-handler rotate at 12PM instead 12AM

periodic-rotating-file-handler : A time/date based rolling handler : org.jboss.logmanager.handlers.PeriodicRotatingFileHandler

<!-- A time/date based rolling handler -->
   <periodic-rotating-file-handler
         file-name="${jboss.server.log.dir}/server.log"
         name="FILE"
         autoflush="true"
         append="true"
         suffix=".yyyy-MM-dd">  <!-- To roll over at the top of each hour, use ".yyyy-MM-dd-HH" instead -->
 
      <error-manager>
         <only-once/>
      </error-manager>
 
      <formatter>
         <!-- To revert back to simple stack traces without JAR versions, change "%E" to "%e" below. -->
         <!-- Uncomment this to get the class name in the log as well as the category
         <pattern-formatter pattern="%d %-5p [%c] %C{1} (%t) %s%E%n"/>
         -->
         <!-- Uncomment this to log without the class name in the log -->
         <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>
      </formatter>
   </periodic-rotating-file-handler>

size-rotating-file-handler : A size based file rolling appender : org.jboss.logmanager.handlers.SizeRotatingFileHandler

ATTENTION, jboss6 est bugé (How to control "server.log" file size in JBoss 6.0.GA release?), il faudra attendre le jboss6.1 pour corriger le problème : les logs jboss ne tournent pas au delà de 1 backupIndex (size-rotating-file-handler not rotating). Vous aurez beau spécifier max-backup-index="3" pour avoir .log, .log.1 .log.2 .log.3 vous n'obtiendrez que les logs :

server.log
server.log.1
<!-- A size based file rolling appender -->
   <size-rotating-file-handler
         file-name="${jboss.server.log.dir}/server.log"
         name="FILE"
         autoflush="true"
         append="true"
         rotate-size="500k"
         max-backup-index="5">
 
      <error-manager>
         <only-once/>
      </error-manager>
 
      <formatter>
         <pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>
      </formatter>
   </size-rotating-file-handler>

Autres ressources sur le Logging Jboss

JBoss4.2.3 : jboss-4.2.3.GA-jdk6/server/default/conf/jboss-log4j.xml

Si vous ne spécifiez pas au niveau de vos applications la déclaration pour log4j, vous pouvez le faire au niveau serveur via le fichier jboss-4.2.3.GA-jdk6/server/default/conf/jboss-log4j.xml

Log rotate

Faire tourner les logs pour ne pas saturer vos disques durs en stockant uniquement 10 fichiers de 100Mo chacun :

<!-- ================================= -->
   <!-- Preserve messages in a local file -->
   <!-- ================================= -->
 
   <!-- A time/date based rolling appender -->
   <!--<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">-->
   <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="MaxBackupIndex" value="10"/>
      <param name="MaxFileSize" value="100MB"/>
 
      <!-- Rollover at midnight each day -->
      <!--<param name="DatePattern" value="'.'yyyy-MM-dd"/>-->
 
      <!-- Rollover at the top of each hour
      <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
      -->
 
      <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>
   </appender>

Pour une application spécifique

<!-- ====================================== -->
   <!-- APPENDER DE Placeoweb Web Services (client) -->
   <!-- ====================================== -->
   <appender name="PLACEOWEB_WS" class="org.jboss.logging.appender.RollingFileAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="File" value="${jboss.server.home.dir}/log/MONAPP/pidiWsClient.log"/>
      <param name="Append" value="true"/>
      <!--<param name="DatePattern" value="'.'yyyy-MM-dd"/>-->
      <param name="MaxBackupIndex" value="10"/>
      <param name="MaxFileSize" value="100MB"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
      </layout>
   </appender>
 
   <category name="com.placeoweb.ws" additivity="false">
       <priority value="TRACE"/>
       <appender-ref ref="PLACEOWEB_WS"/>
   </category>

Pour limiter ou exclure les logs de hibernate

Adapté depuis CestPasDur.com, tutoriaux et ressources du web : Hibernate : Tracer les requêtes SQL, Tracer la valeur des paramètres hibernate et Tracer les transactions Hibernate

<logger name="org.hibernate">
       <level value="OFF" />
   </logger>

Les niveaux de log de la classe Level

  • ALL : The ALL has the lowest possible rank and is intended to turn on all logging.
  • DEBUG : The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
  • ERROR : The ERROR level designates error events that might still allow the application to continue running.
  • FATAL : The FATAL level designates very severe error events that will presumably lead the application to abort.
  • INFO :The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
  • OFF : The OFF has the highest possible rank and is intended to turn off logging.
  • TRACE : The TRACE Level designates finer-grained informational events than the DEBUG
  • WARN :The WARN level designates potentially harmful situations.

Dans l'ordre de déclaration d'importance d'alerte :

FATAL > ERROR > WARN > INFO > DEBUG > TRACE

Et si vous souhaitez récupérer tous ou aucun de ses niveaux :

ALL OFF

Une explication en français : Introduction à Log4J