Pathak
Pathak

Reputation: 193

How to rotate and zip log file using size-rotating-file-handler in wildlfy?

We want to use size-rotating-file-handler available inside logging subsystem of wildfly for size based rotation and compression. But we are able to rotate the file but not able to do compression or zip . Is there any alternate in wildfly so that we can achieve log rotation as well as zipping simultaneously?

We have followed and tried below link but didn't get any luck: https://developer.jboss.org/thread/278779

Note: We are using wildlfy-14 version.

We have used below CLI configuration for same:

/profile=full-ha/subsystem=logging/periodic-rotating-file-handler=FILE:remove()
/profile=full-ha/subsystem=logging/size-rotating-file-handler=FILE:add(name=FILE,autoflush=false,file={relative-to=jboss.server.log.dir,path=server.log},append=true,named-formatter=PATTERN,rotate-size=10m,max-backup-index=15,level=DEBUG)
/profile=full-ha/subsystem=logging/logger=org.hibernate.orm.deprecation:add(level=ERROR)

Upvotes: 1

Views: 4427

Answers (1)

James R. Perkins
James R. Perkins

Reputation: 17815

You'd need to add the suffix=".zip" attribute to your add command. However there is a bug that prevented that from working which wasn't fixed until WildFly 16.

The workaround would be to use a custom-handler which I realize is not ideal, but would work.

/profile=full-ha/subsystem=logging/custom-handler=FILE:add(module=org.jboss.logmanager, \
    class="org".jboss.logmanager.handlers.SizeRotatingFileHandler, \
    named-formatter=PATTERN, level=DEBUG, \
    properties={ \
        autoFlush=true, \
        append=true, \
        rotateSize=10485760, \
        maxBackupIndex=15, \
        fileName=${jboss.server.log.dir}/server.log, \
        suffix=".zip" \
    })

The other option would be to upgrade to WildFly 16 :)

Upvotes: 2

Related Questions