This is a very basic example of sending logs from a classic Java application to a local instance of Elasticsearch.
There is only 1 class that writes 3 log lines when it is executed, one line of each (debug, info, error) level. And accordingly to the configuration declared in the logback.xml file, each line loggged to the Console will be inserted into Elasticsearch asynchronously in the java-logs index
It uses internetitem/logback-elasticsearch-appender library and a local Elasticsearch container that you have to start for the test.
Tha configuration that makes
- Java 11
- Elasticsearch 7.13.3
- Start the Elasticsearch container:
docker run -p 9200:9200 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.13.3 - Import this maven project in your favorite IDE
- Run the application from the main class (Program.java)
- Hit http://localhost:9200/java-logs/_search to see the generated documents
This is what the output should look like:
