Skip to content

Commit

Permalink
Align logging across the servers
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Dec 31, 2024
1 parent 8531df4 commit 7f5e2f5
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static void logCode(Logger log) {
}

/** Log details - this function is about command line details */
// Shared between FusekiMain and Fuseki Webapp (currently).
public static void logServerCmdSetup(Logger log, boolean verbose, DataAccessPointRegistry dapRegistry,
String datasetPath, String datasetDescription, String serverConfigFile, String staticFiles) {
if ( datasetPath != null )
Expand All @@ -46,16 +45,11 @@ public static void logServerCmdSetup(Logger log, boolean verbose, DataAccessPoin
FmtLog.info(log, "Configuration file: %s", serverConfigFile);

FusekiCoreInfo.logDataAccessPointRegistry(log, dapRegistry, verbose);

if ( staticFiles != null )
FmtLog.info(log, "Static files: %s", staticFiles);

if ( verbose ) {
PlatformInfo.logDetailsSystem(log);
PlatformInfo.logDetailsSystem(log);
if ( verbose )
PlatformInfo.logDetailsJVM(log);
}
else
PlatformInfo.logDetailsSystemPlain(log);
}

/** Log a {@link DataAccessPointRegistry} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.apache.jena.atlas.logging.FmtLog;
import org.slf4j.Logger;

public class PlatformInfo {
/** Platform inforamtion - OS and JVM */
/*package*/ class PlatformInfo {

public static void main(String ...args) throws IOException {
long maxMem = Runtime.getRuntime().maxMemory();
Expand All @@ -35,14 +36,8 @@ public static void main(String ...args) throws IOException {
System.out.printf("max=%s total=%s used=%s free=%s\n", f.apply(maxMem), f.apply(totalMem), f.apply(usedMem), f.apply(freeMem));
}

/** System details section */
public static void logDetailsSystem(Logger log) {
log.info("System");
logDetailsSystemPlain(log);
}

/** System details, no section header */
public static void logDetailsSystemPlain(Logger log) {
/** System details */
/*package*/ static void logDetailsSystem(Logger log) {
String prefix = " ";
long maxMem = Runtime.getRuntime().maxMemory();
long totalMem = Runtime.getRuntime().totalMemory();
Expand All @@ -60,19 +55,16 @@ public static void logDetailsSystemPlain(Logger log) {
}

/** JVM details section. */
public static void logDetailsJVM(Logger log) {
/*package*/ static void logDetailsJVM(Logger log) {
String prefix = " ";
log.info("Java");
logOne(log, prefix, "java.vendor");
logOne(log, prefix, "java.home");
logOne(log, prefix, "java.runtime.version");
logOne(log, prefix, "java.runtime.name");
//logOne(log, "java.endorsed.dirs");
logOne(log, prefix, "user.language");
logOne(log, prefix, "user.timezone");
logOne(log, prefix, "user.country");
logOne(log, prefix, "user.dir");
//logOne(log, prefix, "file.encoding");
}

private static void logOne(Logger log, String prefix, String property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ private static void logLogging(String fmt, Object ... args) {
}

private static String log4j2setupFallback() {
// The logging file for Fuseki in Tomcat webapp is in "log4j2.properties" in the webapp root directory.
// This is used by command line Fuseki (full and main)
// This is the default

// filters = threshold
// filter.threshold.type = ThresholdFilter
Expand All @@ -247,6 +246,7 @@ private static String log4j2setupFallback() {
appender.console.name = OUT
appender.console.target = SYSTEM_OUT
appender.console.layout.type = PatternLayout
##appender.console.layout.pattern = %d{HH:mm:ss} %-5p %-15c{1} :: %m%n
appender.console.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] %-10c{1} %-5p %m%n
rootLogger.level = WARN
Expand Down Expand Up @@ -297,8 +297,7 @@ private static String log4j2setupFallback() {
logger.fuseki-request.additivity = false
logger.fuseki-request.level = OFF
logger.fuseki-request.appenderRef.plain.ref = PLAIN
);
""";
""";
}

public static void resetLogging(String configString) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.jena.cmd.*;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.FusekiException;
import org.apache.jena.fuseki.main.FusekiInfo;
import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.fuseki.main.sys.FusekiModules;
import org.apache.jena.fuseki.main.sys.FusekiServerArgsCustomiser;
Expand Down Expand Up @@ -645,7 +644,7 @@ protected void exec() {
// Check for command line or config setup.
try {
Logger log = Fuseki.serverLog;
FusekiInfo.logServerCode(log);
FusekiCoreInfo.logCode(log);
FusekiServer server = makeServer(serverArgs);
infoCmd(server, log);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class FusekiServerCmd {
* syntax but not start it.
*/
static public void main(String... args) {
FusekiServerRunner.runAsync(args).join();
FusekiServerRunner.main(args);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private static Path writeableDirectory(Path root , String relName ) {
return p;
}

/** Running a full-features server set some global state. Clear this up. (mainly for tests.)*/
/** Running a full-features server sets some global state. Clear this up. (mainly for tests.)*/
public static void clearUpSystemState() {
System.getProperties().remove(FusekiServerCtl.envFusekiShiro);
System.getProperties().remove(FusekiServerCtl.envFusekiBase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

package org.apache.jena.fuseki.mod;

import java.net.BindException;

import org.apache.jena.atlas.lib.FileOps;
import org.apache.jena.atlas.lib.Lib;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.FusekiException;
import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.fuseki.main.cmds.FusekiMain;
import org.apache.jena.fuseki.main.cmds.ServerArgs;
Expand All @@ -36,14 +40,40 @@
public class FusekiServerRunner {

public static void main(String... args) {
runAsync(args).join();
//runAsync(args).join();
prepareFusekiMain();
FusekiMain.run(args);
}

public static FusekiServer runAsync(String... args) {
return construct(args).start();
FusekiServer server = construct(args);
try {
server.start();
} catch (FusekiException ex) {
if ( ex.getCause() instanceof BindException ) {
// if ( serverArgs.jettyConfigFile == null )
// Fuseki.serverLog.error("Failed to start server: "+ex.getCause().getMessage()+ ": port="+serverArgs.port);
// else
// Fuseki.serverLog.error("Failed to start server: "+ex.getCause().getMessage()+ ": port in use");
Fuseki.serverLog.error("Failed to start server: "+ex.getCause().getMessage()+ ": port in use");
System.exit(1);
}
throw ex;
} catch (Exception ex) {
throw new FusekiException("Failed to start server: " + ex.getMessage(), ex);
}
return server.start();
}

public static FusekiServer construct(String... args) {
prepareFusekiMain();
// Make server
FusekiServer server = FusekiServer.construct(args);
resetFusekiMain();
return server;
}

private static void prepareFusekiMain() {
String fusekiBase = Lib.getenv(FusekiServerCtl.envFusekiBase);
if ( fusekiBase == null )
fusekiBase = FusekiServerCtl.dftFusekiBase;
Expand All @@ -64,20 +94,21 @@ public void serverArgsModify(CmdGeneral fusekiCmd, ServerArgs serverArgs) {
FusekiMain.addCustomiser(initializeServerArgs);
// They can also modify the argument processing.
serverModules.forEach(FusekiMain::addCustomiser);
// Make server
FusekiServer server = FusekiServer.construct(args);
return server;
}

/** A use-once {@link FusekiModules} for the fill-featured Fuseki server. */
private static void resetFusekiMain() {
FusekiMain.resetCustomisers();
}

/** A use-once {@link FusekiModules} for the full-featured Fuseki server. */
public static FusekiModules serverModules() {
// Modules may have state that is carried across the build steps or used for reload.
FusekiModule fmodShiro = FMod_Shiro.create();
FusekiModule fmodAdmin = FMod_Admin.create();
FusekiModule fmodUI = FMod_UI.create();
FusekiModule fmodPrometheus = FMod_Prometheus.create();

FusekiModules serverModules = FusekiModules.create(fmodAdmin, fmodUI, fmodShiro, fmodPrometheus );
FusekiModules serverModules = FusekiModules.create(fmodAdmin, fmodUI, fmodShiro, fmodPrometheus);
return serverModules;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void customizeEnvironment(WebEnvironment environment) {
shiroConfigLog.info(format("No Shiro file found (tried: %s)", locations));
return;
}
shiroConfigLog.info("Shiro INI: "+loc);
shiroConfigLog.info("Shiro file: "+loc);
String[] configLocationsHere = new String[] {loc};
env.setConfigLocations(configLocationsHere);
}
Expand Down

0 comments on commit 7f5e2f5

Please sign in to comment.