0

How can I disable logging of Spring Batch SQL queries?

They are logged from org.springframework.jdbc.core.JdbcTemplate logger because of:

logging.level:
  org.springframework.jdbc: TRACE

and look like:

2017-05-27 20:41:55.957 DEBUG 13088 --- [jobLauncherTaskExecutor-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2017-05-27 20:41:55.957 DEBUG 13088 --- [jobLauncherTaskExecutor-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_JOB_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE JOB_EXECUTION_ID = ?]
2017-05-27 20:41:55.958 DEBUG 13088 --- [jobLauncherTaskExecutor-1] o.s.jdbc.core.JdbcTemplate               : SQL update affected 1 rows

With such enormous amount of these messages I can't see my application messages (that have matter).

The problem is that by disabling this logger my application SQL queries will also be disabled.

gavenkoa
  • 45,285
  • 19
  • 251
  • 303

1 Answers1

1

You have not specified what logging framework you use.

I have managed this in my Spring Batch application using logback.

I define a separate logger for my application and rest is default logger then I can separately set logging levels for both different loggers.

Please refer my slideshare presentation to get some ideas about defining named loggers in logback.

To address,

With such enormous amount of these messages I can't see my application messages

I guess, whatever logging framework you use, the idea basic is to define a separate logger for your application needs and directing rest to a default logger then setting levels separately i.e. logging at package level wouldn't help here.

The other solution like the one mentioned in accepted answer here will disable logs for your queries too.

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
  • My app also uses `JdbcTemplate` and I like to see those SQL queries. But in addition I see enormous number of Spring Batch SQL queries... I afraid that only syntax parsing of msg content allows to get rid of those messages... – gavenkoa May 28 '17 at 12:55
  • Regarding your presentation. This approach too radical and efforts can be spent on adding support of MDC to application. In that case you would have logical markers (in MCD, that is what you originally tried to achieve) and system structure (logger names, which is useful for filtering). https://logback.qos.ch/manual/mdc.html – gavenkoa May 30 '17 at 10:29
  • I think, I misunderstood your question and my answer doesn't address your issue. Did you solved your problem? – Sabir Khan May 31 '17 at 04:01
  • I checked source of JdbcTemplate and it looks impossible (( Extremely unkind by Batch Framework to pollute application log without possibility to filter out its DB activity. – gavenkoa May 31 '17 at 07:16