I'm running a Spring Boot application that uses logback. The idea is to have the log messages be sent to a RabbitMQ server. To accomplish this, I created an appender that extends ch.qos.logback.core.AppenderBase.
Here is my logback-spring.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="messaging" class="com.foo.logging.appender.MessagingAppenderLogback" />
<root level="info">
<appender-ref ref="messaging" />
</root>
</configuration>
All is well. However, in MessagingAppenderLogback, RabbitTemplate which I wish to use to send the message is null.
@Component
public class MessagingAppenderLogback extends AppenderBase<ILoggingEvent> {
@Autowired
RabbitTemplate rabbitTemplate;
public MessagingAppenderLogback(){ }
@Override
protected void append(ILoggingEvent event) {
System.out.println(" MessagingAppenderLogback#append w/ event " + event);
// rabbitTemplate.convertAndSend(event);
}
}
Per the documentation, I know that "The logging system is initialized early in the application ..."
I'd like to know what I have to do to have rabbitTemplate available in my appender.