Disable Hibernate SQL Logging for a Specific Class

Is there a way to disable SQL statement logging for a specific class?

I turned on SQL logging by specifying log4j logger, which is generally good. Unfortunately, I have one class that is called very often and produces a lot of console output. I would like to disable logging for only one class. Is it possible?

+4
source share
2 answers

Although you can determine at what level each class is logged in log4j 1, for example:

<!-- Suppress success logging from InteractiveAuthenticationSuccessEvent --> <logger name="org.springframework.security"> <level value="ERROR"/> </logger> 

Unable to fine tune it.

To get more precise control over logging, you need to update log4j 2.

In Log4j 2 you can use filters:

http://logging.apache.org/log4j/2.x/manual/filters.html

here is a fragment of the configuration using a regular expression filter:

 <?xml version="1.0" encoding="UTF-8"?> <configuration status="warn" name="MyApp" packages=""> <appenders> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{MM-dd-yyyy}.log.gz"> <RegexFilter regex=".* test .*" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout> <pattern>%d %p %C{1.} [%t] %m%n</pattern> </PatternLayout> <TimeBasedTriggeringPolicy /> </RollingFile> </appenders> <loggers> <root level="error"> <appender-ref ref="RollingFile"/> </root> </loggers> </configuration> 
0
source

No, what you ask for is impossible. What if you do not want to log for a specific class (mapped to a table), but this table is joined to another table. Do you want the log to display information if the table is part of a join?

0
source

Source: https://habr.com/ru/post/1446415/


All Articles