use of org.apache.logging.log4j.message.FormattedMessage in project logging-log4j2 by apache.
the class LoggerSupplierTest method flowTracing_SupplierOfFormattedMessage.
@Test
public void flowTracing_SupplierOfFormattedMessage() {
logger.traceEntry(() -> new FormattedMessage("int foo={}", 1234567890));
assertThat(results).hasSize(1);
String entry = results.get(0);
assertThat(entry).startsWith("ENTER[ FLOW ] TRACE Enter").contains("(int foo=1234567890)").doesNotContain("FormattedMessage");
}
use of org.apache.logging.log4j.message.FormattedMessage in project GregTech by GregTechCE.
the class CoverFluidRegulator method doKeepExact.
/**
* Performs one tick worth of Keep Exact behavior.
* @param transferLimit the maximum amount in milliBuckets that may be transferred in one tick
* @param sourceHandler source(s) to move fluids from
* @param destHandler destination(s) to move fluids to
* @param fluidFilter a predicate which determines what fluids may be moved
* @param keepAmount the desired amount in milliBuckets of a particular fluid in the destination
* @return the total amount in milliBuckets of all fluids transferred from source to dest by this method
*/
protected int doKeepExact(final int transferLimit, final IFluidHandler sourceHandler, final IFluidHandler destHandler, final Predicate<FluidStack> fluidFilter, final int keepAmount) {
if (sourceHandler == null || destHandler == null || fluidFilter == null || keepAmount <= 0)
return 0;
final Map<FluidStack, Integer> sourceFluids = collectDistinctFluids(sourceHandler, IFluidTankProperties::canDrain, fluidFilter);
final Map<FluidStack, Integer> destFluids = collectDistinctFluids(destHandler, IFluidTankProperties::canFill, fluidFilter);
int transferred = 0;
for (FluidStack fluidStack : sourceFluids.keySet()) {
if (transferred >= transferLimit)
break;
// if fluid needs to be moved to meet the Keep Exact value
int amountInDest;
if ((amountInDest = destFluids.getOrDefault(fluidStack, 0)) < keepAmount) {
// move the lesser of the remaining transfer limit and the difference in actual vs keep exact amount
int amountToMove = Math.min(transferLimit - transferred, keepAmount - amountInDest);
// Nothing to do here, try the next fluid.
if (amountToMove <= 0)
continue;
// Simulate a drain of this fluid from the source tanks
FluidStack drainedResult = sourceHandler.drain(copyFluidStackWithAmount(fluidStack, amountToMove), false);
// Can't drain this fluid. Try the next one.
if (drainedResult == null || drainedResult.amount <= 0 || !fluidStack.equals(drainedResult))
continue;
// account for the possibility that the drain might give us less than requested
final int drainable = Math.min(amountToMove, drainedResult.amount);
// Simulate a fill of the drained amount
int fillResult = destHandler.fill(copyFluidStackWithAmount(fluidStack, drainable), false);
// Can't fill, try the next fluid.
if (fillResult <= 0)
continue;
// This Fluid can be drained and filled, so let's move the most that will actually work.
int fluidToMove = Math.min(drainable, fillResult);
FluidStack drainedActual = sourceHandler.drain(copyFluidStackWithAmount(fluidStack, fluidToMove), true);
// Account for potential error states from the drain
if (drainedActual == null)
throw new RuntimeException("Misbehaving fluid container: drain produced null after simulation succeeded");
if (!fluidStack.equals(drainedActual))
throw new RuntimeException("Misbehaving fluid container: drain produced a different fluid than the simulation");
if (drainedActual.amount != fluidToMove)
throw new RuntimeException(new FormattedMessage("Misbehaving fluid container: drain expected: {}, actual: {}", fluidToMove, drainedActual.amount).getFormattedMessage());
// Perform Fill
int filledActual = destHandler.fill(copyFluidStackWithAmount(fluidStack, fluidToMove), true);
// Account for potential error states from the fill
if (filledActual != fluidToMove)
throw new RuntimeException(new FormattedMessage("Misbehaving fluid container: fill expected: {}, actual: {}", fluidToMove, filledActual).getFormattedMessage());
// update the transferred amount
transferred += fluidToMove;
}
}
return transferred;
}
use of org.apache.logging.log4j.message.FormattedMessage in project Gaspunk by Ladysnake.
the class GasDeserializer method loadGases.
private static boolean loadGases(Path root, Path file) {
String relative = root.relativize(file).toString();
if (!"json".equals(FilenameUtils.getExtension(file.toString())) || relative.startsWith("_"))
return true;
String name = FilenameUtils.removeExtension(relative).replaceAll("\\\\", "/");
try (BufferedReader reader = Files.newBufferedReader(file)) {
Gas gas = GSON.fromJson(reader, Gas.class);
ModGases.REGISTRY.register(gas.setRegistryName(name));
} catch (Exception e) {
GasPunk.LOGGER.error(new FormattedMessage("Error trying to load a gas from file {}", file), e);
}
return true;
}
Aggregations