Commit 5f18ac69 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[UWS,TAP] Add a new logger which forwards log entries to SLF4J.

Then, UWS or TAP implementors are free to use whatever logging system they want
(e.g. log4j, logback, ...).
parent ded9cead
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -11,10 +11,13 @@ dependencies {
    compile fileTree(dir: 'lib', includes: ['stil_3.1.jar','cos-1.5beta.jar'])
    compile 'javax.servlet:javax.servlet-api:3.0.1'
    compile 'postgresql:postgresql:9.1-901.jdbc4'
    compile 'org.slf4j:slf4j-api:1.7.25'

    testCompile 'junit:junit:4.12'
    testCompile 'com.h2database:h2:1.4.193'
    testCompile fileTree(dir: 'lib', include: 'astroh2-0.3.jar')
    testCompile 'org.slf4j:slf4j-simple:1.7.25'
    
    
    testRuntime 'simple-jndi:simple-jndi:0.11.4.1'
    testRuntime 'com.vividsolutions:jts-core:1.14.0'
+6 −1
Original line number Diff line number Diff line
@@ -14,9 +14,13 @@

	<property name="cosJarName" value="cos-1.5beta.jar" />
	<property name="cosJar" value="${libDir}/${cosJarName}" />
	
	<property name="stilJarName" value="stil_3.1.jar" />
	<property name="stilJar" value="${libDir}/${stilJarName}" />

	<property name="slf4jApiJarName" value="slf4j-api-1.7.25.jar" />
	<property name="slf4jApiJar" value="${libDir}/${slf4jApiJarName}" />

	<property name="sqliteJarName" value="sqlite-jdbc-3.16.1.jar" />
	<property name="sqliteJar" value="${libDir}/${sqliteJarName}" />

@@ -29,7 +33,7 @@
	<property name="astroh2JarName" value="astroh2-0.3.jar" />
	<property name="astroh2Jar" value="${libDir}/${astroh2JarName}" />
		
	<property name="tapPath" value="tap/**,adql/**,uws/**,cds/**" />
	<property name="tapPath" value="tap/**,adql/**,uws/**,cds/**,datalink/**,puzzlibs/**" />
	<property name="jsonPath" value="org/json/**" />
	<property name="extLibsPath" value="com/oreilly/servlet/**,nom/tam/**,org/apache/tools/bzip2/**,uk/ac/starlink/**" />
	<property name="licensePath" value="COPYING.LESSER" />
@@ -67,6 +71,7 @@
	<!-- CLASSPATHS -->
	<path id="tap.classpath">
		<pathelement location="${cosJar}" />
		<pathelement location="${slf4jApiJar}" />
		<pathelement location="${jsonJar}" />
		<pathelement location="${stilJar}" />
		<pathelement location="${POSTGRES}" />
+5 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
<!DOCTYPE project>
<project name="uws" basedir="." default="buildLib">
	
	<property name="version" value="4.3" />
	<property name="version" value="4.4" />

	<property name="srcDir" value="src" />
	<property name="testDir" value="test" />
@@ -15,6 +15,9 @@
	<property name="cosJarName" value="cos-1.5beta.jar" />
	<property name="cosJar" value="${libDir}/${cosJarName}" />

	<property name="slf4jApiJarName" value="slf4j-api-1.7.25.jar" />
	<property name="slf4jApiJar" value="${libDir}/${slf4jApiJarName}" />
	
	<property name="uwsPath" value="uws/**" />
	<property name="jsonPath" value="org/json/**" />
	<property name="licensePath" value="COPYING.LESSER" />
@@ -36,6 +39,7 @@
	<!-- CLASSPATHS -->
	<path id="uws.classpath">
		<pathelement location="${cosJar}" />
		<pathelement location="${slf4jApiJar}" />
		<pathelement location="${SERVLET-API}" />
	</path>
	
+42 −36
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import static tap.config.TAPConfiguration.KEY_UDFS;
import static tap.config.TAPConfiguration.KEY_UPLOAD_ENABLED;
import static tap.config.TAPConfiguration.KEY_UPLOAD_MAX_FILE_SIZE;
import static tap.config.TAPConfiguration.KEY_USER_IDENTIFIER;
import static tap.config.TAPConfiguration.SLF4J_LOGGER;
import static tap.config.TAPConfiguration.VALUE_ALL;
import static tap.config.TAPConfiguration.VALUE_ANY;
import static tap.config.TAPConfiguration.VALUE_CSV;
@@ -109,6 +110,7 @@ import tap.formatter.SVFormat;
import tap.formatter.TextFormat;
import tap.formatter.VOTableFormat;
import tap.log.DefaultTAPLog;
import tap.log.Slf4jTAPLog;
import tap.log.TAPLog;
import tap.metadata.TAPMetadata;
import tap.metadata.TableSetParser;
@@ -129,7 +131,7 @@ import uws.service.log.UWSLog.LogLevel;
 * </p>
 *
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 2.3 (03/2018)
 * @version 2.3 (04/2018)
 * @since 2.0
 */
public final class ConfigurableServiceConnection implements ServiceConnection {
@@ -355,7 +357,7 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
	}

	/**
	 * Initialize the TAP logger with the given TAP configuration file.
	 * Initialise the TAP logger with the given TAP configuration file.
	 *
	 * @param tapConfig	The content of the TAP configuration file.
	 *
@@ -367,31 +369,33 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
		String propValue = getProperty(tapConfig, KEY_LOGGER);
		if (propValue == null || propValue.trim().equalsIgnoreCase(DEFAULT_LOGGER))
			logger = new DefaultTAPLog(fileManager);
		else if (propValue == null || propValue.trim().equalsIgnoreCase(SLF4J_LOGGER))
			logger = new Slf4jTAPLog();
		else
			logger = newInstance(propValue, KEY_LOGGER, TAPLog.class, new Class<?>[]{ UWSFileManager.class }, new Object[]{ fileManager });

		StringBuffer buf = new StringBuffer("Logger initialized");
		// Set some options for the default logger:
		if (propValue == null || propValue.trim().equalsIgnoreCase(DEFAULT_LOGGER)){

			// Set the minimum log level:
			propValue = getProperty(tapConfig, KEY_MIN_LOG_LEVEL);
			if (propValue != null){
				try{
					((DefaultTAPLog)logger).setMinLogLevel(LogLevel.valueOf(propValue.toUpperCase()));
			}catch(IllegalArgumentException iae){}
				}catch(IllegalArgumentException iae){
				}
			}
		buf.append(" (minimum log level: ").append(((DefaultTAPLog)logger).getMinLogLevel());

			// Set the log rotation period, if any:
			if (fileManager instanceof LocalUWSFileManager){
				propValue = getProperty(tapConfig, KEY_LOG_ROTATION);
				if (propValue != null)
					((LocalUWSFileManager)fileManager).setLogRotationFreq(propValue);
			buf.append(", log rotation: ").append(((LocalUWSFileManager)fileManager).getLogRotationFreq());
			}
		}

		// Log the successful initialization with set parameters:
		buf.append(").");
		logger.info(buf.toString());
		// Log the successful initialisation of the logger:
		logger.info("Logger initialized - {" + logger.getConfigString() + "}");
	}

	/**
@@ -1516,7 +1520,8 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
				uploadLimits[0] = limit;
				return true;
			}
		}catch(TAPException e){}
		}catch(TAPException e){
		}
		return false;
	}

@@ -1540,7 +1545,8 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
				uploadLimits[0] = limit;
			// Set the new maximum output limit:
			uploadLimits[1] = limit;
		}catch(TAPException e){}
		}catch(TAPException e){
		}
	}

	@Override
+35 −16
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@ package tap.config;
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2015-2017 - Astronomisches Rechen Institut (ARI)
 * Copyright 2015-2018 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

import java.lang.reflect.Constructor;
@@ -35,8 +36,8 @@ import tap.backup.DefaultTAPBackupManager;
 * <p><i>This class implements the Design Pattern "Utility": no instance of this class can be created, it can not be extended,
 * and it must be used only thanks to its static classes and attributes.</i></p>
 *
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 2.1 (09/2017)
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.3 (07/2018)
 * @since 2.0
 */
public final class TAPConfiguration {
@@ -83,14 +84,26 @@ public final class TAPConfiguration {
	/** Name/Key of the property specifying the logger to use.
	 * By default, {@link tap.log.DefaultTAPLog} is used. */
	public final static String KEY_LOGGER = "logger";
	/** Default value of the property {@link #KEY_LOGGER}: {@value #DEFAULT_LOGGER}. */
	/** Default value of the property {@link #KEY_LOGGER}:
	 * {@value #DEFAULT_LOGGER}. */
	public final static String DEFAULT_LOGGER = "default";
	/** Name/Key of the property specifying the minimum type of messages (i.e. DEBUG, INFO, WARNING, ERROR, FATAL)
	 * that must be logged. By default all messages are logged...which is equivalent to set this property to "DEBUG". */
	/** Name/Key of the property specifying the minimum type of messages
	 * (i.e. DEBUG, INFO, WARNING, ERROR, FATAL) that must be logged by the
	 * <strong>default logger</strong>.
	 * <p>By default all messages are logged...which is equivalent to set this
	 * property to "DEBUG".</p>
	 * <p><i><b>Note:</b> If {@link #KEY_LOGGER} is set to a value different
	 * from {@value #DEFAULT_LOGGER}, this property is ignored.</i></p> */
	public final static String KEY_MIN_LOG_LEVEL = "min_log_level";
	/** Name/Key of the property specifying the frequency of the log file rotation.
	 * By default the log rotation occurs every day at midnight. */
	/** Name/Key of the property specifying the frequency of the log file
	 * rotation to set in the <strong>default logger</strong>.
	 * <p>By default the log rotation occurs every day at midnight.</p>
	 * <p><i><b>Note:</b> If {@link #KEY_LOGGER} is set to a value different
	 * from {@value #DEFAULT_LOGGER}, this property is ignored.</i></p> */
	public final static String KEY_LOG_ROTATION = "log_rotation";
	/** SLF4J logger value: {@value #SLF4J_LOGGER}.
	 * @since 2.3 */
	public final static String SLF4J_LOGGER = "slf4j";

	/* UWS BACKUP */
	/** Name/Key of the property specifying the frequency (in milliseconds) of jobs backup.
@@ -191,6 +204,11 @@ public final class TAPConfiguration {
	/** Name/Key of the property specifying the local file path of the XML file containing the TAP metadata to load. */
	public final static String KEY_METADATA_FILE = "metadata_file";

	/* DATALINK KEY */
	/** Name/Key of the property providing the API for the Datalink capability.
	 * @since 2.3 */
	public final static String KEY_DATALINK = "datalink";

	/* HOME PAGE KEY */
	/** Name/Key of the property specifying the TAP home page to use.
	 * It can be a file, a URL or a class. If null, the default TAP home page of the library is used.
@@ -298,7 +316,8 @@ public final class TAPConfiguration {
	public final static String KEY_TAP_FACTORY = "tap_factory";

	/** No instance of this class should be created. */
	private TAPConfiguration(){}
	private TAPConfiguration(){
	}

	/**
	 * <p>Read the asked property from the given Properties object.</p>
Loading