Rotating Access Logs in JBoss EAP 7.x

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application (EAP)
    • 7.x

Issue

  • How to rotate access logs in EAP by size?
  • How to set up the rotation period in EAP access log?
  • I have noticed that log size is creating in GB so please let me know log rotation solution so that once it touches 500MB it rotates

Resolution

If the access log isn't enabled, follow the instructions in this knowledge article "How to enable access logging for JBoss EAP 7?" first.

Run the following commands in JBoss CLI:

  • Standalone Mode:

      /subsystem=undertow/server=default-server/host=default-host/setting=access-log:write-attribute(name="use-server-log", value="true")
      /subsystem=logging/pattern-formatter=ACCESS_LOG_FORMATTER:add(pattern="%s%n")
      /subsystem=logging/periodic-size-rotating-file-handler=ACCESS_LOG:add(autoflush=true, append=true, named-formatter=ACCESS_LOG_FORMATTER, file={relative-to="jboss.server.log.dir", path="access_log.log"}, rotate-size=500m, suffix=".yyyy-MM-dd", max-backup-index=3)
      /subsystem=logging/logger=io.undertow.accesslog:add(handlers=[ACCESS_LOG], use-parent-handlers=false)
      :reload
    
  • Domain Mode:

      /profile=full-ha/subsystem=undertow/server=default-server/host=default-host/setting=access-log:write-attribute(name="use-server-log", value="true")
      /profile=full-ha/subsystem=logging/pattern-formatter=ACCESS_LOG_FORMATTER:add(pattern="%s%n")
      /profile=full-ha/subsystem=logging/periodic-size-rotating-file-handler=ACCESS_LOG:add(autoflush=true, append=true, named-formatter=ACCESS_LOG_FORMATTER, file={relative-to="jboss.server.log.dir", path="access_log.log"}, rotate-size=500m ,suffix=".yyyy-MM-dd", max-backup-index=3)
      /profile=full-ha/subsystem=logging/logger=io.undertow.accesslog:add(handlers=[ACCESS_LOG], use-parent-handlers=false)
      :reload
    

Or update the XML configuration file directly like the following:
Note: As mentioned in the configuration guide, the management CLI (or management console) is the preferred method, and it is not recommended to edit the XML configuration file manually. Because editing the XML configuration file manually can be error-prone.

  1. Add the <access-log> with use-server-log="true" option in the undertow subsystem:

     <access-log use-server-log="true"/>
    

    or add the following if you would like to use custom log format as described in this knowledge article

     <access-log pattern="%h %l %u %t &quot;%r&quot; %s %b &quot;%{i,Referer}&quot; &quot;%{i,User-Agent}&quot; Cookie: &quot;%{i,COOKIE}&quot; Set-Cookie: &quot;%{o,SET-COOKIE}&quot; SessionID: %S Thread: &quot;%I&quot; TimeTaken: %T" use-server-log="true"/>
    
  2. Create a new <formatter>:

     <formatter name="ACCESS_LOG_FORMATTER">
         <pattern-formatter pattern="%s%n"/>
     </formatter>
    
  3. Create a new <periodic-size-rotating-file-handler> in the logging subsystem:

     <periodic-size-rotating-file-handler name="ACCESS_LOG" autoflush="true">
         <formatter>
             <named-formatter name="ACCESS_LOG_FORMATTER"/>
         </formatter>
         <file relative-to="jboss.server.log.dir" path="access_log.log"/>
         <rotate-size value="500m"/>
         <max-backup-index value="3"/>
         <suffix value=".yyyy-MM-dd"/>
         <append value="true"/>
     </periodic-size-rotating-file-handler> 
    
  4. Specify the above "ACCESS_LOG" handler in a new <logger> category for io.undertow.accesslog with use-parent-handlers="false" in the logging subsystem:

     <logger category="io.undertow.accesslog" use-parent-handlers="false">
         <handlers>
             <handler name="ACCESS_LOG"/>
         </handlers>
     </logger>
    
  5. Restart your instance.


In addition, if you want to compress rotated access log automatically, you can use the feature added in JBoss EAP 7.3 or later. Please follow the steps described in this knowledge article "How to compress rotated access log in JBoss EAP 7" for details.

Root Cause

The access log defined in Undertow subsystem without the use-server-log option will create an access_log.log file rotating daily.

Components
Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.