Logging to RabbitMQ from a spring boot application

5.1k views Asked by At

I'm trying to use the AmqpAppender to log to a RabbitMQ exchange from a trivial spring boot application. I have a topic exchange "demo.log" defined and a queue bound to it with "#" as the routing key. I don't seem to be getting any messages to RabbitMQ using the logbook-spring.xml file below. Can someone please point out what I'm missing here?

Thanks!

--john

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <include resource="org/springframework/boot/logging/logback/base.xml" />

  <appender name="amqp" class="org.springframework.amqp.rabbit.logback.AmqpAppender">
    <host>localhost</host>
    <port>5672</port>
    <virtualHost>/</virtualHost>
    <username>guest</username>
    <password>guest</password>
    <exchangeType>topic</exchangeType>
    <exchangeName>demo.log</exchangeName>
    <applicationId>demo</applicationId>
    <routingKeyPattern>test</routingKeyPattern>
    <contentType>text/plain</contentType>
    <maxSenderRetries>2</maxSenderRetries>
  </appender> 

  <logger name="com.example" level="DEBUG">
    <appender-ref ref="amqp"/>
  </logger>

</configuration>
1

There are 1 answers

2
Gary Russell On BEST ANSWER

You need a <layout/> and <charset/> (used to convert String to byte[]) ...

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
    <include resource="org/springframework/boot/logging/logback/base.xml" />

    <appender name="amqp"
        class="org.springframework.amqp.rabbit.logback.AmqpAppender">
        <host>localhost</host>
        <port>5672</port>
        <virtualHost>/</virtualHost>
        <username>guest</username>
        <password>guest</password>
        <exchangeType>topic</exchangeType>
        <exchangeName>demo.log</exchangeName>
        <applicationId>demo</applicationId>
        <routingKeyPattern>test</routingKeyPattern>
        <contentType>text/plain</contentType>
        <maxSenderRetries>2</maxSenderRetries>
        <charset>UTF-8</charset>
        <layout>
            <pattern><![CDATA[ %d %p %t [%c] - <%m>%n ]]></pattern>
        </layout>
    </appender>

    <logger name="com.example" level="DEBUG">
        <appender-ref ref="amqp" />
    </logger>

</configuration>

I have opened a JIRA Issue to give some diagnostics when these are missing.

UI Screen Shot