orpqK
orpqK

Reputation: 2785

Is it possible to send logs to Logstash

In my Spring Boot app, I am using Logback to write logs to a file in /tmp/myLog.log.

In my app.yml:

logging:
  file: /tmp/myLog.log

My logback.xml:

<configuration>
    <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
    <property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%t] --- %-40.40logger{39} : %m%n"/>

    <appender name="FILE"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <pattern>${FILE_LOG_PATTERN}</pattern>
        </encoder>
        <file>${LOG_FILE}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${LOG_FILE}.%i</fileNamePattern>
        </rollingPolicy>
        <triggeringPolicy
                class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="FILE" />
    </root>

</configuration>

Then I tell Logstash to look at this log file, in my conf file:

input {
  file {
    path => "/tmp/myLog.log"
    start_position => "beginning"
  }
}
output {
  elasticsearch { hosts => ["localhost:9200"] }
  stdout { codec => json }
} 

Now It is looking at this location at myLog.log. Is there a way to send logs to logstash instead of telling it to looking at a location, in my Spring Boot app?

Upvotes: 0

Views: 5189

Answers (1)

daniel.eichten
daniel.eichten

Reputation: 2555

I was successfully playing around with the Logback-Elasticsearch-Appender. You might want to give it a try.

Upvotes: 3

Related Questions