During troubleshooting, changing a log level when needed can be cumbersome. Developers often have to access the server’s filesystem, which isn’t always possible, modify the configuration file, and then reload the logger settings. This process can be time-consuming and disruptive. Fortunately, there is a more efficient way to change log levels directly within the Beanshell code at runtime. This method requires no restarts, reloads, or system access. In this post, I will demonstrate how to achieve this seamless log level adjustment, making troubleshooting in IdentityIQ much more straightforward.
With this simple rule it is possible to set log level of any logger
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule language="beanshell" name="Runtime Log Levels Change" type="RequestObjectSelector">
<Source>
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.Level;
import sailpoint.server.InternalContext;
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Logger log = ctx.getLogger("sailpoint.server.InternalContext");
log.setLevel(Level.FATAL);
log.info("Info Log Message");
log.debug("Debug Log Message");
log.error("Error Log Message");
log.fatal("Fatal Log Message");
</Source>
</Rule>
Here is sample output of InternalContext
logger in different log levels