Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Log4j2, how to avoid logging messages that contain a certain text?

Tags:

logging

log4j2

How can I filter out Log4j2 messages according to their message content?

For example, I don't want to log Hibernate messages that contain the text: HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead. Of course, I can disable all Hibernate deprecation warnings, like this:

<Logger name="org.hibernate.orm.deprecation" additivity="false" level="ERROR">
    …
</Logger>

But then I will get no deprecation warnings at all, and they are usually useful. I want to remove just that one (because there is nothing I can do to fix it, and they are issued by the thousands). Please note this is a Log4j2 question, not a Hibernate question.

like image 659
MarcG Avatar asked Sep 18 '25 23:09

MarcG


1 Answers

Oops, it seems I answered myself, I don't know how I missed this RegexFilter :

<Logger name="org.hibernate.orm.deprecation" additivity="false" level="WARN">
    <RegexFilter regex=".*HHH90000022.*" onMatch="DENY" onMismatch="NEUTRAL"/>
    …
</Logger>
like image 74
MarcG Avatar answered Sep 23 '25 05:09

MarcG