Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Springboot sending logs to fluentd not working

I need some help for the following problem.

I have a spring boot application and I would like to configure a fluentd appender using logback.

I've created a file called logback.xml in my src/main/resources with the following content:

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


    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date - %level - [%thread] - %logger - [%file:%line] - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FLUENT_TEXT" class="ch.qos.logback.more.appenders.DataFluentAppender">
        <tag>dab</tag>
        <label>normal</label>
        <remoteHost>localhost</remoteHost>
        <port>24224</port>
        <maxQueueSize>20</maxQueueSize>
    </appender>

    <logger name="org.com" level="DEBUG"/>


    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FLUENT_TEXT" />
    </root>

</configuration>

In my build.gradle I have :

compile 'org.fluentd:fluent-logger:0.3.1'
compile 'com.sndyuk:logback-more-appenders:1.1.0'

When I launch the app using gradle bootRun I have the following message:

10:56:33,020 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - Attempted to append to non started appender [STDOUT].
10:56:33,020 |-WARN in ch.qos.logback.more.appenders.DataFluentAppender[FLUENT_TEXT] - Attempted to append to non started appender [FLUENT_TEXT].
10:56:33,028 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - Attempted to append to non started appender [STDOUT].
Exception in thread "main" 10:56:33,028 |-WARN in ch.qos.logback.more.appenders.DataFluentAppender[FLUENT_TEXT] - Attempted to append to non started appender [FLUENT_TEXT].
java.lang.NullPointerException
        at ch.qos.logback.more.appenders.DataFluentAppender$FluentDaemonAppender.close(DataFluentAppender.java:72)

I've found here https://github.com/spring-projects/spring-boot/blob/master/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc something saying that logback.xml is loaded too early so I need to use a file called logback-spring.xml.

I've did it and it's like the file is never loaded, no error but nothing gets to my fluetd socket.

Any idea how to solve it ?

Thanks. C.C.

like image 513
CC. Avatar asked Nov 10 '22 04:11

CC.


1 Answers

When running your springboot application, load a 'spring' profile.

One way of doing it would be via the command line, see below.

-Dspring.profiles.active=spring
like image 135
JC Carrillo Avatar answered Nov 15 '22 06:11

JC Carrillo