Class BackTraceFileHandler

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable, org.jboss.logmanager.handlers.FlushableCloseable, org.jboss.logmanager.Protectable

    public class BackTraceFileHandler
    extends org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
    For Jboss/Wildfly: Write debug messages only when an error occurs.

    This handler holds back debug messages in a buffer and writes them only to the file when an error occurs.

    You should clear the buffer at the beginning or end of each HTTP request, to ensure that the buffer does not contain old stuff when processing the next HTTP request.

    You have to put the utilities.jar file into the Wildfly folder modules/de/stefanfrings/utils/main together with a modules.xml file:

     <?xml version="1.0" encoding="UTF-8"?>
     <module xmlns="urn:jboss:module:1.3" name="de.stefanfrings.utils">
             <resource-root path="utilities.jar"/>
             <module name="org.jboss.logmanager"/>

    Example of the required settings in standalone.xml:

     <!-- Write log messages >= INFO to server.log, without exceptions -->
     <periodic-rotating-file-handler name="serverLog" autoflush="false">
        <level name="INFO"/>
           <pattern-formatter pattern="%-5p %date{YYYY-MM-DD HH:mm:ss.SSS} %X{requestID} [%t] %-50c{50} %s%n"/>
        <file relative-to="jboss.server.log.dir" path="server.log"/>
        <suffix value=".yyyy-MM-dd"/>
        <append value="true"/>
     <!-- Write buffered log messages to debug.log when a warning or error occurs -->
     <custom-handler name="debugLog" class="de.stefanfrings.utils.BackTraceFileHandler" module="de.stefanfrings.utils">
             <pattern-formatter pattern="%-5p %date{YYYY-MM-DD HH:mm:ss.SSS} %X{requestID} [%t] %-50c{50} %s%e%n"/>
             <property name="fileName" value="${jboss.server.log.dir}/debug.log"/>
             <property name="suffix" value=".yyyy-MM-dd"/>
             <property name="bufferSize" value="100"/>
             <property name="allowedLevel" value="OFF"/>
             <property name="triggerLevel" value="WARN"/>
     <!-- Log level for specific classes or packages -->
     <logger category="de.stefanfrings">
         <level name="DEBUG"/>
     <!-- Default log level and output -->
         <level name="INFO"/>
             <handler name="debugLog"/>
             <handler name="serverLog"/>
    Stefan Frings,
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.jboss.logmanager.handlers.PeriodicRotatingFileHandler

    • Field Summary

      • Fields inherited from class org.jboss.logmanager.handlers.WriterHandler

      • Fields inherited from class org.jboss.logmanager.ExtHandler

        handlers, handlersUpdater
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void clearBuffer()
      Clear the buffer of the current thread.
      void close()
      Close this handler, release buffer memory.
      protected void doPublish​(org.jboss.logmanager.ExtLogRecord record)  
      void setAllowedLevel​(String level)  
      void setBufferSize​(String size)  
      void setTriggerLevel​(String level)  
      • Methods inherited from class org.jboss.logmanager.handlers.PeriodicRotatingFileHandler

        getNextSuffix, getTimeZone, preWrite, setFile, setSuffix, setTimeZone
      • Methods inherited from class org.jboss.logmanager.handlers.FileHandler

        getFile, setAppend, setFileName
      • Methods inherited from class org.jboss.logmanager.handlers.OutputStreamHandler

        getEncoding, setEncoding, setOutputStream, setWriter
      • Methods inherited from class org.jboss.logmanager.handlers.WriterHandler

        flush, safeClose
      • Methods inherited from class org.jboss.logmanager.ExtHandler

        addHandler, checkAccess, checkAccess, clearHandlers, disableAccess, enableAccess, getHandlers, isAutoFlush, isEnabled, protect, publish, publish, removeHandler, setAutoFlush, setEnabled, setErrorManager, setFilter, setFormatter, setHandlers, setLevel, unprotect
    • Constructor Detail

      • BackTraceFileHandler

        public BackTraceFileHandler()
    • Method Detail

      • close

        public void close()
        Close this handler, release buffer memory.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        close in class org.jboss.logmanager.handlers.WriterHandler
      • clearBuffer

        public static void clearBuffer()
        Clear the buffer of the current thread.
      • doPublish

        protected void doPublish​(org.jboss.logmanager.ExtLogRecord record)
        doPublish in class org.jboss.logmanager.handlers.WriterHandler
      • setAllowedLevel

        public void setAllowedLevel​(String level)
      • setTriggerLevel

        public void setTriggerLevel​(String level)
      • setBufferSize

        public void setBufferSize​(String size)