Generating logging information in Gosu rules
To trigger the flow of information from a Gosu rule to a log file, you
need to configure the following:
- The appender definition
(
<RollingFile>) for the rule log file in log4j2.xml. - The logger definition (
<Logger>) associated with the rule file in log4j2.xml. - The activation trigger for the logging category in a Gosu rule using gw.api.system.PCLoggingCategory.
Logging category definitions
A logging category defines how the Apache log4j logging utility handles different types of logging requests. In the base configuration, Guidewire provides a number of readily usable logging categories.
To define how PolicyCenter interacts with
the ASSIGNMENT category, add something similar to the following code
in file
log4j2.xml.
<!-- Rolling file definition... -->
<RollingFile name= "RuleEngineLog" fileName="${guidewire.logDirectory}/ruleengine.log"
filePattern="${guidewire.logDirectory}/ruleengine.log%d{.yyyy-MM-dd}">
<PatternLayout pattern="${file.defaultPattern}" charset="UTF-8"/>
<TimeBasedTriggeringPolicy/>
</RollingFile>
<!-- Logger definition... -->
<Logger name="Assignment" additivity="false" level= "info">
<AppenderRef ref="RuleEngineLog">
</Logger>Notice that this code does the following:
- It defines a rolling log file named
ruleengine.log in the
<RollingFile>element. - It then links the ruleengine.log
file to the
Assignmentlogger category in the<Logger>element. - It sets a default logging level of INFO.
Base configuration logging categories
There are several ways to view the base configuration logging
categories:
- From the Set Log Level Server Tools screen.
- By running the system_tools command from a command prompt and adding the -loggercats option.
Triggering a logging category from a Gosu rule
For example, to use this API in Gosu code to perform assignment
logging, do something similar to the
following:
uses gw.api.system.PCLoggerCategory
...
var logger = PCLoggerCategory.ASSIGNMENT
...
logger.info("Print out this message.")Logging example
The following code is an example of the use of a logging category in a Gosu rule. This code assumes that the necessary appender and logger definitions exist in file log4j2.xml.
var logger=gw.api.system.PCLoggerCategory.ContextualLogger
// If there is an address, assign by location using that address
if (addr != null) {
if ( policy.CurrentRoleAssignment.assignGroupByLocation("branch", addr, false,
assignment.CurrentAssignment.AssignedGroup) ) {
// Then attempt to assign to the proper group within this branch
if ( policy.CurrentRoleAssignment.assignGroupByRoundRobin("branchuw", true,
assignment.CurrentAssignment.AssignedGroup) ) {
logger.debug("##### This is the Global Pre-renewal Assignment rule " + actions.getRule().DisplayName)
logger.debug("Assigned Group is " + policy.CurrentRoleAssignment.AssignedGroup.DisplayName)
actions.exit()
}
}
}
See also
