3

My program has an underlaying system that persist every log in elasticsearch. I have a class that fetches data online and logs it with slf4j log.error(data). This allow the underlaying system to persist the log in elasticsearch, but it also floods the console with every fetched data.

I wish to disable the consoleAppender just for this specific class.

I've seen other post where people would disable the consoleAppender with logback or would exclude all logging from a specific class, but I couldn't find any information on how to disable one logger in one class.

Is this possible?

Purfakt
  • 101
  • 1
  • 16

1 Answers1

9

It sounds like you just need to set the logging level for that class. Set it to ERROR, WARN or another level, depending on the level of the messages that are flooding the console. Try modifying the application.properties file by adding something like:

logging.level.com.test.MyClass=WARN
Ryan Stuetzer
  • 392
  • 1
  • 4
  • 1
    It indeed works. Now it seems like I miss something about the logging system in SpringBoot. How is it that when I set `logging.level.com.test.MyClass="OFF"`, the custom logger I register programmatically still catches the log events? Shouldn't this config deactivate *all* logging for `MyClass`? – Purfakt Sep 19 '18 at 08:25
  • 2
    You don't need quotes around OFF – Ryan Stuetzer Sep 20 '18 at 13:20