This is an interesting question which also introduces new questions.
You could have a list of words which could either escalate or de-escalate the log level for that message.
One approach to this, would be to make your own logger class, which encapsulates your general logging framework, mirroring each of the log methods.
The first version for establishment would be simply calling the logging framework behind ie.
public class MyLogger {
public void info(String message) { Logger.info(message); }
public void debug(String message) { Logger.debug(message); }
// And so on
}
Say you have a wordlist you could introduce some words to trigger another level, if contained in message.
public class MyLogger {
private final List<String> warnTriggerMessages;
public MyLogger(List<String> warnTrigerMessages) {
this.warnTriggerMessages = warnTrigerMessages;
}
public void info(String message) {
if (warnTriggerMessages.stream().anyMatch(trigger => message.contains(trigger))) {
Logger.warn(message);
} else {
Logger.info(message);
}
}
// And so on
}
This was just a very simple example, but could be expanded with a more generic approach or intertwined with a strategyPattern, which would resolve the logging method based on a "proposed" log level and the message, where the message could cause the strategy to choos another log level than the proposed loglevel.