Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure PeriodicSizeRotatingFileHandler in JBoss 7?

I search logger configuration in the web for Jboss 7. How to configure logger using date and size together.

File Logger 1 size-rotating-file-handler

<size-rotating-file-handler name="FILE">
    <formatter>
        <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
    </formatter>
    <file relative-to="jboss.server.log.dir" path="server.log"/>
    <rotate-size value="1000k"/>
    <max-backup-index value="20"/>
    <append value="true"/>
</size-rotating-file-handler>

Out Put Files are : 
    server.log.1
    server.log.2
    server.log.3
    ..

File Logger 2 periodic-rotating-file-handler

<periodic-rotating-file-handler name="FILE">
    <formatter>
        <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
    </formatter>
    <file relative-to="jboss.server.log.dir" path="server.log"/>
    <suffix value=".yyyy-MM-dd"/>
    <append value="true"/>
</periodic-rotating-file-handler>

Out Put Files are : 
    server.log.2013-12-12
    server.log.2013-12-13
    server.log.2013-12-14
    ..

My expected files are

server.log.2013-12-12.1
server.log.2013-12-12.2
server.log.2013-12-12.3
server.log.2013-12-13.1
server.log.2013-12-13.2
server.log.2013-12-13.3         
like image 814
Zaw Than oo Avatar asked Jan 13 '14 04:01

Zaw Than oo


2 Answers

Depending on your version of JBoss AS 7 there is a org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler you can use as a custom-handler. I believe it was introduced in jboss-logmanager 1.3.0.Final. I can't recall which version of JBoss AS/WildFly it is in though.

Here's an example CLI command.

/subsystem=logging/custom-handler=example:add(class=org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler, module=org.jboss.logmanager, formatter="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n", properties={rotateSize=1024000,maxBackupIndex=20,suffix=".yyyy-MM-dd",fileName="${jboss.server.log.dir}/example.log"})
like image 146
James R. Perkins Avatar answered Sep 24 '22 08:09

James R. Perkins


Here's what worked for me (make sure to change the rotationSize and maxBackupIndex to whatever makes sense for you. The numbers I have in there are just for testing):

        <custom-handler name="FILESIZEDATE" class="org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler" module="org.jboss.logmanager">
            <formatter>
                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
            </formatter>
            <properties>
                <property name="autoFlush" value="true"/>
                <property name="append" value="true"/>
                <property name="rotateSize" value="1000"/>
                <property name="maxBackupIndex" value="20"/>
                <property name="suffix" value=".yyyy-MM-dd"/>
                <property name="fileName" value="${jboss.server.log.dir}/server.log"/>
            </properties>
        </custom-handler>

        <root-logger>
            <level name="INFO"/>
            <handlers>
                <handler name="FILESIZEDATE"/>
                <handler name="CONSOLE"/>
            </handlers>
        </root-logger>
like image 29
Creature Avatar answered Sep 23 '22 08:09

Creature