Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update logging to slf4j backed by log4j2 #42

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# # Build the image
# mvn -DskipTests clean package
# mvn dependency:copy-dependencies -DincludeArtifactIds=fits -DincludeTypes=zip
# docker build -f docker/Dockerfile -t fitsservlet .
# # Modify the following versions appropriately
# docker build -f docker/Dockerfile -t registry.lts.harvard.edu/lts/fits:1.5.5 .
# # If desired push this image to the registry
# docker push registry.lts.harvard.edu/lts/fits:1.5.5
#
# # Run the service in the foreground
# docker run --rm -it -p 8080:8080 fitsservlet
Expand Down
25 changes: 20 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<fits.version>1.5.2-SNAPSHOT</fits.version>
<fits.version>1.5.5</fits.version>
</properties>

<build>
Expand Down Expand Up @@ -108,12 +108,27 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.17.2</version>
</dependency>
<!--
The following are necessary beginning with JDK 11 (or OpenJDK 11)
Expand Down Expand Up @@ -179,8 +194,8 @@
<connection>scm:git:git://github.com/harvard-lts/FITSservlet.git</connection>
<developerConnection>scm:git:git://github.com/harvard-lts/FITSservlet.git</developerConnection>
<url>https://github.com/harvard-lts/FITSservlet</url>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@

import javax.servlet.ServletException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.harvard.hul.ois.fits.Fits;
import edu.harvard.hul.ois.fits.exceptions.FitsException;

/**
* Wrapper around a fits instance
*
*/
public class FitsWrapper {


private static final String fitsHome = System.getProperty(FITS_HOME_SYSTEM_PROP_NAME);
private static Logger logger = LogManager.getLogger(FitsWrapper.class);
private static Logger logger = LoggerFactory.getLogger(FitsWrapper.class);
private Fits fits;

public FitsWrapper() throws ServletException {
Expand All @@ -38,7 +37,7 @@ public FitsWrapper() throws ServletException {

// This really should have been checked earlier.
if (fitsHome == null) {
logger.fatal(FITS_HOME_SYSTEM_PROP_NAME + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
logger.error(FITS_HOME_SYSTEM_PROP_NAME + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
throw new ServletException(FITS_HOME_SYSTEM_PROP_NAME + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class FitsWrapperFactory extends BasePooledObjectFactory<FitsWrapper> {

private static Logger LOG = LogManager.getLogger(FitsWrapperFactory.class);
private static Logger LOG = LoggerFactory.getLogger(FitsWrapperFactory.class);

@Override
public FitsWrapper create() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.harvard.hul.ois.fits.FitsOutput;
import edu.harvard.hul.ois.fits.service.common.Constants;
Expand Down Expand Up @@ -75,7 +75,7 @@ public class FitsServlet extends HttpServlet {
private static final long MB_MULTIPLIER = 1024 * 1024;
private static final String FALSE = "false";

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

private File uploadBaseDir; // base directory into which all uploaded files will be placed
private FitsWrapperPool fitsWrapperPool;
Expand All @@ -93,7 +93,7 @@ public void init() throws ServletException {
logger.info(FITS_HOME_SYSTEM_PROP_NAME + ": " + fitsHome);

if (StringUtils.isEmpty(fitsHome)) {
logger.fatal(FITS_HOME_SYSTEM_PROP_NAME + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
logger.error(FITS_HOME_SYSTEM_PROP_NAME + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
throw new ServletException(FITS_HOME_SYSTEM_PROP_NAME + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;


/**
* This program is a test client to upload files to a web server using HTTP POST.
Expand Down Expand Up @@ -59,7 +60,7 @@ public class FormFileUploaderClientApplication {
String log4jProp = System.getProperty(LOG4J_SYSTEM_PROPERTY);
System.out.println("System property -- " + LOG4J_SYSTEM_PROPERTY + ": " + log4jProp);
// else should set log4j properties file from environment variable either in Eclipse of command line with -Dlog4j2.configurationFile=<some location>
logger = LogManager.getLogger(FormFileUploaderClientApplication.class);
logger = LoggerFactory.getLogger(FormFileUploaderClientApplication.class);
}

/**
Expand Down