I would like to print all INFO logs to my console, but only send ERROR logs to my Airbrake appender.
My log4j2 has a root logger that adds the ConsoleAppender and is set to log level INFO.
<Loggers>
<Root level="INFO">
<AppenderRef ref="ConsoleAppender"/>
</Root>
</Loggers>
I then create a logger by the name of my application com.acme.app
Logger logger = LogManager.getLogger("com.acme.app");
logger.info("This is an info log");
logger.error("This is an error log");
With this configuration, when I run my application I will get the output
2019-06-10 12:20:48 [main] INFO ... - This is an info log
2019-06-10 12:20:48 [main] ERROR ... - This is an error log
I now want to add the airbrake appender and only send ERROR logs to airbrake, but I want to continue printing both INFO and ERROR logs.
<Loggers>
<Root level="INFO">
<AppenderRef ref="ConsoleAppender"/>
</Root>
<Logger name="com.acme.app" level="ERROR">
<AppenderRef ref="Airbrake"/>
</Logger>
</Loggers>
This will start sending ERROR logs to my airbrake, but now I will only see ERROR logs in the console.
If I set the level to INFO or move the appender to the root, I will see both INFO and ERROR logs, but I will also be sending INFO logs to airbrake- which is undesirable.
I've also tried adding multiple levels for the same logger name and explicitly point INFO back to the console-
<Loggers>
<Root level="INFO">
<AppenderRef ref="ConsoleAppender"/>
</Root>
<Logger name="com.acme.app" level="ERROR">
<AppenderRef ref="Airbrake"/>
</Logger>
<Logger name="com.acme.app" level="INFO">
<AppenderRef ref="ConsoleAppender"/>
</Logger>
</Loggers>
I tried both ERROR first and INFO first and it appears whichever is the last defined is what's used. If INFO comes last it will print all of the logs but not sending any errors, if ERROR comes last it will send the error but not print any of the INFO logs.
How can I have Airbrake capture all of the ERROR logs, but allow other logs to fallback to the root logger without sending all logs to the Airbrake appender?