Skip to content

Commit

Permalink
Decouple FusekiLogging from the webapp.
Browse files Browse the repository at this point in the history
Pass in an addition allocation to look for a log4j1 properties file.
  • Loading branch information
afs committed Aug 25, 2018
1 parent 689c4cf commit 2490112
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public class FusekiCmd {
// statics of a class are run.

static {
FusekiEnv.mode = FusekiEnv.INIT.STANDALONE ;
FusekiLogging.setLogging() ;
FusekiEnv.mode = FusekiEnv.INIT.STANDALONE;
FusekiEnv.setEnvironment();
FusekiLogging.setLogging(FusekiEnv.FUSEKI_BASE);
}

static public void main(String... argv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import java.io.File ;
import java.net.URL ;
import java.nio.file.Path;

import org.apache.jena.atlas.lib.StrUtils ;
import org.apache.jena.atlas.logging.LogCtl ;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.webapp.FusekiEnv;
import org.apache.jena.riot.SysRIOT ;
import org.apache.log4j.PropertyConfigurator ;
import org.apache.log4j.helpers.Loader ;
Expand Down Expand Up @@ -65,12 +65,20 @@ public static synchronized void allowLoggingReset(boolean value) {

/** Set up logging - standalone and war packaging */
public static synchronized void setLogging() {
setLogging(null);

}

/** Set up logging. Allow an extra location (string directory name without trailing "/"). This may be null
*
* @param extraDir
*/
public static synchronized void setLogging(Path extraDir) {
if ( ! allowLoggingReset )
return ;
if ( loggingInitialized )
return ;
loggingInitialized = true ;
FusekiEnv.setEnvironment() ;

logLogging("Fuseki logging") ;
// No loggers have been created but configuration may have been set up.
Expand All @@ -86,12 +94,12 @@ public static synchronized void setLogging() {
}
logLogging("Fuseki logging - setup") ;
// Look for a log4j.properties in the current working directory
// and an existing FUSEKI_BASE for easy customization.
// and a plane (e.g. FUSEKI_BASE in the webapp/full server) for easy customization.
String fn1 = "log4j.properties" ;
String fn2 = null ;

if ( FusekiEnv.FUSEKI_BASE != null )
fn2 = FusekiEnv.FUSEKI_BASE.toString()+"/log4j.properties" ;
if ( extraDir != null )
fn2 = extraDir.resolve("log4j.properties").toString() ;
if ( attempt(fn1) ) return ;
if ( attempt(fn2) ) return ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public FusekiServerEnvironmentInit() { }

@Override
public void contextInitialized(ServletContextEvent sce) {
FusekiLogging.setLogging();
JenaSystem.init() ;
// These two do not touch Jena.
FusekiEnv.setEnvironment() ;
FusekiLogging.setLogging(FusekiEnv.FUSEKI_BASE);
JenaSystem.init() ;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class TS_Fuseki extends ServerTest
FileOps.ensureDir(FusekiTestHome);
FileOps.clearDirectory(FusekiTestHome);
System.setProperty("FUSEKI_HOME", FusekiTestHome) ;
FusekiLogging.setLogging();
FusekiEnv.setEnvironment() ;
FusekiLogging.setLogging();
// To avoid confusion with log4j.properties in the main part of the server,
// we modify in place the logging, not try to set it with another
// Log4j properties file from the classpath.
Expand Down

0 comments on commit 2490112

Please sign in to comment.