Question

I'm using Log4j 2 in my project to write son logs to a database table. These events are identified based on certain MDC key/value pair. My concern is about the unchecked LoggingException this appender can throw from its append method. These database logs are generated inside asynchronous, transactional process and I don't want the main process gets affected by a potential exception raised by the appender. How should I take care of it? Should I move the configuration based appender to a custom appender? Is there any guarantee that the appender won't rollback my business process in case of log event append error?

thks in advance

Was it helpful?

Solution

Assuming you are using JDBCAppender, I depends on two things:

  • Are you sharing the database connection of your application with log4j? By default, you are not. In fact, you would have to try very hard to accomplish this. So, failures on the logging connection will not impact transactions on the business DB connection.
  • If you are sharing a JDBC connection, then it depends on the autoCommit setting of that connection. If autoCommit is true, logging errors will not affect business transactions even on the same connection.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top