DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • What ChatGPT Needs Is Context
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Never Use Credentials in a CI/CD Pipeline Again
  • An Overview of Kubernetes Security Projects at KubeCon Europe 2023

Trending

  • What ChatGPT Needs Is Context
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Never Use Credentials in a CI/CD Pipeline Again
  • An Overview of Kubernetes Security Projects at KubeCon Europe 2023
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Boot Database Project Configuration for Logging Using AOP

Spring Boot Database Project Configuration for Logging Using AOP

In this article, see how to set up an asynchronous framework in a Spring Boot project for logging.

Gabriel Campbell user avatar by
Gabriel Campbell
·
Nov. 22, 19 · Tutorial
Like (3)
Save
Tweet
Share
15.58K Views

Join the DZone community and get the full member experience.

Join For Free

Grayscale photo of a laptop with code on screen

Spring Boot Database Project for Logging Using AOP

In this article, I would like to show you how to set up an asynchronous framework in a Spring Boot project for logging. This is intended to be the first part of a series of three. The next article will involve configuring the application for analytics.

Why log asynchronously? The advantage is that logging is treated as a cross-cutting concern. This means that logging should never be entangled in the main application logic.

Also, when does logging become analytics? What is the correlation between logging and application analytics? We have debug logging to debug applications when finding the source of bugs. However, Info level logging can add value to analytics. Hence it can be seen that there is an overlap in logging and analytics. Machine learning could also ingest this data to analyze when failures occur as well as performance.

For an introduction to Spring AOP and the logging code that is referenced in this article, please see https://www.baeldung.com/spring-aop-annotation.

First, we set up our logging by creating a separate package for logging:

Screenshot of creation of package for logging

Creation of a separate package for logging

We have added the LoggingAOP class and the annotation interfaces LogExecutionTime and LogExecutioonDetails. These two interfaces will give you the execution time that a method takes and the method signature respectively.

In the MutlipleDatabaseController, add the annotation to methods, for example, when saving a new person:

Screenshot of MultipleDatabaseController screen

MultipleDatabaseController

When the application is run and we make a call we have:

[nio-8080-exec-1] com.gabriel.logging.LoggingAOP : Signature=Person com.gabriel.multipledatabaseconnection.controller.MultipleDatabaseController.savePerson(Person): Args= [Ljava.lang.Object;@518639d8: Executed in 100ms


Please note that the AOP is done in a clean manner without too much configuration in the POM. For example, I don't specify compile time or load weaving explicitly. I let Spring determine everything. Spring also picks the optimal AOP framework. This reduces the startup time of the application and leaves a cleaner POM with less configuration. Less is always better!

The source code for this article is under the logging branch in gabriel-multipledatabases.

Further Reading



Spring Framework Spring Boot Database application

Published at DZone with permission of Gabriel Campbell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • What ChatGPT Needs Is Context
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Never Use Credentials in a CI/CD Pipeline Again
  • An Overview of Kubernetes Security Projects at KubeCon Europe 2023

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: