I want to enable logging against a bucket on GCS using the java sdk. Essentially, I want to implement the equivalent of the gsutil command : gsutil logging set on -b gs://logging-bucket -o AccessLog gs://mycompanybucket
as specified in the documentation here . I have tried to call the command line via java code but this always hands forever.
public static void checkLoggingBuckets(ArrayList<String> cloudbuckets) throws IOException {
Runtime rt = Runtime.getRuntime();
ArrayList<String> bucketList = cloudbuckets;
try {
for (String st: bucketList) {
String command = "cmd /c cmd.exe gsutil logging set on -b gs://logs-bucket-2019 -o AccessLog gs://";
System.out.println("checking for bucket " + st);
Process proc = rt.exec(command + st);
int result = proc.waitFor();
System.out.println("Process exit code: " + result);
System.out.println();
System.out.println("Result:");
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}