From 8be5453666a54a213d6895582fe6dd252b6dd995 Mon Sep 17 00:00:00 2001 From: Bryce Willey Date: Fri, 7 Jul 2023 17:43:11 -0400 Subject: [PATCH] Logging improvements Use the LoggingFeature for all of the clients, not just the TylerEFM ones Also try to add tabs in logs that should be aligned --- .../litlab/efsp/tyler/SoapClientChooser.java | 58 +++++++- .../litlab/efsp/ecf5/SoapClientChooserV5.java | 125 +++++++++++++++--- .../litlab/efsp/server/EfspServer.java | 32 ++--- .../efsp/tyler/ecfcodes/CodeUpdater.java | 8 +- 4 files changed, 184 insertions(+), 39 deletions(-) diff --git a/TylerEcf4/src/main/java/edu/suffolk/litlab/efsp/tyler/SoapClientChooser.java b/TylerEcf4/src/main/java/edu/suffolk/litlab/efsp/tyler/SoapClientChooser.java index 0adbd01f..55b73279 100644 --- a/TylerEcf4/src/main/java/edu/suffolk/litlab/efsp/tyler/SoapClientChooser.java +++ b/TylerEcf4/src/main/java/edu/suffolk/litlab/efsp/tyler/SoapClientChooser.java @@ -4,9 +4,12 @@ import ecf4.latest.tyler.efm.wsdl.webservicesprofile_implementation_4_0.CourtRecordMDEService; import ecf4.latest.tyler.efm.wsdl.webservicesprofile_implementation_4_0.FilingReviewMDEService; import ecf4.latest.tyler.efm.wsdl.webservicesprofile_implementation_4_0.ServiceMDEService; +import edu.suffolk.litlab.efsp.ConfigurationLoader; import edu.suffolk.litlab.efsp.Jurisdiction; +import jakarta.xml.ws.WebServiceFeature; import java.net.URL; import java.util.Optional; +import org.apache.cxf.ext.logging.LoggingFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,6 +26,21 @@ public class SoapClientChooser { private static final String RECORD_SUFFIX = "-ECF-4.0-CourtRecordMDEService.wsdl"; private static final String SCHEDULE_SUFFIX = "-v5-CourtSchedulingMDE.wsdl"; + private static Optional shouldLogRequests = Optional.empty(); + + public static boolean shouldLogRequests() { + if (shouldLogRequests.isEmpty()) { + shouldLogRequests = Optional.of(ConfigurationLoader.shouldLogRequests()); + } + return shouldLogRequests.orElse(false); + } + + public static WebServiceFeature getLoggingFeature() { + LoggingFeature loggingFeature = new LoggingFeature(); + loggingFeature.setPrettyLogging(true); + return loggingFeature; + } + private static URL getRes(TylerDomain domain, TylerVersion version, String suffix) { String wsdlPath = "wsdl/" @@ -45,8 +63,13 @@ public static Optional getFilingReviewFactory(Jurisdicti var domain = new TylerDomain(jurisdiction, TylerClients.getTylerEnv()); return version.map( v -> { + boolean shouldLog = shouldLogRequests(); URL url = getRes(domain, v, REVIEW_SUFFIX); - return new FilingReviewMDEService(url); + if (shouldLog) { + return new FilingReviewMDEService(url, getLoggingFeature()); + } else { + return new FilingReviewMDEService(url); + } }); } @@ -54,13 +77,31 @@ public static Optional getServiceFactory(Jurisdiction jurisdi var version = TylerClients.getVersion(jurisdiction); var domain = new TylerDomain(jurisdiction, TylerClients.getTylerEnv()); - return version.map(v -> new ServiceMDEService(getRes(domain, v, SERVICE_SUFFIX))); + return version.map( + v -> { + boolean shouldLog = shouldLogRequests(); + URL url = getRes(domain, v, SERVICE_SUFFIX); + if (shouldLog) { + return new ServiceMDEService(url, getLoggingFeature()); + } else { + return new ServiceMDEService(url); + } + }); } public static Optional getCourtRecordFactory(Jurisdiction jurisdiction) { var version = TylerClients.getVersion(jurisdiction); var domain = new TylerDomain(jurisdiction, TylerClients.getTylerEnv()); - return version.map(v -> new CourtRecordMDEService(getRes(domain, v, RECORD_SUFFIX))); + return version.map( + v -> { + boolean shouldLog = shouldLogRequests(); + URL url = getRes(domain, v, RECORD_SUFFIX); + if (shouldLog) { + return new CourtRecordMDEService(url, getLoggingFeature()); + } else { + return new CourtRecordMDEService(url); + } + }); } public static Optional getCourtSchedulingFactory( @@ -70,6 +111,15 @@ public static Optional getCourtSchedulingFactory( } var version = TylerClients.getVersion(jurisdiction); var domain = new TylerDomain(jurisdiction, TylerClients.getTylerEnv()); - return version.map(v -> new CourtSchedulingMDE_Service(getRes(domain, v, SCHEDULE_SUFFIX))); + return version.map( + v -> { + boolean shouldLog = shouldLogRequests(); + URL url = getRes(domain, v, SCHEDULE_SUFFIX); + if (shouldLog) { + return new CourtSchedulingMDE_Service(url, getLoggingFeature()); + } else { + return new CourtSchedulingMDE_Service(url); + } + }); } } diff --git a/TylerEcf5/src/main/java/edu/suffolk/litlab/efsp/ecf5/SoapClientChooserV5.java b/TylerEcf5/src/main/java/edu/suffolk/litlab/efsp/ecf5/SoapClientChooserV5.java index 29bb61c5..91189e91 100644 --- a/TylerEcf5/src/main/java/edu/suffolk/litlab/efsp/ecf5/SoapClientChooserV5.java +++ b/TylerEcf5/src/main/java/edu/suffolk/litlab/efsp/ecf5/SoapClientChooserV5.java @@ -9,15 +9,18 @@ import ecf5.TylerCourtSchedulingMDEService; import ecf5.TylerFilingAssemblyMDEService; import ecf5.TylerFilingReviewMDEService; +import edu.suffolk.litlab.efsp.ConfigurationLoader; import edu.suffolk.litlab.efsp.Jurisdiction; import edu.suffolk.litlab.efsp.tyler.TylerClients; import edu.suffolk.litlab.efsp.tyler.TylerDomain; import edu.suffolk.litlab.efsp.tyler.TylerVersion; import jakarta.xml.ws.BindingProvider; +import jakarta.xml.ws.WebServiceFeature; import java.net.URL; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; +import org.apache.cxf.ext.logging.LoggingFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +37,21 @@ public class SoapClientChooserV5 { private static final String TYLER_FILING_ASSEM_WSDL = "-ECF5-TylerFilingAssemblyMDEService.wsdl"; private static final String TYLER_FILING_REVIEW_WSDL = "-ECF5-TylerFilingReviewMDEService.wsdl"; + private static Optional shouldLogRequests = Optional.empty(); + + public static boolean shouldLogRequests() { + if (shouldLogRequests.isEmpty()) { + shouldLogRequests = Optional.of(ConfigurationLoader.shouldLogRequests()); + } + return shouldLogRequests.orElse(false); + } + + public static WebServiceFeature getLoggingFeature() { + LoggingFeature loggingFeature = new LoggingFeature(); + loggingFeature.setPrettyLogging(true); + return loggingFeature; + } + public static Optional, CourtPolicyClient>> getCourtPolicyFactory(Jurisdiction jurisdiction) { var version = TylerClients.getVersion(jurisdiction); @@ -41,8 +59,17 @@ public class SoapClientChooserV5 { return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, COURT_POLICY_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( - u -> (consume) -> new CourtPolicyClient(new CourtPolicyMDEService(u), v, consume)); + u -> + (consume) -> { + if (shouldLog) { + return new CourtPolicyClient( + new CourtPolicyMDEService(u, getLoggingFeature()), v, consume); + } else { + return new CourtPolicyClient(new CourtPolicyMDEService(u), v, consume); + } + }); }); } @@ -53,8 +80,17 @@ public class SoapClientChooserV5 { return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, COURT_RECORD_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( - u -> (consume) -> new CourtRecordClient(new CourtRecordMDEService(u), v, consume)); + u -> + (consume) -> { + if (shouldLog) { + return new CourtRecordClient( + new CourtRecordMDEService(u, getLoggingFeature()), v, consume); + } else { + return new CourtRecordClient(new CourtRecordMDEService(u), v, consume); + } + }); }); } @@ -65,10 +101,18 @@ public class SoapClientChooserV5 { return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, COURT_SCHED_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( u -> - (consume) -> - new CourtSchedulingClient(new CourtSchedulingMDEService(u), v, consume)); + (consume) -> { + if (shouldLog) { + return new CourtSchedulingClient( + new CourtSchedulingMDEService(u, getLoggingFeature()), v, consume); + } else { + return new CourtSchedulingClient( + new CourtSchedulingMDEService(u), v, consume); + } + }); }); } @@ -79,8 +123,17 @@ public class SoapClientChooserV5 { return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, FILING_REVIEW_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( - u -> (consume) -> new FilingReviewClient(new FilingReviewMDEService(u), v, consume)); + u -> + (consume) -> { + if (shouldLog) { + return new FilingReviewClient( + new FilingReviewMDEService(u, getLoggingFeature()), v, consume); + } else { + return new FilingReviewClient(new FilingReviewMDEService(u), v, consume); + } + }); }); } @@ -91,7 +144,17 @@ public static Optional, ServiceClient>> getSe return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, SERVICE_WSDL); - return url.map(u -> (consume) -> new ServiceClient(new ServiceMDEService(u), v, consume)); + boolean shouldLog = shouldLogRequests(); + return url.map( + u -> + (consume) -> { + if (shouldLog) { + return new ServiceClient( + new ServiceMDEService(u, getLoggingFeature()), v, consume); + } else { + return new ServiceClient(new ServiceMDEService(u), v, consume); + } + }); }); } @@ -102,10 +165,18 @@ public static Optional, ServiceClient>> getSe return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, TYLER_COURT_RECORD_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( u -> - (consume) -> - new TylerCourtRecordClient(new TylerCourtRecordMDEService(u), v, consume)); + (consume) -> { + if (shouldLog) { + return new TylerCourtRecordClient( + new TylerCourtRecordMDEService(u, getLoggingFeature()), v, consume); + } else { + return new TylerCourtRecordClient( + new TylerCourtRecordMDEService(u), v, consume); + } + }); }); } @@ -116,11 +187,18 @@ public static Optional, ServiceClient>> getSe return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, TYLER_COURT_SCHED_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( u -> - (consume) -> - new TylerCourtSchedulingClient( - new TylerCourtSchedulingMDEService(u), v, consume)); + (consume) -> { + if (shouldLog) { + return new TylerCourtSchedulingClient( + new TylerCourtSchedulingMDEService(u, getLoggingFeature()), v, consume); + } else { + return new TylerCourtSchedulingClient( + new TylerCourtSchedulingMDEService(u), v, consume); + } + }); }); } @@ -131,11 +209,18 @@ public static Optional, ServiceClient>> getSe return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, TYLER_FILING_ASSEM_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( u -> - (consume) -> - new TylerFilingAssemblyClient( - new TylerFilingAssemblyMDEService(u), v, consume)); + (consume) -> { + if (shouldLog) { + return new TylerFilingAssemblyClient( + new TylerFilingAssemblyMDEService(u, getLoggingFeature()), v, consume); + } else { + return new TylerFilingAssemblyClient( + new TylerFilingAssemblyMDEService(u), v, consume); + } + }); }); } @@ -146,10 +231,18 @@ public static Optional, ServiceClient>> getSe return version.flatMap( v -> { var url = createLocalWsdlUrl(domain, v, TYLER_FILING_REVIEW_WSDL); + boolean shouldLog = shouldLogRequests(); return url.map( u -> - (consume) -> - new TylerFilingReviewClient(new TylerFilingReviewMDEService(u), v, consume)); + (consume) -> { + if (shouldLog) { + return new TylerFilingReviewClient( + new TylerFilingReviewMDEService(u, getLoggingFeature()), v, consume); + } else { + return new TylerFilingReviewClient( + new TylerFilingReviewMDEService(u), v, consume); + } + }); }); } diff --git a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/EfspServer.java b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/EfspServer.java index 677a3271..a9c9a10d 100644 --- a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/EfspServer.java +++ b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/EfspServer.java @@ -110,21 +110,23 @@ protected EfspServer( sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(new ArrayList>(services.keySet())); - LoggingFeature loggingFeature = new LoggingFeature(); - // TODO(brycew): control this from a cofig - loggingFeature.addSensitiveElementNames( - Set.of("api_key", "password", "Password", "TYLER-TOKEN-ILLINOIS", "TYLER-ID-ILLINOIS")); - loggingFeature.addSensitiveProtocolHeaderNames( - Set.of( - "TYLER-TOKEN-ILLINOIS", - "TYLER-TOKEN-MASSACHUSETTS", - "TYLER-TOKEN-VERMONT", - "TYLER-ID-ILLINOIS", - "X-API-KEY", - "x-api-key", - "X-Api-Key")); - loggingFeature.setPrettyLogging(true); - sf.setFeatures(List.of(loggingFeature)); + if (ConfigurationLoader.shouldLogRequests()) { + LoggingFeature loggingFeature = new LoggingFeature(); + // TODO(brycew): control this from a cofig + loggingFeature.addSensitiveElementNames( + Set.of("api_key", "password", "Password", "TYLER-TOKEN-ILLINOIS", "TYLER-ID-ILLINOIS")); + loggingFeature.addSensitiveProtocolHeaderNames( + Set.of( + "TYLER-TOKEN-ILLINOIS", + "TYLER-TOKEN-MASSACHUSETTS", + "TYLER-TOKEN-VERMONT", + "TYLER-ID-ILLINOIS", + "X-API-KEY", + "x-api-key", + "X-Api-Key")); + loggingFeature.setPrettyLogging(true); + sf.setFeatures(List.of(loggingFeature)); + } for (Map.Entry, SingletonResourceProvider> prov : services.entrySet()) { sf.setResourceProvider(prov.getKey(), prov.getValue()); diff --git a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/CodeUpdater.java b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/CodeUpdater.java index 65662a37..f95a8b98 100644 --- a/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/CodeUpdater.java +++ b/proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/ecfcodes/CodeUpdater.java @@ -288,7 +288,7 @@ private boolean downloadCourtTables( String baseUrl) throws JAXBException, IOException, SQLException { MDC.put(MDCWrappers.SESSION_ID, location); - log.info("Doing updates for: {}, tables: {}", location, tables); + log.info("Doing updates for: {},\ttables: {}", location, tables); Instant downloadStart = Instant.now(); // TODO(brycew-later): check that the effective date is later than today // JAXBElement obj = ccl.getEffectiveDate().getDateRepresentation(); @@ -327,7 +327,7 @@ private boolean downloadCourtTables( var downloadInc = Duration.between(downloadStart, Instant.now()); downloadDuration = downloadDuration.plus(downloadInc); log.info( - "Location: {}: Downloads took: {} (total: {})", location, downloadInc, downloadDuration); + "Location: {}:\tDownloads took: {} (total: {})", location, downloadInc, downloadDuration); Instant updateStart = Instant.now(); for (DownloadedCodes down : downloaded.values()) { @@ -344,7 +344,7 @@ private boolean downloadCourtTables( updateDuration = updateDuration.plus(updateInc); cd.commit(); - log.info("Location: {}: updates took: {} (total: {})", location, updateInc, updateDuration); + log.info("Location: {}:\tupdates took: {} (total: {})", location, updateInc, updateDuration); MDC.remove(MDCWrappers.REQUEST_ID); MDC.remove(MDCWrappers.SESSION_ID); return true; @@ -419,7 +419,7 @@ public boolean updateAll(String baseUrl, FilingReviewMDEPort filingPort, CodeDat final String courtLocation = courtAndTables.getKey(); List tables = courtAndTables.getValue(); log.debug( - "In {}, removing entries for court {} for tables: {}", + "In {},\nremoving entries for court {} for tables: {}", cd.getJurisdiction(), courtLocation, tables);