0

I'm getting a log from, for example here

org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:260

but when I set (I have a ton for just classes where this works not including subclasses)

    <Logger name="org.hibernate.engine.spi.CascadingActions" additivity="false"/>
    <Logger name="org.hibernate.engine.spi.CascadingActions$6" additivity="false"/>

I still am getting logs from CascadingActions$6, I can't ignore org.hibernate.engine.spi for unobvious reasons.

Is this another unobvious problem? or is there a specific syntax I'm missing for ignoring a subclass with log4j2?

xenoterracide
  • 16,274
  • 24
  • 118
  • 243
  • You should take a look at filters: https://logging.apache.org/log4j/2.x/manual/filters.html – Simon Martinelli Mar 18 '21 at 16:15
  • @SimonMartinelli I tried adding one of those, specifically the RegexFilter but I couldn't quite figure out the regex I needed, and I'm on very limited time as I'm departing this project tomorrow ;) – xenoterracide Mar 18 '21 at 16:16
  • There is no logger with the name org.hibernate.engine.spi.CascadingActions$6 so you cannot use the logger configuration. I must ask the stupid question. Why do you log Hibernate SPI? – Simon Martinelli Mar 18 '21 at 16:19
  • @SimonMartinelli because of this https://stackoverflow.com/a/66681932/206466 – xenoterracide Mar 19 '21 at 00:34
  • Did you read this: https://vladmihalcea.com/the-best-way-to-log-jdbc-statements/ – Simon Martinelli Mar 19 '21 at 07:07
  • @SimonMartinelli yes, or rather it contains the same content at least. Unfortunately those logging statements were for some reason not capturing the parameter to the mentioned spring data query, I can't say why exactly, as it just delegates to hibernate. For the other options, I didn't want to add a 3rd party dependency for what seems like could be answered by the logger. – xenoterracide Mar 19 '21 at 16:46

1 Answers1

1

The answer to this is relatively simple. Looking at the source code for CascadingActions you will see

private static final CoreMessageLogger LOG = Logger.getMessageLogger(
        CoreMessageLogger.class,
        CascadingAction.class.getName()
);

The name of the logger is the second parameter. Notice it is "CascadingAction", not CascadingActions. I can't tell you whether this was intended or a typo.

So neither of your configured Loggers are going to match anything. The subclasses use the parent Class's Logger so that will never match.

The bottom line is that you can't always assume the logger name is the same as the class name. You need to check.

rgoers
  • 8,696
  • 1
  • 22
  • 24