I'd like change log level from error
to warn
for one specific combination of message and logger.
I have tried to filter out these cases and log it again with the new (warn
) level. Filtering out worked, however the new log did not appear in the console no matter in which part of the code the logger was instantiated and called.
class CustomFilter : Filter<ILoggingEvent>() {
val logger: Logger = LoggerFactory.getLogger(SqlExceptionHelper::class.java)
override fun decide(event: ILoggingEvent): FilterReply {
val messageMatches = event.message.contains("my message part")
val loggerMatches = event.loggerName == SqlExceptionHelper::class.java.name
val levelMatches = event.level == Level.ERROR
return if (messageMatches && loggerMatches && levelMatches) {
FilterReply.DENY.also { logger.warn(event.message) }
} else {
FilterReply.NEUTRAL
}
}
}
I have tried also Turbofilter
in a similar way as here. I was able to see the new log in this case, but all the aruments of decide
except logger and level were null
, so I didn't manage to filter the log to be replaced according to the message.
I'm using Logback 1.2.11