# Logging in connector rule code

**URL:** <https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612>\
**Category:** SHF Discussion and Questions\
**Tags:** connectors, provisioning, jdbc-connector, identity-security-cloud\
**Created:** [February 2, 2024, 7:19pm UTC](https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612 "2024-02-02T19:19:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikramsah](https://avatars.discourse-cdn.com/v4/letter/v/a88e4f/32.png) [@vikramsah](https://developer.sailpoint.com/discuss/u/vikramsah)\
**Post date:** [February 2, 2024, 7:19pm UTC](https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612/1 "2024-02-02T19:19:53Z")

</div>

I am writing my first connector rule and want to log/print some variables like AccountRequest , ProvisioningPlan.AttributeRequest etc., to see how the object looks like. What is the best way to do this?

---

<div class="post-metadata">

**Author:** ![jsosa](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jsosa/32/31578_2.png) [@jsosa](https://developer.sailpoint.com/discuss/u/jsosa)\
**Post date:** [February 4, 2024, 7:09pm UTC](https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612/2 "2024-02-04T19:09:01Z")

</div>

Hi @vikramsah ! First you will need to enable your logger, you can follow

> **[CCG Enable Debug Log by Connector](https://community.sailpoint.com/t5/Connector-Directory/CCG-Enable-Debug-Log-by-Connector/ta-p/169807)**
>
> IMPORTANT:  The method of configuring logging levels per connector that is described in this document has been been updated. Logging functionality is now configurable by API. For more information, refer to the Enabling Connector Logging in...

then, just use log.info, .debug, .error, .warn, etc.

As AccountRequest, ProvisioningPlan.AttributeRequest, etc are objects, you will get the string serialization, but you can go printing objects attributes. I let you an example of some recent JDBC Provision rule I have developed these days, I always prints all, not only to see how the object look like, but is very good to debug (having ccg.log opened):

```auto
List accounts = plan.getAccountRequests();
if ((accounts != null) && (accounts.size() > 0)) {
	Iterator accountsIterator = accounts.iterator();

	while (accountsIterator.hasNext()) {
		AccountRequest account = (AccountRequest) accountsIterator.next();
		if (account == null) {
			log.warn("account returned is null - should never get here");
			result.setStatus(ProvisioningResult.STATUS_FAILED);
			return result;
		}
		log.warn("#################### plan is " + account.getOperation());

		log.warn(
				"before plan operations, getting all account attribute values ");
		Map accountAttributes = new HashMap();
		List attributesRequestList = account.getAttributeRequests();
		Iterator attributesRequesIterator = attributesRequestList.iterator();
		while (attributesRequesIterator.hasNext()) {
			AttributeRequest attributeRequest = (AttributeRequest) attributesRequesIterator.next();
			log.warn("attribute##" + attributeRequest.getName() + "##" + attributeRequest.getValue()
					+ "##" + attributeRequest.getDisplayValue());
			accountAttributes.put(attributeRequest.getName(), attributeRequest.getValue());
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![jrossicare](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@jrossicare](https://developer.sailpoint.com/discuss/u/jrossicare)\
**Post date:** [February 5, 2024, 2:02am UTC](https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612/3 "2024-02-05T02:02:02Z")

</div>

Hi Vikram

Here is some of the stuff I log - can be quite handy. I set a ‘logPrefix’ so it is easier to grep in CCG log. I also log as Error, so I dont have to keep playing with CCG Log levels

```auto
    String logPrefix = "Blah WSBO - ";
    try {
       if (provisioningPlan != null) {
           log.error(logPrefix + "Prov plan is not null");
           //This part is just info dump:
           for (int i = 0 ; i < this.variables.length ; i++) {
              String varName = this.variables[i];
              Object varValue = null;
              try {
                 if ("transient".equals(varName))
                    varValue = "[reserved word]";
                 else
                    varValue = eval(varName);
              } catch (Exception ex) {
                 varValue = "[eval exception]";
              }
              String varClass = "void";
              if ((void != varValue) && (null != varValue))
                 varClass = varValue.getClass().getSimpleName();

              if (void == varValue)
                  log.error(logPrefix + "x " + varName + " is void");
              else if (null == varValue)
                  log.error(logPrefix + "x " + varName + " is null");
              else
                  log.error(logPrefix + "x " + varName + " (" + varClass + ") = " + varValue);
           }
           log.error(logPrefix + "Full URL = " + requestEndPoint.getFullUrl());
           log.error(logPrefix + "Context URL = " + requestEndPoint.getContextUrl());
           log.error(logPrefix + "HTTP Method = " + requestEndPoint.getHttpMethodType());
           log.error(logPrefix + "OperationType = " + requestEndPoint.getOperationType());
           log.error(logPrefix + "App ID = " + application.getId() );

           for (AccountRequest accReq : Util.iterate(provisioningPlan.getAccountRequests())) {
               log.error(logPrefix + "AccountRequest Operation: " + accReq.getOperation().toString() );
               for (ProvisioningPlan.AttributeRequest attReq : Util.iterate(accReq.getAttributeRequests())) {
                   log.error(logPrefix + "attReq: " + attReq.getName() + " => " + attReq.getValue() + " (" + attReq.getValue().getClass() + ")");
               }

...
           }
       } else {
           log.error(logPrefix + "Rule - Modify Body: plan is null");
       }
    } catch (Exception ex) {
        log.error(logPrefix + "Exception: " + ex);
    }

```

---

<div class="post-metadata">

**Author:** ![vikramsah](https://avatars.discourse-cdn.com/v4/letter/v/a88e4f/32.png) [@vikramsah](https://developer.sailpoint.com/discuss/u/vikramsah)\
**Post date:** [February 5, 2024, 9:54pm UTC](https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612/5 "2024-02-05T21:54:28Z")

</div>

Thanks Julian, This was helpful.

---

<div class="post-metadata">

**Author:** ![StephenHolinaty](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/stephenholinaty/32/29996_2.png) [@StephenHolinaty](https://developer.sailpoint.com/discuss/u/StephenHolinaty)\
**Post date:** [February 5, 2024, 10:16pm UTC](https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612/6 "2024-02-05T22:16:03Z")

</div>

I agree with a lot of this.

- do not declare your own logger, use log.{level}(“string”)

setting a specific prefix is also amazingly helpful for Grepping logs.

log.info(“WSAO: SourceName: Operation - {log goes here}”) means that i can:  
`tail -f ~/log/ccg.log | grep "WSAO: SourceName"`  
and see all of the relevant details.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [April 5, 2024, 10:16pm UTC](https://developer.sailpoint.com/discuss/t/logging-in-connector-rule-code/28612/7 "2024-04-05T22:16:58Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
