Skip to content

Commit

Permalink
Merge pull request #16 from madgeek-arc/feature/logging
Browse files Browse the repository at this point in the history
Feature/logging
  • Loading branch information
jdvorak001 authored Jul 1, 2024
2 parents 7babd7e + 8934465 commit a75ec66
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<guidelines.project.dir>../guidelines-cris-managers</guidelines.project.dir>
<logger.version>2.23.1</logger.version>
<fully.qualified.main.class.name>org.eurocris.openaire.cris.validator.CRISValidator</fully.qualified.main.class.name>
<maven.compiler.version>17</maven.compiler.version>
</properties>
Expand All @@ -37,6 +38,27 @@
<version>2.3.8</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${logger.version}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import org.openarchives.oai._2.SetType;
import org.openarchives.oai._2.StatusType;
import org.openarchives.oai._2_0.oai_identifier.OaiIdentifierType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.ErrorHandler;
Expand All @@ -77,6 +79,8 @@
@FixMethodOrder( value=MethodSorters.NAME_ASCENDING )
public class CRISValidator {

private static final Logger logger = LoggerFactory.getLogger(CRISValidator.class);

/**
* The spec of the set of equipments.
*/
Expand Down Expand Up @@ -221,7 +225,7 @@ private static Schema getSchema( final StreamSource ... sources ) throws IOExcep
final String targetNamespace = doc.getDocumentElement().getAttribute( "targetNamespace" );
schemaUrlsByNs.put( targetNamespace, schemaUrl );
nssBySchemaUrl.put( schemaUrl, targetNamespace );
System.out.println( "Will use " + schemaUrl + " for namespace " + targetNamespace );
logger.info( "Will use " + schemaUrl + " for namespace " + targetNamespace );
}
return getXmlSchemaFactory().newSchema( schemaList.toArray( new Source[0] ) );
}
Expand Down Expand Up @@ -382,7 +386,7 @@ public void check010_MetadataFormats() throws Exception {
} );
final long nMetadataFormats = checker.run();
final int nOpenAireMetadataFormats = metadataFormatsByPrefix.size();
System.out.println( "Having " + nOpenAireMetadataFormats + " OpenAIRE CRIS metadata formats (out of the total " + nMetadataFormats + " metadata formats)" );
logger.info( "Having " + nOpenAireMetadataFormats + " OpenAIRE CRIS metadata formats (out of the total " + nMetadataFormats + " metadata formats)" );
}

private CheckingIterable<MetadataFormatType> wrapCheckMetadataFormatPresent( final CheckingIterable<MetadataFormatType> parent ) {
Expand All @@ -396,7 +400,7 @@ public boolean test( final MetadataFormatType mf ) {
try {
final DocumentBuilder db = getDocumentBuilderFactory().newDocumentBuilder();
final String schemaUrl = mf.getSchema();
System.out.println( "Metadata format prefix " + mf.getMetadataPrefix() + " with ns " + mf.getMetadataNamespace() );
logger.info( "Metadata format prefix " + mf.getMetadataPrefix() + " with ns " + mf.getMetadataNamespace() );
assertTrue( "Please reference the official XML Schema at " + OPENAIRE_CERIF_SCHEMAS_ROOT + " (2h)", schemaUrl.startsWith( OPENAIRE_CERIF_SCHEMAS_ROOT ) );
assertTrue( "The schema file should be " + OPENAIRE_CERIF_SCHEMA_FILENAME + " (2i)", schemaUrl.endsWith( "/" + OPENAIRE_CERIF_SCHEMA_FILENAME ) );
final String localSchemaUrl = schemaUrlsByNs.get( metadataNs );
Expand Down Expand Up @@ -729,7 +733,7 @@ public void error( final SAXParseException exception ) throws SAXException {
final String msg = exception.getMessage();
if ( msg.startsWith( "cvc-pattern-valid: " ) ) {
patternValidErrorSignalled = true;
System.err.println( "In " + elString + ": " + msg );
logger.error( "In " + elString + ": " + msg );
} else {
if (!( patternValidErrorSignalled && msg.startsWith( "cvc-complex-type.2.2: " ) )) {
throw exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.openarchives.oai._2.ResumptionTokenType;
import org.openarchives.oai._2.SetType;
import org.openarchives.oai._2_0.oai_identifier.OaiIdentifierType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

/**
Expand All @@ -48,6 +50,8 @@
* @author jdvorak
*/
public class OAIPMHEndpoint {

private static final Logger logger = LoggerFactory.getLogger(OAIPMHEndpoint.class);

private final String baseUrl;

Expand Down Expand Up @@ -200,7 +204,7 @@ public Iterable<HeaderType> callListIdentifiers( final String metadataFormatPref
@SuppressWarnings( "unchecked")
private OAIPMHtype makeConnection( final boolean repoWideRequest, final String verb, final String... params ) throws IOException, SAXException, JAXBException {
final URL url = makeUrl( verb, params );
System.out.println( "Fetching and validating " + url.toExternalForm() );
logger.info( "Fetching and validating " + url.toExternalForm() );
final URLConnection conn = handleCompression( url.openConnection() );
conn.setRequestProperty( "User-Agent", userAgent );
conn.setRequestProperty( "Accept", "text/xml, application/xml" );
Expand Down Expand Up @@ -239,7 +243,7 @@ private void checkContentTypeHeader( final URLConnection conn ) {
// in the light of RFC7303 section 9.2 we accept "application/xml" as equivalent
final String contentType = conn.getContentType();
if (!( contentType.startsWith( "text/xml" ) || contentType.startsWith( "application/xml" ) )) {
System.err.println( "The Content-Type doesn't start with 'text/xml' or 'application/xml': " + contentType );
logger.error( "The Content-Type doesn't start with 'text/xml' or 'application/xml': " + contentType );
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="stdout" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %highlight{%-5level} [%15.15t] %-40.40c{1.}: %m%n"/>
</Console>
</Appenders>

<Loggers>
<AsyncRoot level="DEBUG">
<AppenderRef ref="stdout"/>
</AsyncRoot>
</Loggers>
</Configuration>

0 comments on commit a75ec66

Please sign in to comment.