improve terminology logging

This commit is contained in:
Grahame Grieve 2020-08-12 14:44:41 +10:00
parent 89e5c7010d
commit 9e422a1a2e
3 changed files with 30 additions and 27 deletions

View File

@ -0,0 +1,23 @@
package org.hl7.fhir.r5.context;
public class BaseLogger {
private int id = 0;
private String lastId;
public String getLastId() {
return lastId;
}
protected String nextId() {
id++;
lastId = Integer.toString(id);
return lastId;
}
public void clearLastId() {
lastId = null;
}
}

View File

@ -40,13 +40,11 @@ import java.util.List;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
public class HTMLClientLogger implements ToolingClientLogger {
public class HTMLClientLogger extends BaseLogger implements ToolingClientLogger {
private static final boolean DEBUG = false;
private PrintStream file;
private int id = 0;
private String lastId;
public HTMLClientLogger(String log) {
if (log != null) {
@ -61,12 +59,12 @@ public class HTMLClientLogger implements ToolingClientLogger {
public void logRequest(String method, String url, List<String> headers, byte[] body) {
if (file == null)
return;
id++;
if (DEBUG) {
System.out.println("tx: " +method+" "+url+" "+present(body));
}
lastId = Integer.toString(id);
file.println("<hr/><a name=\"l"+lastId+"\"> </a>");
String id = nextId();
file.println("<hr/><a name=\"l"+id+"\"> </a>");
file.println("<p>#"+id+"</p>");
file.println("<pre>");
file.println(method+" "+url+" HTTP/1.0");
for (String s : headers)
@ -115,12 +113,5 @@ public class HTMLClientLogger implements ToolingClientLogger {
}
}
public String getLastId() {
return lastId;
}
public void clearLastId() {
lastId = null;
}
}

View File

@ -40,11 +40,9 @@ import java.util.List;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
public class TextClientLogger implements ToolingClientLogger {
public class TextClientLogger extends BaseLogger implements ToolingClientLogger {
private PrintStream file;
private int id = 0;
private String lastId;
public TextClientLogger(String log) {
if (log != null) {
@ -59,9 +57,8 @@ public class TextClientLogger implements ToolingClientLogger {
public void logRequest(String method, String url, List<String> headers, byte[] body) {
if (file == null)
return;
id++;
lastId = Integer.toString(id);
file.println("\r\n--- "+lastId+" -----------------\r\nRequest: \r\n");
String id = nextId();
file.println("\r\n--- "+id+" -----------------\r\nRequest: \r\n");
file.println(method+" "+url+" HTTP/1.0");
for (String s : headers)
file.println(Utilities.escapeXml(s));
@ -91,12 +88,4 @@ public class TextClientLogger implements ToolingClientLogger {
}
}
public String getLastId() {
return lastId;
}
public void clearLastId() {
lastId = null;
}
}