├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── javatechie │ │ └── elk │ │ ├── ElkStackExampleApplication.java │ │ └── User.java └── resources │ ├── application.properties │ └── application.yml └── test └── java └── com └── javatechie └── elk └── ElkStackExampleApplicationTests.java /README.md: -------------------------------------------------------------------------------- 1 | # elk-stack-logging-example 2 | How to perform centralize logging in microservice architecture using ELK Stack 3 | 4 | ###### Download ELK Binary Distrubution 5 | 6 | ###### 1.Elastic Search [Download](https://www.elastic.co/downloads/elasticsearch). 7 | ###### 2.Logstash [Download](https://www.elastic.co/downloads/kibana). 8 | ###### 3.Kibana [Download](https://artifacts.elastic.co/downloads/logstash/logstash-7.6.2.zip). 9 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.6.RELEASE 9 | 10 | 11 | com.javatechie 12 | elk-stack-example 13 | 0.0.1-SNAPSHOT 14 | elk-stack-example 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | true 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | org.junit.vintage 39 | junit-vintage-engine 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/javatechie/elk/ElkStackExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.elk; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | import java.util.stream.Stream; 14 | 15 | @SpringBootApplication 16 | @RestController 17 | public class ElkStackExampleApplication { 18 | 19 | Logger logger=LoggerFactory.getLogger(ElkStackExampleApplication.class); 20 | 21 | @GetMapping("/getUser/{id}") 22 | public User getUserById(@PathVariable int id) { 23 | List users=getUsers(); 24 | User user=users.stream(). 25 | filter(u->u.getId()==id).findAny().orElse(null); 26 | if(user!=null){ 27 | logger.info("user found : {}",user); 28 | return user; 29 | }else{ 30 | try { 31 | throw new Exception(); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | logger.error("User Not Found with ID : {}",id); 35 | } 36 | return new User(); 37 | } 38 | } 39 | 40 | 41 | private List getUsers() { 42 | return Stream.of(new User(1, "John"), 43 | new User(2, "Shyam"), 44 | new User(3, "Rony"), 45 | new User(4, "mak")) 46 | .collect(Collectors.toList()); 47 | } 48 | 49 | public static void main(String[] args) { 50 | SpringApplication.run(ElkStackExampleApplication.class, args); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/javatechie/elk/User.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.elk; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | @ToString 11 | @Data 12 | public class User { 13 | 14 | private int id; 15 | private String name; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: ELK-STACK-EXAMPLE 4 | 5 | server: 6 | port: 9898 7 | 8 | logging: 9 | file: C:/Users/basan/Desktop/logs/elk-stack.log -------------------------------------------------------------------------------- /src/test/java/com/javatechie/elk/ElkStackExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.elk; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ElkStackExampleApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------