Pass -debug param to default logger + add logger to context builders

This commit is contained in:
dotasek 2022-03-25 13:38:24 -04:00
parent 35f5b96eb7
commit 86b714bb7b
4 changed files with 35 additions and 9 deletions

View File

@ -201,6 +201,9 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
@With @With
private final boolean allowLoadingDuplicates; private final boolean allowLoadingDuplicates;
@With
private final IWorkerContext.ILoggingService loggingService;
public SimpleWorkerContextBuilder() { public SimpleWorkerContextBuilder() {
cacheTerminologyClientErrors = false; cacheTerminologyClientErrors = false;
alwaysUseTerminologyServer = false; alwaysUseTerminologyServer = false;
@ -209,6 +212,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
locale = null; locale = null;
userAgent = null; userAgent = null;
allowLoadingDuplicates = false; allowLoadingDuplicates = false;
loggingService = new SystemOutLoggingService();
} }
private SimpleWorkerContext getSimpleWorkerContextInstance() throws IOException { private SimpleWorkerContext getSimpleWorkerContextInstance() throws IOException {
@ -227,6 +231,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
private SimpleWorkerContext build(SimpleWorkerContext context) throws IOException { private SimpleWorkerContext build(SimpleWorkerContext context) throws IOException {
context.initTS(terminologyCachePath); context.initTS(terminologyCachePath);
context.setUserAgent(userAgent); context.setUserAgent(userAgent);
context.setLogger(loggingService);
return context; return context;
} }

View File

@ -1,6 +1,15 @@
package org.hl7.fhir.r5.context; package org.hl7.fhir.r5.context;
class SystemOutLoggingService implements IWorkerContext.ILoggingService { import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class SystemOutLoggingService implements IWorkerContext.ILoggingService {
private final boolean debug;
public SystemOutLoggingService() {
this(false);
}
@Override @Override
public void logMessage(String message) { public void logMessage(String message) {
@ -9,6 +18,8 @@ class SystemOutLoggingService implements IWorkerContext.ILoggingService {
@Override @Override
public void logDebugMessage(LogCategory category, String message) { public void logDebugMessage(LogCategory category, String message) {
System.out.println(" -" + category.name().toLowerCase() + ": " + message); if (debug) {
} System.out.println(" -" + category.name().toLowerCase() + ": " + message);
}
}
} }

View File

@ -12,9 +12,11 @@ import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;
import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.IWorkerContext.ICanonicalResourceLocator; import org.hl7.fhir.r5.context.IWorkerContext.ICanonicalResourceLocator;
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion; import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.context.SystemOutLoggingService;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
@ -207,6 +209,10 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
@With @With
private final boolean canRunWithoutTerminologyServer; private final boolean canRunWithoutTerminologyServer;
@With
private final IWorkerContext.ILoggingService loggingService;
public ValidationEngineBuilder() { public ValidationEngineBuilder() {
terminologyCachePath = null; terminologyCachePath = null;
userAgent = null; userAgent = null;
@ -216,9 +222,10 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
txVersion = null; txVersion = null;
timeTracker = null; timeTracker = null;
canRunWithoutTerminologyServer = false; canRunWithoutTerminologyServer = false;
loggingService = new SystemOutLoggingService();
} }
public ValidationEngineBuilder(String terminologyCachePath, String userAgent, String version, String txServer, String txLog, FhirPublication txVersion, TimeTracker timeTracker, boolean canRunWithoutTerminologyServer) { public ValidationEngineBuilder(String terminologyCachePath, String userAgent, String version, String txServer, String txLog, FhirPublication txVersion, TimeTracker timeTracker, boolean canRunWithoutTerminologyServer, IWorkerContext.ILoggingService loggingService) {
this.terminologyCachePath = terminologyCachePath; this.terminologyCachePath = terminologyCachePath;
this.userAgent = userAgent; this.userAgent = userAgent;
this.version = version; this.version = version;
@ -227,15 +234,16 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
this.txVersion = txVersion; this.txVersion = txVersion;
this.timeTracker = timeTracker; this.timeTracker = timeTracker;
this.canRunWithoutTerminologyServer = canRunWithoutTerminologyServer; this.canRunWithoutTerminologyServer = canRunWithoutTerminologyServer;
this.loggingService = loggingService;
} }
public ValidationEngineBuilder withTxServer(String txServer, String txLog, FhirPublication txVersion) { public ValidationEngineBuilder withTxServer(String txServer, String txLog, FhirPublication txVersion) {
return new ValidationEngineBuilder(terminologyCachePath, userAgent, version, txServer, txLog, txVersion,timeTracker, canRunWithoutTerminologyServer); return new ValidationEngineBuilder(terminologyCachePath, userAgent, version, txServer, txLog, txVersion,timeTracker, canRunWithoutTerminologyServer, loggingService);
} }
public ValidationEngine fromNothing() throws IOException { public ValidationEngine fromNothing() throws IOException {
ValidationEngine engine = new ValidationEngine(); ValidationEngine engine = new ValidationEngine();
SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder(); SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder().withLoggingService(loggingService);
if (terminologyCachePath != null) if (terminologyCachePath != null)
contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath); contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
engine.setContext(contextBuilder.build()); engine.setContext(contextBuilder.build());
@ -246,7 +254,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
public ValidationEngine fromSource(String src) throws IOException, URISyntaxException { public ValidationEngine fromSource(String src) throws IOException, URISyntaxException {
ValidationEngine engine = new ValidationEngine(); ValidationEngine engine = new ValidationEngine();
engine.loadCoreDefinitions(src, false, terminologyCachePath, userAgent, timeTracker); engine.loadCoreDefinitions(src, false, terminologyCachePath, userAgent, timeTracker, loggingService);
engine.getContext().setCanRunWithoutTerminology(canRunWithoutTerminologyServer); engine.getContext().setCanRunWithoutTerminology(canRunWithoutTerminologyServer);
if (txServer != null) { if (txServer != null) {
@ -258,11 +266,11 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
} }
} }
private void loadCoreDefinitions(String src, boolean recursive, String terminologyCachePath, String userAgent, TimeTracker tt) throws FHIRException, IOException { private void loadCoreDefinitions(String src, boolean recursive, String terminologyCachePath, String userAgent, TimeTracker tt, IWorkerContext.ILoggingService loggingService) throws FHIRException, IOException {
NpmPackage npm = getPcm().loadPackage(src, null); NpmPackage npm = getPcm().loadPackage(src, null);
if (npm != null) { if (npm != null) {
version = npm.fhirVersion(); version = npm.fhirVersion();
SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder(); SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder().withLoggingService(loggingService);
if (terminologyCachePath != null) if (terminologyCachePath != null)
contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath); contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
if (userAgent != null) { if (userAgent != null) {

View File

@ -2,6 +2,7 @@ package org.hl7.fhir.validation.cli.services;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.context.SystemOutLoggingService;
import org.hl7.fhir.r5.context.TerminologyCache; import org.hl7.fhir.r5.context.TerminologyCache;
import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
@ -329,6 +330,7 @@ public class ValidationService {
String txver = validator.setTerminologyServer(cliContext.getTxServer(), cliContext.getTxLog(), ver); String txver = validator.setTerminologyServer(cliContext.getTxServer(), cliContext.getTxLog(), ver);
System.out.println(" - Version " + txver + " (" + tt.milestone() + ")"); System.out.println(" - Version " + txver + " (" + tt.milestone() + ")");
validator.setDebug(cliContext.isDoDebug()); validator.setDebug(cliContext.isDoDebug());
validator.getContext().setLogger(new SystemOutLoggingService(cliContext.isDoDebug()));
for (String src : cliContext.getIgs()) { for (String src : cliContext.getIgs()) {
igLoader.loadIg(validator.getIgs(), validator.getBinaries(), src, cliContext.isRecursive()); igLoader.loadIg(validator.getIgs(), validator.getBinaries(), src, cliContext.isRecursive());
} }