use of net.logstash.logback.argument.StructuredArgument in project logstash-logback-encoder by logfellow.
the class ArgumentsJsonProvider method writeTo.
@Override
public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
if (!includeStructuredArguments && !includeNonStructuredArguments) {
// Short-circuit if nothing is included
return;
}
Object[] args = event.getArgumentArray();
if (args == null || args.length == 0) {
return;
}
boolean hasWrittenFieldName = false;
for (int argIndex = 0; argIndex < args.length; argIndex++) {
Object arg = args[argIndex];
if (arg instanceof StructuredArgument) {
if (includeStructuredArguments) {
if (!hasWrittenFieldName && getFieldName() != null) {
generator.writeObjectFieldStart(getFieldName());
hasWrittenFieldName = true;
}
StructuredArgument structuredArgument = (StructuredArgument) arg;
structuredArgument.writeTo(generator);
}
} else if (includeNonStructuredArguments) {
if (!hasWrittenFieldName && getFieldName() != null) {
generator.writeObjectFieldStart(getFieldName());
hasWrittenFieldName = true;
}
String fieldName = nonStructuredArgumentsFieldPrefix + argIndex;
generator.writeObjectField(fieldName, arg);
}
}
if (hasWrittenFieldName) {
generator.writeEndObject();
}
}
use of net.logstash.logback.argument.StructuredArgument in project pay-connector by alphagov.
the class Card3dsResponseAuthService method processGateway3DSecureResponse.
private void processGateway3DSecureResponse(String chargeExternalId, ChargeStatus oldChargeStatus, Gateway3DSAuthorisationResponse operationResponse, Auth3dsResult auth3dsResult) {
Optional<String> transactionId = operationResponse.getTransactionId();
ChargeStatus newStatus = operationResponse.getMappedChargeStatus();
if (newStatus == AUTHORISATION_3DS_REQUIRED) {
int numberOf3dsRequiredEventsRecorded = chargeService.count3dsRequiredEvents(chargeExternalId);
if (numberOf3dsRequiredEventsRecorded < authorisation3dsConfig.getMaximumNumberOfTimesToAllowUserToAttempt3ds()) {
LOGGER.info("Gateway instructed us to send the user through 3DS again for {} — this will be attempt {} of {}", chargeExternalId, numberOf3dsRequiredEventsRecorded + 1, authorisation3dsConfig.getMaximumNumberOfTimesToAllowUserToAttempt3ds());
} else {
newStatus = AUTHORISATION_REJECTED;
LOGGER.info("Gateway instructed us to send the user through 3DS again for {} but there have already been {} attempts in total, " + "so treating authorisation as rejected", chargeExternalId, numberOf3dsRequiredEventsRecorded);
}
}
LOGGER.info("3DS response authorisation for {} - {} .'. about to attempt charge update from {} -> {}", chargeExternalId, operationResponse, oldChargeStatus, newStatus);
ChargeEntity updatedCharge = chargeService.updateChargePost3dsAuthorisation(chargeExternalId, newStatus, AUTHORISATION_3DS, transactionId.orElse(null), operationResponse.getGateway3dsRequiredParams().map(Gateway3dsRequiredParams::toAuth3dsRequiredEntity).orElse(null), operationResponse.getProviderSessionIdentifier().orElse(null));
var worldPay3dsOrFlexLogMessage = integration3dsType(auth3dsResult, updatedCharge);
var structuredLoggingArguments = updatedCharge.getStructuredLoggingArgs();
if (worldPay3dsOrFlexLogMessage == WORLDPAY_3DS_CLASSIC) {
structuredLoggingArguments = ArrayUtils.addAll(structuredLoggingArguments, new StructuredArgument[] { kv(INTEGRATION_3DS_VERSION, "3DS") });
} else if (worldPay3dsOrFlexLogMessage == WORLDPAY_3DS_FLEX) {
structuredLoggingArguments = ArrayUtils.addAll(structuredLoggingArguments, new StructuredArgument[] { kv(INTEGRATION_3DS_VERSION, "3DS Flex") });
}
var logMessage = String.format(Locale.UK, "3DS authentication result%s authorisation for %s (%s %s) for %s (%s) - %s .'. %s -> %s", worldPay3dsOrFlexLogMessage.getLogMessage(), updatedCharge.getExternalId(), updatedCharge.getPaymentGatewayName().getName(), updatedCharge.getGatewayTransactionId(), updatedCharge.getGatewayAccount().getAnalyticsId(), updatedCharge.getGatewayAccount().getId(), operationResponse, oldChargeStatus, updatedCharge.getStatus());
LOGGER.info(logMessage, structuredLoggingArguments);
authorisationService.emitAuthorisationMetric(updatedCharge, "authorise-3ds");
}
use of net.logstash.logback.argument.StructuredArgument in project echopraxia by tersesystems.
the class LogstashLoggerTest method toJson.
private String toJson(ILoggingEvent event) throws IOException {
final StringWriter sw = new StringWriter();
final Object[] argumentArray = event.getArgumentArray();
final StructuredArgument argument = (StructuredArgument) argumentArray[0];
try (JsonGenerator generator = mapper.createGenerator(sw)) {
generator.writeStartObject();
argument.writeTo(generator);
generator.writeEndObject();
}
return sw.toString();
}
use of net.logstash.logback.argument.StructuredArgument in project echopraxia by tersesystems.
the class LogstashCoreLogger method convertArguments.
// Top level conversion to Logback must be StructuredArgument, with an optional throwable
// at the end of the array.
protected Object[] convertArguments(List<Field> args) {
// Top level arguments must be StructuredArguments, +1 for throwable
Value<Throwable> throwable = null;
List<Object> arguments = new ArrayList<>(args.size() + 1);
for (Field field : args) {
final Value<?> value = field.value();
if (value.type() == Value.ValueType.EXCEPTION) {
throwable = (Value.ExceptionValue) value;
} else {
final String name = field.name();
StructuredArgument array = field instanceof ValueField ? StructuredArguments.value(name, value) : StructuredArguments.keyValue(name, value);
arguments.add(array);
}
}
// If the exception exists, it must be raw so the varadic case will pick it up.
if (throwable != null) {
arguments.add(throwable.raw());
}
return arguments.toArray();
}
Aggregations