Configure Log4j 2 to store logging information in database table using Hibernate

I would like to configure log4j2 to store log information in a database table.

I know it works using java,sql,Connection, but I’d like to map the table exactly as I map the other table in order to take advantages of Hibernate first and second level cache.

This is the working code BUT the connection is just a “trick”

<JDBC name="PostgreSQLDatabase" tableName="plugin_luminare3.app_logs">
		class="luminare.MainTest" method="getPGConnection" />
	<Column name="LOG_ID" pattern="%u" />
	<Column name="ENTRY_DATE" isEventTimestamp="true" />
	<Column name="LOG_LEVEL" pattern="%level" />
	<Column name="MESSAGE" pattern="%m" />

Thanks in advance

Hibernate is useful for data that gets updated. Logs are append-only, so just use a native SQL to fetch the log entries.

What advantage would Hibernate bring if you mapped that table? Second-level caching is also useful to reduce load on Primary nodes, as scaling reads is easy as you can just use database replication to span more nodes.

Hello Vlad, thank you for the answer; I’ll use native java.sql Connection to manage this stuff.