com.global.api.logging.RequestFileLogger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of globalpayments-sdk Show documentation
Show all versions of globalpayments-sdk Show documentation
API for processing payments through Global Payments
package com.global.api.logging;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
public class RequestFileLogger extends RequestConsoleLogger {
private final File file;
public RequestFileLogger(String fileName) {
file = new File(fileName);
}
@Override
public void RequestSent(String request){
// Creates parent directories that do not exist. Doesn't throw an exception if the directories already exists
try {
Files.createDirectories(Paths.get(String.valueOf(file)).getParent());
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file, true))) {
bw.append(super.requestFormat(request)).append("\n");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void ResponseReceived(String response) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file, true))) {
bw.append(super.responseFormat(response)).append("\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}