2

Given third party library whose source code I cannot change:

package thirdpartylibrary;
class ThirdPartyClass {
    void thirdPartyMethod() {
        log.error("Something happened");
    }
}

In the log file I would like to see:

INFO Something happened

instead of:

ERROR Something happened

How to change log level for thirdpartylibrary.ThirdPartyClass via logback.xml or similar configuration?

I am aware that I could turn off logging via:

<logger name="thirdpartylibrary.ThirdPartyClass" level="OFF"/>

But then I would not know that Something happened at all.

Reason why I would like to achieve it is that I would like to take log levels seriously as described here: https://stackoverflow.com/a/8021604/2866645

I.e. ERROR level should mean that our operations team should be woken up at 2AM.

I would like to eliminate false positives.

Thanks for your feedback!

ondrej.lerch
  • 128
  • 5
  • Indeed org.springframework.boot.logging.logback.LevelRemappingAppender looks exactly as what I was looking for. Unfortunatelly, it is no longer available in Spring Boot 2.0, see https://stackoverflow.com/questions/50407297/replacement-for-logback-levelremappingappender-in-spring-boot-2. So I wonder if there is elegant way that would work with Logback 1.2 & Spring Boot 2.0. Thanks! – ondrej.lerch Sep 13 '18 at 12:34
  • 1
    I guess you could just add the original code in your own project? See https://github.com/spring-projects/spring-boot/commit/e92e56dda5d4ed35479b0797bbdd486551665663#diff-8c36970abc3c64173beb3a6f9f4a9375 – Wim Deblauwe Sep 13 '18 at 13:36

1 Answers1

-1

One way is that you override the log.error method of your logging library and get the class/package name of the class trying to log the message via the level ERROR. if the package/class is one of your third party you can change the level of the log message.

it should be something like this

if(object.className == thirdParty)
{
 log.info(message);
}
Saram Ali Azhar
  • 234
  • 1
  • 18