M
M
mitaichik2016-05-07 00:12:59
Java
mitaichik, 2016-05-07 00:12:59

How to make 2 root appenders in log4j2?

Good day. I'm trying log4j2.
The task is to log all errors in 2 places: the console and the database (I wrote my appender).
I try like this, but it only logs to the last appender:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="bestapp">
    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
        <MysqlAppender name="MYSQL"/>
    </Appenders>
    <Loggers>
        <Root level="ERROR">
            <AppenderRef ref="CONSOLE" />
        </Root>
        <Root level="ERROR">
            <AppenderRef ref="MYSQL" />
        </Root>
    </Loggers>
</Configuration>

How to make it log in both?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vlad20012, 2016-05-07
@mitaichik

There should be only one root, but there can be many appenders:

<Loggers>
    <Root level="ERROR">
        <AppenderRef ref="CONSOLE" />
        <AppenderRef ref="MYSQL" />
    </Root>
</Loggers>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question