class ResourceConsumptionLog {

    static String doLog(ResourceConsumptionEvents.ResourceConsumptionEvent event) {
        if (event instanceof CapacityGroupAllocationEvent) {
            CapacityGroupAllocationEvent changeEvent = (CapacityGroupAllocationEvent) event;
            CompositeResourceConsumption consumption = changeEvent.getCapacityGroupConsumption();

            StringBuilder sb = new StringBuilder("Resource consumption change: group=");
            sb.append(consumption.getConsumerName());

            if (consumption.isAboveLimit()) {
                sb.append(" [above limit] ");
            } else {
                sb.append(" [below limit] ");
            }

            sb.append("actual=");
            ResourceDimensions.format(consumption.getCurrentConsumption(), sb);
            sb.append(", max=");
            ResourceDimensions.format(consumption.getMaxConsumption(), sb);
            sb.append(", limit=");
            ResourceDimensions.format(consumption.getAllowedConsumption(), sb);

            if (consumption.getAttributes().isEmpty()) {
                sb.append(", attrs={}");
            } else {
                sb.append(", attrs={");
                consumption.getAttributes().forEach((k, v) -> sb.append(k).append('=').append(v).append(','));
                sb.setCharAt(sb.length() - 1, '}');
            }

            String message = sb.toString();
            if (consumption.isAboveLimit()) {
                logger.warn(message);
            } else {
                logger.info(message);
            }
            return message;
        }

        if (event instanceof CapacityGroupUndefinedEvent) {
            String message = "Capacity group not defined: group=" + event.getCapacityGroup();
            logger.warn(message);
            return message;
        }

        if (event instanceof CapacityGroupRemovedEvent) {
            String message = "Capacity group no longer defined: group=" + event.getCapacityGroup();
            logger.info(message);
            return message;
        }

        String message = "Unrecognized resource consumption event type " + event.getClass();
        logger.error(message);
        return message;
    }

    @Inject public  ResourceConsumptionLog(ResourceConsumptionService resourceConsumptionService);

}