简体   繁体   中英

How to log different log level to different log file from the same category in Wildfly standalone.xml?

I want to log all error and warn to an warn_error.log file and the rest to the rest.log file.

I have create the following in standalone.xml but it doesn't do what I expected.

Anyone any suggestion or solutions?

`<periodic-rotating-file-handler name="MY_WARN_ERROR" autoflush="true">
                <formatter>
                    <named-formatter name="PATTERN"/>
                </formatter>
                <file relative-to="jboss.server.log.dir" path="warn_error.log"/>
                <suffix value=".yyyy-MM-dd"/>
                <append value="true"/>
            </periodic-rotating-file-handler>`
`<periodic-rotating-file-handler name="MY_REST" autoflush="true">
                <formatter>
                    <named-formatter name="PATTERN"/>
                </formatter>
                <file relative-to="jboss.server.log.dir" path="rest.log"/>
                <suffix value=".yyyy-MM-dd"/>
                <append value="true"/>
            </periodic-rotating-file-handler>`
            <logger category="com.myapplication" use-parent-handlers="false">
                <level name="ERROR"/>
                <level name="WARN"/>
                <handlers>
                    <handler name="MY_WARN_ERROR"/>
                </handlers>
            </logger>
            <logger category="com.myapplication" use-parent-handlers="false">
                <level name="ALL"/>
                <handlers>
                    <handler name="MY_REST"/>
                </handlers>
            </logger>

You can't define the same logger twice. You'd have to use filters if you really only want specific logs going into one file. You have to add the handlers to a single logger configuration though.

Something like:

/subsystem=logging/periodic-rotating-file-handler=MY_WARN_ERROR:add(level=WARN, named-formatter=PATTERN, file={relative-dir=jboss.server.log.dir, path=warn_error.log}, append=true, suffix=".yyyy-MM-dd", autoflush=true)
/subsystem=logging/periodic-rotating-file-handler=MY_REST:add(named-formatter=PATTERN, file={relative-dir=jboss.server.log.dir, path=warn_error.log}, append=true, suffix=".yyyy-MM-dd", autoflush=true)
/subsystem=logging/logger=com.myapplication:add(use-parent-handlers=false, handlers=[MY_WARN_ERROR, MY_REST])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM