Search code examples
springspring-bootrabbitmqamqpspring-amqp

trouble configuring RabbitMq logback appender


My project demands to send the logs at centralized location(Graylog) server. So i thought of using "AMQP Appender" in logback.xml to send the logs to RabbitMq and then will configure the Graylog server to fetch the logs from RabbitMq.

this is how my logback.xml looks like.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>
                {
                "time": "%date{ISO8601}",
                "thread": "%thread",
                "level": "%level",
                "class": "%logger{36}",
                "message": "%message"
                }
            </pattern>      </encoder>
    </appender>

  <appender name="RabbitMq" class="org.springframework.amqp.rabbit.logback.AmqpAppender">
        <layout>
            <pattern>
                {
                "time": "%date{ISO8601}",
                "thread": "%thread",
                "level": "%level",
                "class": "%logger{36}",
                "message": "%message"
                }
            </pattern>  
        </layout>
        <host>localhost:8080</host>
        <port>5672</port>
        <username>guest</username>
        <password>guest</password>
        <exchangeType>direct</exchangeType>
        <exchangeName>amq.direct</exchangeName>
        <applicationId>RabbitMq-IT-SE</applicationId>
     <routingKeyPattern>%property{applicationId}.%c.%p</routingKeyPattern>
        <generateId>true</generateId>
        <charset>UTF-8</charset>
        <durable>true</durable>
        <abbreviation>36</abbreviation>
        <deliveryMode>NON_PERSISTENT</deliveryMode>
        <declareExchange>true</declareExchange>

    </appender> 



    <logger name="org.springframework.amqp.rabbit.logback" level="INFO" additivity="true">
        <appender-ref ref="RabbitMq"/>
    </logger>

    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="RabbitMq"/>
    </root>

</configuration>

i can see the logs in console and i am expecting them on RabbitMq Server as well. But somehow i am not able to find the logs on RabbitMq Server. I can see the connection established in "Overview" tab but i do not know in which queue i have to look for messages. Am i missing something ?

If i miss to provide some details then please let me know, i will update the post asap.

Thanks.


Solution

  • You are publishing to a direct exchange with a rather complex routing key.

    You would need to bind a queue with each possible routing key (including the app id, logging class name and log severity).

    If you want to use a direct exchange, I would suggest a simple routing key and bind a single queue with that key.

    It would be better to publish to a topic exchange, then you can bind queues with patterns to decide which log entries you want.

    See the rabbitmq tutorials to understand the different exchange types.