package gw.rating
uses gw.api.system.PCLoggerCategory
uses gw.plugin.Plugins
uses gw.plugin.rateflow.IRateRoutinePlugin
uses gw.rating.flow.domain.CalcRoutine
uses gw.rating.worksheet.WorksheetLogger
uses gw.rating.worksheet.domain.WorksheetEntryContainer
final class RateRoutineExecutionLoggerUtil {
static final var _rfLogger = PCLoggerCategory.RATEFLOW
private construct() {
}
/**
* Calls plugin to find if worksheets are on or off, and returns an appropriate logger.
*
* @param patternCode policy line pattern code
*
* @return a {@link WorksheetLogger} if worksheets are on for the policy line, a {@link NoOpLogger} else.
*/
@SuppressWarnings("unused")
public static function getLoggerInstanceForLine(patternCode: String): RateRoutineExecutionLogger {
var worksheetsEnabled = Plugins.get(IRateRoutinePlugin).worksheetsEnabledForLine(patternCode)
return worksheetsEnabled ? WorksheetLogger.get() : NoOpLogger.get()
}
/**
* Cause the given code block to be executed with logging.
*
* @param code code corresponding to a rate routine that is to be executed
* @param rateBook the rate book being used
* @param calcRoutine the rate routine
* @param worksheetEnabled true if worksheet logging is enabled, false else
* @param worksheetEntryContainer if worksheets are enabled, this is the root worksheet entry container
* May be omitted if worksheet logging is not enabled
*/
public static function execute(code : block(), rateBook : RateBook, calcRoutine : CalcRoutine, worksheetEnabled : boolean,
worksheetEntryContainer : WorksheetEntryContainer = null) {
var logger = worksheetEnabled ? WorksheetLogger.get(worksheetEntryContainer) : NoOpLogger.get()
logger.begin(rateBook.BookCode, rateBook.BookEdition, calcRoutine.Code, calcRoutine.Version.toString())
code()
logger.end()
logger.clear()
if (worksheetEnabled) {
_rfLogger.debug("Worksheet:\n${worksheetEntryContainer?.worksheetEntriesString()}")
}
}
}