Java project log written to LOGSTASH-TCP/UDP

Source: Internet
Author: User
Tags logstash

Benefits: The project log is written to Logstash and then sent to Elasticsearch, which makes it easy to view the search log, as well as report analysis.

Logstash is a data acquisition tool, there are a variety of channels, such as files, TCP,UDP, etc., if it is to collect log files, you need to store files on the server, start a Logstash service, not easy to quickly deploy, and the way to adopt tcp/udp relatively simple , you just need to send the data to the Logstash service. Here is the main way to talk about network transmission.

First, both TCP and UDP need to add dependencies in Maven:

<dependency>    <groupId>net.logstash.logback</groupId>    <artifactId> logstash-logback-encoder</artifactid>    <version>4.8</version></dependency>

Here we are using the Logback log framework

Tcp
 <appender name= " tcp_logstash  Span style= "COLOR: #800000" > " class  ="  net.logstash.logback.appender.logstashtcpsocketappender  "  > <destination>192.168 . 10.11 : 2233  </destination> <!--encoder must be configured with a variety of options-- <encoder charset= " utf-8  "  class  = " net.logstash.logback.encoder.logstashencoder   " /> </appender> 

Note: class is using Logstashtcpsocketappender, which supports TCP transport

Udp
    <appender name="udp_logstash"class="  Net.logstash.logback.appender.LogstashSocketAppender">        192.168.  10.113333</port>    </appender>

Note: class is using Logstashsocketappender, which supports UDP transmission

Finally, in <root>, add the appropriate reference to the line, for example:

<root level="warn"> <appender-ref ref="Udp_logstash"/> <appender-ref ref="Console"/> <appender-ref ref="Info"/> <appender-ref ref="warn"/> <appender-ref ref="Error"/> </root>

Here, the configuration in our code is complete, and after the program is started, the corresponding level+ log is sent to Logstash.

Java project log written to LOGSTASH-TCP/UDP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.