How to configure jboss 7 to write logs to differen

2019-05-21 00:53发布

I'm using Jboss 7.1.1 and I have the following log definition:

<subsystem xmlns="urn:jboss:domain:logging:1.1">
        <console-handler name="CONSOLE">
            <level name="INFO"/>
            <formatter>
                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
            </formatter>
        </console-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>
        <size-rotating-file-handler name="ACEII">
            <level name="DEBUG"/>
            <formatter>
                <pattern-formatter pattern="%z{utc}%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%c] %s%E%n"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="ACEII.log"/>
            <rotate-size value="10M"/>
            <max-backup-index value="10"/>
            <append value="true"/>
        </size-rotating-file-handler>
        <logger category="ace2" use-parent-handlers="false">
            <level name="DEBUG"/>
            <handlers>
                <handler name="ACEII"/>
            </handlers>
        </logger>
        <logger category="com.arjuna">
            <level name="WARN"/>
        </logger>
        <logger category="org.apache.tomcat.util.modeler">
            <level name="WARN"/>
        </logger>
        <logger category="sun.rmi">
            <level name="WARN"/>
        </logger>
        <logger category="jacorb">
            <level name="WARN"/>
        </logger>
        <logger category="jacorb.config">
            <level name="ERROR"/>
        </logger>
        <root-logger>
            <level name="INFO"/>
            <handlers>
                <handler name="CONSOLE"/>
                <handler name="FILE"/>
            </handlers>
        </root-logger>
    </subsystem>

I'd like the ACE log to be written to a different folder, so I tried putting different values in the relative-to attribute but nothing seems to work, any idea on how to do it?

5条回答
▲ chillily
2楼-- · 2019-05-21 01:28

This is what I use; I then handle log rotation with logrotate:

    <file-handler name="FILE" autoflush="true">
        <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"/>
        <append value="true"/>                                                                                                                             
    </file-handler>

Obviously, you can modify this to suit your needs.

查看更多
在下西门庆
3楼-- · 2019-05-21 01:42

This works just fine for me.

domain.sh -Djboss.server.log.dir="my custom logs dir"
查看更多
欢心
4楼-- · 2019-05-21 01:45

Know this is an older question, but still found it relevant for JBOSS EAP 7

I found James response from here insightful - https://developer.jboss.org/wiki/Wildfly82LogPathChange

I was able to edit the standalone.conf and specify the custom logging directory there.

The is also a domain.conf that can be edited for domain mode.

All that is needed it to add the following to the end of the file:

#Specify the log dir
JAVA_OPTS="$JAVA_OPTS -Djboss.server.log.dir=my custom logs dir"

As I understand it for Windows the .bat files can be updated instead of the .conf files.

查看更多
我命由我不由天
5楼-- · 2019-05-21 01:45

Found the answer :)

I'm using Java service wrapper to install Jboss as a windows service and that service has a configuration file located in a certain path, so I've noticed that if i remove the relative-to attribute it write the logs to the folder where the configuration file is located.

All i had to do define it like this:

<size-rotating-file-handler name="ACEII">
            <level name="DEBUG"/>
            <formatter>
                <pattern-formatter pattern="%z{utc}%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%c] %s%E%n"/>
            </formatter>
            **<file path="../Log/ACEII.log"/>**
            <rotate-size value="10M"/>
            <max-backup-index value="10"/>
            <append value="true"/>
        </size-rotating-file-handler>

And that did the trick for me.

查看更多
手持菜刀,她持情操
6楼-- · 2019-05-21 01:53

You need to leave off the relative-to and enter the absolute path in the path attribute.

    <size-rotating-file-handler name="ACEII">
        <level name="DEBUG"/>
        <formatter>
            <pattern-formatter pattern="%z{utc}%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p [%c] %s%E%n"/>
        </formatter>
        <file path="/var/log/myLogDir/ACEII.log"/>
        <rotate-size value="10M"/>
        <max-backup-index value="10"/>
        <append value="true"/>
    </size-rotating-file-handler>

You can also use your own relative path by adding a path to your configuration.

In CLI you would just execute: /path=my.log.dir:add(path="/var/log")

If you just want to edit the xml add the following.

<paths>
    <path name="my.log.dir" path="/var/log"/>
</paths>

Paths themselves can have a relative path if you wanted to define specif directories in a default log directory for example.

Once you have your path defined you can use the name you gave the path in the relative-to attribute.

查看更多
登录 后发表回答