Replies: 3 comments 1 reply
-
One of the possible solutions to retrieve a database client from Spring Boot is:
|
Beta Was this translation helpful? Give feedback.
-
I would not implement such a sophisticated configuration mechanism, because:
|
Beta Was this translation helpful? Give feedback.
-
Firstly, I don't think that writing logs into database synchronously and fully is valid requirement and design. If writing key logs into database for key logic and key business, there's no Spring database client issues, just use MDC or NDC of Log4j to do it. |
Beta Was this translation helpful? Give feedback.
-
Spring Boot supports automatic connection establishment with many databases (see Data).
It might be tempting to reuse those connections to forward logs directly to a database. Alas, a couple of problems appear:
Database connections appear very late in an application's lifecycle, while the logging subsystem is required basically from the start. Currently Spring:
log4j2.xml
that does not contain any${spring:...}
lookups (since the Spring configuration is not available yet).Environment
becomes available, Spring reconfigures Log4j Core, based on itslogging.*
properties.ApplicationContext
is refreshed.Database clients also support logging. Such log events can not be delivered to the database, since they would cause recursive logging.
What do you think is the best approach to log events through Spring Boot's managed database clients?
Is it even advisable to use the same database client for logging and business?
Some pros and cons I collected:
Connection
in the JDBC appender #1916). I might be an advantage to attach it to Spring Boot's connection pool instead of handling multiple pools.Beta Was this translation helpful? Give feedback.
All reactions