JENA-1916: Less verbose logging for admin
diff --git a/jena-fuseki2/apache-jena-fuseki/log4j2.properties b/jena-fuseki2/apache-jena-fuseki/log4j2.properties
index c5213b5..a95d274 100644
--- a/jena-fuseki2/apache-jena-fuseki/log4j2.properties
+++ b/jena-fuseki2/apache-jena-fuseki/log4j2.properties
@@ -37,6 +37,9 @@
logger.fuseki-server.name = org.apache.jena.fuseki.Server
logger.fuseki-server.level = INFO
+logger.fuseki-config.name = org.apache.jena.fuseki.Config
+logger.fuseki-config.level = INFO
+
logger.fuseki-admin.name = org.apache.jena.fuseki.Admin
logger.fuseki-admin.level = INFO
@@ -59,7 +62,7 @@
appender.plain.layout.type = PatternLayout
appender.plain.layout.pattern = %m%n
-logger.request-log.name = org.apache.jena.fuseki.Request
-logger.request-log.additivity = false
-logger.request-log.level = OFF
-logger.request-log.appenderRef.plain.ref = PLAIN
+logger.fuseki-request.name = org.apache.jena.fuseki.Request
+logger.fuseki-request.additivity = false
+logger.fuseki-request.level = OFF
+logger.fuseki-request.appenderRef.plain.ref = PLAIN
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionCtl.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionCtl.java
index c887352..9742452 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionCtl.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionCtl.java
@@ -23,6 +23,7 @@
import org.apache.jena.fuseki.servlets.ActionLifecycle;
import org.apache.jena.fuseki.servlets.HttpAction;
import org.apache.jena.fuseki.servlets.ServletProcessor;
+import org.apache.jena.fuseki.system.ActionCategory;
import org.apache.jena.sparql.core.DatasetGraph;
/**
@@ -31,7 +32,7 @@
*/
public abstract class ActionCtl extends ServletProcessor implements ActionLifecycle {
protected ActionCtl() {
- super(Fuseki.adminLog);
+ super(Fuseki.adminLog, ActionCategory.ADMIN);
}
@Override
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionStats.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionStats.java
index 60beb5c..34eaba2 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionStats.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/ctl/ActionStats.java
@@ -40,8 +40,8 @@
public class ActionStats extends ActionContainerItem
{
// For endpoint with "" as name.
- private static String emptyNameKeyPrefix = "_";
-
+ private static String emptyNameKeyPrefix = "_";
+
public ActionStats() { super(); }
@Override
@@ -49,7 +49,8 @@
// This does not consult the system database for dormant etc.
protected JsonValue execCommonContainer(HttpAction action) {
- action.log.info(format("[%d] GET stats all", action.id));
+ if ( action.verbose )
+ action.log.info(format("[%d] GET stats all", action.id));
return generateStats(action.getDataAccessPointRegistry());
}
@@ -66,7 +67,8 @@
protected JsonValue execCommonItem(HttpAction action) {
String datasetPath = getItemDatasetName(action);
- action.log.info(format("[%d] GET stats dataset %s", action.id, datasetPath));
+ if ( action.verbose )
+ action.log.info(format("[%d] GET stats dataset %s", action.id, datasetPath));
JsonBuilder builder = new JsonBuilder();
DataAccessPoint dap = getItemDataAccessPoint(action, datasetPath);
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java
index a4879ae..a261689 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java
@@ -36,6 +36,7 @@
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.auth.Auth;
import org.apache.jena.fuseki.servlets.*;
+import org.apache.jena.fuseki.system.ActionCategory;
import org.apache.jena.riot.web.HttpNames;
import org.apache.jena.web.HttpSC;
import org.slf4j.Logger;
@@ -101,7 +102,7 @@
/** Set up and handle a HTTP request for a dataset. */
private static boolean process(DataAccessPoint dap, HttpServletRequest request, HttpServletResponse response) {
- HttpAction action = allocHttpAction(dap, Fuseki.actionLog, request, response);
+ HttpAction action = allocHttpAction(dap, Fuseki.actionLog, ActionCategory.ACTION, request, response);
return dispatchAction(action);
}
@@ -363,7 +364,7 @@
}
// We don't wire in all the RDF syntaxes.
// Instead, "Quads" drops through to the default operation.
-
+
// -- SPARQL Graph Store Protocol
boolean hasParamGraph = request.getParameter(HttpNames.paramGraph) != null;
boolean hasParamGraphDefault = request.getParameter(HttpNames.paramGraphDefault) != null;
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiInfo.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiInfo.java
index 2800060..75ed403 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiInfo.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiInfo.java
@@ -28,14 +28,14 @@
import org.apache.jena.fuseki.Fuseki;
import org.slf4j.Logger;
+/** Information about the server */
public class FusekiInfo {
- public static void info(FusekiInitialConfig serverConfig, DataAccessPointRegistry registry) {
- if ( ! serverConfig.verbose )
- return;
- if ( serverConfig.quiet )
- return;
-
+ /** Print command line setup */
+ public static void info(String datasetPath,
+ String datasetDescription,
+ String fusekiServerConfigFile,
+ DataAccessPointRegistry registry) {
Logger log = Fuseki.serverLog;
FmtLog.info(log, "Apache Jena Fuseki");
@@ -49,16 +49,16 @@
// log.error("No dataset path nor server configuration file");
// }
- if ( serverConfig.datasetPath != null ) {
+ if ( datasetPath != null ) {
if ( z.size() != 1 )
log.error("Expected only one dataset");
- List<String> endpoints = z.get(serverConfig.datasetPath);
- FmtLog.info(log, "Dataset Type = %s", serverConfig.datasetDescription);
- FmtLog.info(log, "Path = %s; Services = %s", serverConfig.datasetPath, endpoints);
+ List<String> endpoints = z.get(datasetPath);
+ FmtLog.info(log, "Dataset Type = %s", datasetDescription);
+ FmtLog.info(log, "Path = %s; Services = %s", datasetPath, endpoints);
}
- if ( serverConfig.fusekiServerConfigFile != null ) {
+ if ( fusekiServerConfigFile != null ) {
// May be many datasets and services.
- FmtLog.info(log, "Configuration file %s", serverConfig.fusekiServerConfigFile);
+ FmtLog.info(log, "Configuration file %s", fusekiServerConfigFile);
z.forEach((name, endpoints)->{
FmtLog.info(log, "Path = %s; Services = %s", name, endpoints);
});
@@ -98,7 +98,7 @@
FmtLog.info(log, " OS: %s %s %s", System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"));
}
- public static void logDetailsVerbose(Logger log) {
+ public static void xlogDetailsVerbose(Logger log) {
logDetails(log);
logOne(log, "java.vendor");
logOne(log, "java.home");
@@ -116,21 +116,6 @@
FmtLog.info(log, " %-20s = %s", property, System.getProperty(property));
}
- /** Create a human-friendly string for a number based on Kilo/Mega/Giga/Tera (powers of 2) */
- public static String strNumMixed(long x) {
- // https://en.wikipedia.org/wiki/Kibibyte
- if ( x < 1024 )
- return Long.toString(x);
- if ( x < 1024*1024 )
- return String.format("%.1fK", x/1024.0);
- if ( x < 1024*1024*1024 )
- return String.format("%.1fM", x/(1024.0*1024));
- if ( x < 1024L*1024*1024*1024 )
- return String.format("%.1fG", x/(1024.0*1024*1024));
- return String.format("%.1fT", x/(1024.0*1024*1024*1024));
- }
-
-
/** Create a human-friendly string for a number based on Kilo/Mega/Giga/Tera (powers of 10) */
public static String strNum10(long x) {
if ( x < 1_000 )
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionExecLib.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionExecLib.java
index fc3ff5d..6ce59dc 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionExecLib.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ActionExecLib.java
@@ -32,6 +32,7 @@
import org.apache.jena.atlas.web.HttpException;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.server.*;
+import org.apache.jena.fuseki.system.ActionCategory;
import org.apache.jena.query.QueryCancelledException;
import org.apache.jena.riot.web.HttpNames;
import org.apache.jena.web.HttpSC;
@@ -49,10 +50,10 @@
* @param response HTTP response
* @return a new HTTP Action
*/
- public static HttpAction allocHttpAction(DataAccessPoint dap, Logger log, HttpServletRequest request, HttpServletResponse response) {
+ public static HttpAction allocHttpAction(DataAccessPoint dap, Logger log, ActionCategory category, HttpServletRequest request, HttpServletResponse response) {
long id = allocRequestId(request, response);
// Need a way to set verbose logging on a per servlet and per request basis.
- HttpAction action = new HttpAction(id, log, request, response);
+ HttpAction action = new HttpAction(id, log, category, request, response);
if ( dap != null ) {
// TODO remove setRequest?
DataService dataService = dap.getDataService();
@@ -192,12 +193,17 @@
action.finishRequest();
}
+ private static boolean logLifecycle(HttpAction action) {
+ return action.verbose || action.category != ActionCategory.ADMIN;
+ }
+
/** Log an {@link HttpAction} request. */
public static void logRequest(HttpAction action) {
String url = ActionLib.wholeRequestURL(action.request);
String method = action.request.getMethod();
- FmtLog.info(action.log, "[%d] %s %s", action.id, method, url);
+ if ( logLifecycle(action) )
+ FmtLog.info(action.log, "[%d] %s %s", action.id, method, url);
if ( action.verbose ) {
Enumeration<String> en = action.request.getHeaderNames();
for (; en.hasMoreElements();) {
@@ -238,18 +244,20 @@
String timeStr = fmtMillis(time);
- if ( action.message == null )
- FmtLog.info(action.log, "[%d] %d %s (%s)",
- action.id, action.statusCode, HttpSC.getMessage(action.statusCode), timeStr);
- else
- FmtLog.info(action.log,"[%d] %d %s (%s)", action.id, action.statusCode, action.message, timeStr);
- // Standard format NCSA log.
- if ( Fuseki.requestLog != null && Fuseki.requestLog.isInfoEnabled() ) {
- String s = RequestLog.combinedNCSA(action);
- Fuseki.requestLog.info(s);
+ if ( logLifecycle(action) ) {
+ if ( action.message == null )
+ FmtLog.info(action.log, "[%d] %d %s (%s)",
+ action.id, action.statusCode, HttpSC.getMessage(action.statusCode), timeStr);
+ else
+ FmtLog.info(action.log,"[%d] %d %s (%s)", action.id, action.statusCode, action.message, timeStr);
}
-
- // See also HttpAction.finishRequest - request logging happens there.
+ // Standard format NCSA log.
+ if ( action.category == ActionCategory.ACTION ) {
+ if ( Fuseki.requestLog != null && Fuseki.requestLog.isInfoEnabled() ) {
+ String s = RequestLog.combinedNCSA(action);
+ Fuseki.requestLog.info(s);
+ }
+ }
}
/**
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
index f435717..fa0ea1c 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
@@ -32,6 +32,7 @@
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.FusekiException;
import org.apache.jena.fuseki.server.*;
+import org.apache.jena.fuseki.system.ActionCategory;
import org.apache.jena.query.TxnType;
import org.apache.jena.sparql.SystemARQ;
import org.apache.jena.sparql.core.DatasetGraph;
@@ -48,6 +49,7 @@
{
public final long id;
public final boolean verbose;
+ public final ActionCategory category;
public final Logger log;
// ----
@@ -103,14 +105,14 @@
* @param request HTTP request
* @param response HTTP response
*/
- public HttpAction(long id, Logger log, HttpServletRequest request, HttpServletResponse response) {
+ public HttpAction(long id, Logger log, ActionCategory category, HttpServletRequest request, HttpServletResponse response) {
this.id = id;
- this.log = log;
- this.request = request;
- this.response = new HttpServletResponseTracker(this, response);
- // Should this be set when setDataset is called from the dataset context?
// Currently server-wide, e.g. from the command line.
this.verbose = Fuseki.getVerbose(request.getServletContext());
+ this.log = log;
+ this.category = category;
+ this.request = request;
+ this.response = new HttpServletResponseTracker(this, response);
this.contextPath = request.getServletContext().getContextPath();
this.actionURI = ActionLib.actionURI(request);
this.serviceDispatchRegistry = OperationRegistry.get(request.getServletContext());
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletAction.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletAction.java
index 29799e5..5895b96 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletAction.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletAction.java
@@ -26,6 +26,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.jena.fuseki.system.ActionCategory;
import org.slf4j.Logger;
/**
@@ -57,6 +58,6 @@
}
private HttpAction allocHttpActionServlet(HttpServletRequest request, HttpServletResponse response) {
- return allocHttpAction(null, log, request, response);
+ return allocHttpAction(null, log, ActionCategory.ACTION, request, response);
}
}
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletProcessor.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletProcessor.java
index a461d45..26de8ab 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletProcessor.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ServletProcessor.java
@@ -24,6 +24,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.jena.fuseki.system.ActionCategory;
import org.slf4j.Logger;
/**
@@ -35,12 +36,14 @@
*/
public abstract class ServletProcessor extends HttpServlet implements ActionProcessor {
private final Logger LOG;
+ private final ActionCategory category;
/**
* Constructor for an external {@link ActionProcessor}.
*/
- public ServletProcessor(Logger log) {
+ protected ServletProcessor(Logger log, ActionCategory category) {
this.LOG = log;
+ this.category = category;
}
/**
@@ -53,7 +56,7 @@
}
private HttpAction allocHttpActionServlet(HttpServletRequest request, HttpServletResponse response) {
- HttpAction action = allocHttpAction(null, LOG, request, response);
+ HttpAction action = allocHttpAction(null, LOG, category, request, response);
action.setEndpoint(null);
return action;
}
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/ActionCategory.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/ActionCategory.java
new file mode 100644
index 0000000..f4dba87
--- /dev/null
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/ActionCategory.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.fuseki.system;
+
+/**
+ * Different kinds of request. For example, this is used to modify the logging done.
+ * Control operations do not get the request lifecycle logged; the UI support
+ * operations like ping and stats would otherwise swamp the log.
+ */
+public enum ActionCategory {
+ ACTION, // Normal operations
+ ADMIN // Control and admin
+}
+
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/FusekiLogging.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/FusekiLogging.java
index 0dbea92..bfb10f4 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/FusekiLogging.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/system/FusekiLogging.java
@@ -44,7 +44,7 @@
/**
* Places for the log4j properties file at (3).
- * This is not the standard, fixed classpath names used by log4j.
+ * This is not the standard, fixed classpath names used by log4j.
* // log4j2.properties, log4j2.yaml, log4j2.json, log4j2.xml
*/
@@ -84,7 +84,7 @@
public static final String log4j2_configurationFile = "log4j.configurationFile";
public static final String log4j2_web_configuration = "log4jConfiguration";
-
+
/** Set up logging. Allow an extra location (string directory name without trailing "/"). This may be null
*
* @param extraDir
@@ -143,7 +143,7 @@
// Stop anything attempting to do it again.
System.setProperty(log4j2_configurationFile, "set");
}
-
+
private static boolean checkSystemProperties(String... properties) {
String x = null;
for ( String propertyName : properties ) {
@@ -161,7 +161,7 @@
private static void loadConfiguration(InputStream inputStream, String resourceName) throws IOException {
ConfigurationSource source = new ConfigurationSource(inputStream);
- ConfigurationFactory factory;
+ ConfigurationFactory factory;
if ( resourceName.endsWith(".properties" ) )
factory = new PropertiesConfigurationFactory();
else
@@ -232,9 +232,6 @@
, "logger.fuseki.name = org.apache.jena.fuseki"
, "logger.fuseki.level = INFO"
, ""
- , "logger.fuseki-request.name = org.apache.jena.fuseki.Request"
- , "logger.fuseki-request.level = INFO"
- ,""
, "logger.fuseki-fuseki.name = org.apache.jena.fuseki.Fuseki"
, "logger.fuseki-fuseki.level = INFO"
,""
@@ -242,10 +239,10 @@
, "logger.fuseki-server.level = INFO"
,""
, "logger.fuseki-config.name = org.apache.jena.fuseki.Config"
- , "logger.fuseki-config.level = WARN"
+ , "logger.fuseki-config.level = INFO"
,""
, "logger.fuseki-admin.name = org.apache.jena.fuseki.Admin"
- , "logger.fuseki-admin.level = WARN"
+ , "logger.fuseki-admin.level = INFO"
,""
, "logger.jetty.name = org.eclipse.jetty"
, "logger.jetty.level = WARN"
@@ -265,14 +262,14 @@
, "appender.plain.layout.type = PatternLayout"
, "appender.plain.layout.pattern = %m%n"
, ""
- , "logger.request-log.name = org.apache.jena.fuseki.Request"
- , "logger.request-log.additivity = false"
- , "logger.request-log.level = OFF"
- , "logger.request-log.appenderRef.plain.ref = PLAIN"
+ , "logger.fuseki-request.name = org.apache.jena.fuseki.Request"
+ , "logger.fuseki-request.additivity = false"
+ , "logger.fuseki-request.level = OFF"
+ , "logger.fuseki-request.appenderRef.plain.ref = PLAIN"
);
// @formatter:on
}
-
+
public static void resetLogging(String configString) {
LogCmd.resetLogging(configString);
}