Skip to content

little-pinecone/spring-boot-log4j-2-scaffolding

Repository files navigation

spring-boot-log4j-2-scaffolding

keep growing logo

This project is a simple scaffolding for a Spring Boot application that uses Log4j 2 for logging and Elastic Stack for processing log entries.

To learn how to set up a project like this one, check out the following posts:

Getting Started

To clone the repository, run in the command line:

$ git clone https://github.com/little-pinecone/spring-boot-log4j-2-scaffolding.git

You can build the application with:

$ mvn clean install

Spring security

The application uses Spring Boot security starter. The default credentials are specified in the application.properties file:

  • Useranme test
  • Password test

Monitoring Spring Boot with Actuator

After starting the Spring Boot app, you have to sign in:

login form

Now you can browse the enabled and exposed Actuator endpoints: info, health, metrics.

Run the Spring Boot app, Elastic Stack, Prometheus and Grafana

  • Run this application to make sure that the all.log file is created and not empty (more than one line is required).
  • Run the $ docker-compose up -d command in the project directory. The following services should be started:
IMAGE                                     PORTS                                            NAMES
elasticsearch:7.7.0                  0.0.0.0:9200->9200/tcp, 9300/tcp                 springbootelasticstack_elasticsearch_1
logstash:7.7.0                       0.0.0.0:5044->5044/tcp, 0.0.0.0:9600->9600/tcp   springbootelasticstack_logstash_1
kibana:7.7.0                         0.0.0.0:5601->5601/tcp                           springbootelasticstack_kibana_1
springbootelasticstack_filebeat                                                       springbootelasticstack_filebeat_1
springbootelasticstack_metricbeat                                                     springbootelasticstack_metricbeat_1
elastichq/elasticsearch-hq:latest    0.0.0.0:5000->5000/tcp                           springbootelasticstack_elastichq_1
prom/prometheus                      0.0.0.0:9090->9090/tcp                           springbootelasticstack_prometheus_1
grafana/grafana:7.1.3                0.0.0.0:3000->3000/tcp                           springbootelasticstack_grafana_1
springbootelasticstack_app           0.0.0.0:8080->8080/tcp                           springbootelasticstack_app_1
  • Visit http://localhost:5000/#!/ to use ElastiHQ interface to verify the content send to Elasticsearch (run Query for the spring-boot-app-logs-YYYY.MM.dd index):

elastichq-screenshot

  • Visit http://localhost:5601/ to log in to Kibana:

kibana-login-screenshot

  • Use the default username: elastic and password: test.
  • Create index defined in the logstash.conf file and browse logs accumulated in the logs/all.log file (the file is automatically created on the application startup):

kibana-discover-screenshot

  • Visit http://localhost:5601/app/monitoring to check out clusters monitoring:

stack-monitoring-screenshot

Standalone cluster shows metrics for Filebeat, docker-cluster displays metrics for Elasticsearch, Kibana and Logstash:

docker-cluster-screenshot

You can also monitor the application state using Grafana:

grafana-dashboard-screenshot

Overview and technical features

  • Log4j 2 is used for logs processing.
  • The application uses the root logger and sends log entries to RollingFile and Console appenders (when you run the app, the logs directory will be created automatically).
  • After log entries had been processed by Filebeat and Logstash, they are send to ElasticSearch.
  • You can browse logs in Kibana.
  • You can browse Elastic Stack metrics in a Kibana dashboard.
  • You can monitor the Spring Boot app using Actuator endpoints.
  • You can monitor the Spring Boot app using the Prometheus or Grafana dashboards.
  • Project documentation

Built With

License

This project is licensed under the Unlicense - see the license details.

About

Demo project for a Spring Boot using Log4j2 and Elastic Stack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published