Modifying Log Level When Using SailPointJUnitTestHelper

I have created a rule that will log debug messages just fine when running the rule within IdentityIQ.

However, when I run the rule in Eclipse with the SailPointJUnitTestHelper, I only get error and warn log messages output to the console, the debug log messages are ignored.

How do I change the log level when using SailPointJUnitTestHelper to see my debug log messages within Eclipse?

I came up with a solution that works for me, hopefully someone finds this helpful.

Little background, I am using IdentityIQ 8.2 in a VM. I have tried adjusting the log4j2.properties file and the changes there seem to make no difference when using the SailPointJUnitTestHelper.

I modified the SailPointJUnitTestHelper class in the following ways.

  • Modified both constructors to accept another String parameter and a Level parameter.
    • If you have existing tests in place, you will want to create new constructors to keep your other tests working.
  • Added logic to set up the custom logger.
public SailPointJUnitTestHelper(String username, String password, String customLoggerName, Level customLoggerLevel) throws Exception 
{
	this(username, password, AutoClose.AfterClass, customLoggerName, customLoggerLevel);
}

public SailPointJUnitTestHelper(String username, String password, AutoClose autoClose, String customLoggerName,  Level customLoggerLevel) throws Exception 
{
    //This is the new ADDITIONAL logic I added to this constructor. I did not include 
    //the rest of the constructor logic here to keep things cleaner for this example.
    
    //Set the custom Logger
	Logger customLogger = Logger.getLogger(customLoggerName);
	customLogger.setLevel(customLoggerLevel);
}

In my Beanshell rule script I setup my custom log.

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
  
Log log = LogFactory.getLog("myCustomRuleLogName");

log.error("TEST ERROR");
log.warn("TEST WARN");
log.info("TEST INFO");
log.debug("TEST DEBUG");
log.trace("TEST TRACE");

In Eclipse in my Integration test class.

public MyBeanShellRule_IntegrationTests() throws Exception
{
    super("UserToAuthenticateWith", "UserPassword", AutoClose.AfterTest, "myCustomRuleLogName", Level.DEBUG);
}

With these changes I can now control the log level output from my script within Eclipse. For example, instead of only seeing error and warning log messages output from my script in the Eclipse console. I can now have info, debug, or trace log messages output to the Console from my script, by setting the level in the constructor (using super).