-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bhuwanupadhyay/develop
Add logstash-logback-spring-boot-starter
- Loading branch information
Showing
20 changed files
with
563 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
transactional-outbox-pattern-jpa-starter,1.0.0 | ||
drools-engine-starter,1.0.0 | ||
aws-dynamodb-enhanced-client-repository-starter,1.0.0 | ||
logstash-logback-spring-boot-starter,1.0.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Logstash Logback Spring Boot Starter | ||
|
||
Library for Logstash logback for ELK with zero configuration | ||
|
||
## Usage | ||
|
||
### Add dependency in your spring boot project | ||
|
||
- Maven | ||
|
||
```xml | ||
<dependency> | ||
<groupId>io.github.bhuwanupadhyay</groupId> | ||
<artifactId>logstash-logback-spring-boot-starter</artifactId> | ||
<version>[version]</version> | ||
</dependency> | ||
``` | ||
|
||
- Gradle | ||
|
||
``` | ||
implementation 'io.github.bhuwanupadhyay:logstash-logback-spring-boot-starter:[version]' | ||
``` | ||
|
||
### Customize configurations | ||
|
||
Autoconfiguration enable logstash logging automatically, and connected with logstash server url `localhost:5044`. | ||
|
||
In case if you have to change logstash server url, override following properties: | ||
|
||
```yaml | ||
boot: | ||
logstash: | ||
destination: localhost:5044 | ||
``` | ||
By default custom fields are: | ||
```json | ||
{ "appname" : "<spring.application.name>" } | ||
``` | ||
|
||
To disable logstash logging, override following properties: | ||
|
||
```yaml | ||
boot: | ||
logstash: | ||
enabled: false | ||
``` | ||
All configuration properties: | ||
```yaml | ||
boot: | ||
logstash: | ||
destination: localhost:5044 | ||
enabled: true | ||
key-store-location: keystore/trust.pk | ||
key-store-password: 12345 | ||
custom-fields: |- | ||
{"appname":"${spring.application.name}", "env": "${spring.profiles.active}"} | ||
queue-size: 512 | ||
``` | ||
## Demo | ||
[Greeting Service](demo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Getting Started | ||
|
||
### ELK Stack | ||
|
||
Before running your application you should start ELK Stack on your machine. | ||
|
||
The best way to do that is through Docker containers. | ||
|
||
- Create a Docker network to enable communication between containers via container name. | ||
|
||
```shell script | ||
docker network create elk | ||
``` | ||
|
||
- Run elasticsearch docker container. | ||
|
||
```shell script | ||
docker run -d --name elasticsearch --net elk -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.9.2 | ||
``` | ||
|
||
- Create logstash configuration file `logstash.conf`. | ||
|
||
```shell script | ||
cat <<EOF> ~/logstash.conf | ||
input { | ||
tcp { | ||
port => 5044 | ||
codec => json_lines | ||
} | ||
} | ||
output { | ||
elasticsearch { | ||
hosts => ["http://elasticsearch:9200"] | ||
index => "example-%{appname}-%{env}" | ||
} | ||
} | ||
EOF | ||
``` | ||
- Run logstash docker container. | ||
```shell script | ||
docker run -d --name logstash --net elk -p 5044:5044 -v ~/logstash.conf:/usr/share/logstash/pipeline/logstash.conf logstash:7.9.2 | ||
``` | ||
- Run kibana docker container. | ||
```shell script | ||
docker run -d --name kibana --net elk -e "ELASTICSEARCH_URL=http://elasticsearch:9200" -p 5601:5601 kibana:7.9.2 | ||
``` | ||
### Greeting Service | ||
- Run the service and then check url [http://localhost:9200/_cat/indices](http://localhost:9200/_cat/indices) and look your index: | ||
``` | ||
example-greeting-service-dev | ||
``` | ||
- Open kibana dashboard [http://localhost:5601](http://localhost:5601/) and create an index: | ||
``` | ||
example-greeting* | ||
``` | ||
- Run discover and add filter message, then you will see logging: | ||
``` | ||
10 hits | ||
Documents | ||
message | ||
Started DemoApplication in 1.251 seconds (JVM running for 1.714) | ||
Tomcat started on port(s): 8080 (http) with context path '' | ||
Initializing Servlet 'dispatcherServlet' | ||
Initializing Spring DispatcherServlet 'dispatcherServlet' | ||
Completed initialization in 3 ms | ||
Greeting Initialized at 2902820304765 | ||
Greeting Initialized at 2904734799104 | ||
Greeting Initialized at 2905670902001 | ||
Greeting Initialized at 2906859407908 | ||
Greeting Initialized at 2907493282685 | ||
``` | ||
Thank you for reading! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.3.4.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.example</groupId> | ||
<artifactId>demo</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>demo</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.bhuwanupadhyay</groupId> | ||
<artifactId>logstash-logback-spring-boot-starter</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...tash-logback-spring-boot-starter/demo/src/main/java/com/example/demo/DemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.demo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DemoApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DemoApplication.class, args); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
logstash-logback-spring-boot-starter/demo/src/main/java/com/example/demo/Greeting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.demo; | ||
|
||
public class Greeting { | ||
|
||
private String message; | ||
|
||
public Greeting() { | ||
} | ||
|
||
public Greeting(String message) { | ||
this.message = message; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...h-logback-spring-boot-starter/demo/src/main/java/com/example/demo/GreetingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.demo; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class GreetingController { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(GreetingController.class); | ||
|
||
@GetMapping("/greetings") | ||
public ResponseEntity<Greeting> getGreetings() { | ||
long currentTime = System.nanoTime(); | ||
LOG.info("Greeting Initialized at {}", currentTime); | ||
if (currentTime % 2 == 0) { | ||
return ResponseEntity.ok(new Greeting("Good Morning!")); | ||
} else { | ||
return ResponseEntity.ok(new Greeting("Good Afternoon!")); | ||
} | ||
} | ||
} | ||
|
||
|
11 changes: 11 additions & 0 deletions
11
logstash-logback-spring-boot-starter/demo/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
spring: | ||
application: | ||
name: greeting-service | ||
profiles: | ||
active: dev | ||
boot: | ||
logstash: | ||
destination: localhost:5044 | ||
custom-fields: |- | ||
{"appname":"${spring.application.name}", "env": "${spring.profiles.active}"} | ||
queue-size: 512 |
13 changes: 13 additions & 0 deletions
13
...logback-spring-boot-starter/demo/src/test/java/com/example/demo/DemoApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.demo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class DemoApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.bhuwanupadhyay</groupId> | ||
<artifactId>spring-boot-artifacts-parent</artifactId> | ||
<version>0.0.2</version> | ||
</parent> | ||
|
||
<artifactId>logstash-logback-spring-boot-starter</artifactId> | ||
<version>1.0.4</version> | ||
<name>Logstash Logback Spring Boot Starter</name> | ||
<description>Library for Logstash logback for ELK with zero configuration</description> | ||
|
||
<properties> | ||
<logstash-logback-encoder.version>6.4</logstash-logback-encoder.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.logstash.logback</groupId> | ||
<artifactId>logstash-logback-encoder</artifactId> | ||
<version>${logstash-logback-encoder.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
Oops, something went wrong.