You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2014/12/18 15:34:31 UTC
[1/2] jena git commit: Logging
Repository: jena
Updated Branches:
refs/heads/master 4ea4846cb -> 19f917ed1
Logging
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/0c5450ae
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/0c5450ae
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/0c5450ae
Branch: refs/heads/master
Commit: 0c5450ae63b204dfbe79a3d3abd3c518b00a8c95
Parents: 4ea4846
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Dec 18 14:23:46 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Dec 18 14:23:46 2014 +0000
----------------------------------------------------------------------
.../org/apache/jena/fuseki/FusekiLogging.java | 130 ++++++++++---------
1 file changed, 71 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/0c5450ae/jena-fuseki2/src/main/java/org/apache/jena/fuseki/FusekiLogging.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/FusekiLogging.java b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/FusekiLogging.java
index 707cc5d..8bab4f1 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/FusekiLogging.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/FusekiLogging.java
@@ -29,66 +29,23 @@ import org.apache.log4j.helpers.Loader ;
public class FusekiLogging
{
- private static String log4Jsetup = StrUtils.strjoinNL
- // Preferred: classes/log4j.properties, from src/main/resources/log4j.properties
- // Keep these in-step. Different usages cause different logging initalizations.
- ("## Plain output to stdout",
- "log4j.appender.jena.plainstdout=org.apache.log4j.ConsoleAppender",
- "log4j.appender.jena.plainstdout.target=System.out",
- "log4j.appender.jena.plainstdout.layout=org.apache.log4j.PatternLayout",
- "log4j.appender.jena.plainstdout.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-10c{1} %-5p %m%n",
- //"log4j.appender.jena.plainstdout.layout.ConversionPattern=%d{HH:mm:ss} %-10c{1} %-5p %m%n",
-
- "## Plain output to stderr",
- "log4j.appender.jena.plainstderr=org.apache.log4j.ConsoleAppender",
- "log4j.appender.jena.plainstderr.target=System.err",
- "log4j.appender.jena.plainstderr.layout=org.apache.log4j.PatternLayout",
- //"log4j.appender.jena.plainstderr.layout.ConversionPattern=%d{HH:mm:ss} %-10c{1} %-5p %m%n",
- "log4j.appender.jena.plainstderr.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-10c{1} %-5p %m%n",
-
- "## Everything",
- "log4j.rootLogger=INFO, jena.plainstdout",
- "log4j.logger.com.hp.hpl.jena=WARN",
- "log4j.logger.org.openjena=WARN",
- "log4j.logger.org.apache.jena=WARN",
-
- "log4j.logger.org.apache.jena=WARN",
-
- "# System logs.",
- "log4j.logger." + Fuseki.serverLogName + "=INFO",
- "log4j.logger." + Fuseki.actionLogName + "=INFO",
- "log4j.logger." + Fuseki.adminLogName + "=INFO",
- "log4j.logger." + Fuseki.validationLogName + "=INFO",
- "log4j.logger." + Fuseki.configLogName + "=INFO",
-
- "log4j.logger.org.apache.jena.tdb.loader=INFO",
- "log4j.logger.org.eclipse.jetty=WARN" ,
- "log4j.logger.org.apache.shiro=WARN",
-
- "# NCSA RequestAccess log",
- "log4j.appender.plain=org.apache.log4j.ConsoleAppender",
- "log4j.appender.plain.target=System.out",
- "log4j.appender.plain.layout=org.apache.log4j.PatternLayout",
- "log4j.appender.plain.layout.ConversionPattern=%m%n",
- "log4j.additivity."+Fuseki.requestLogName + "=false",
- "log4j.logger."+Fuseki.requestLogName + "=INFO, plain",
-
- "## Parser output",
- "log4j.additivity" + SysRIOT.riotLoggerName + "=false",
- "log4j.logger." + SysRIOT.riotLoggerName + "=INFO, plainstdout"
- ) ;
+ // This class must not have static constants, or otherwise not use "Fuseki.*"
+ // or any class else where that might kick off logging. Otherwise, the
+ // setLogging is poiintless (it's already set).
+ // PlanB - reinitilize logging regardless on first call.
+
// Set logging.
- // 1/ Use log4j.configuration is defined.
- // 2/ Use file:log4j.properties
+ // 1/ Use log4j.configuration if defined.
+ // 2/ Use file:log4j.properties if exists
// 3/ Use log4j.properties on the classpath.
// 4/ Use Built in.
// Using FusekiCmd causes
- private static boolean LogLogging = false ;
+ private static final boolean LogLogging = false ;
private static boolean loggingInitialized = false ;
- public static void setLogging() {
+ public static synchronized void setLogging() {
if ( loggingInitialized )
return ;
loggingInitialized = true ;
@@ -98,15 +55,18 @@ public class FusekiLogging
String x = System.getProperty("log4j.configuration", null) ;
logLogging("log4j.configuration = %s", x) ;
- if ( x != null ) // && !x.equals("set") )
- // Punt to log4j proper, or maybe already set.
- // "set" indicates that logging was set before.
+ if ( x != null ) {
+ // log4j wil initialize in the usual way. This includes avalue of
+ // "set", which indicates that logging was set before by some other Jena code.
+ if ( x.equals("set") )
+ Fuseki.serverLog.warn("Fuseki logging: Unexpected: Log4j was setup by someother part of Jena") ;
return ;
+ }
logLogging("Fuseki logging - setup") ;
// Look for a log4j.properties in the current working directory for easy
// customization.
try {
- logLogging("Fuseki logging - look for local log4j.properties") ;
+ logLogging("Fuseki logging - look for file:log4j.properties") ;
String fn = "log4j.properties" ;
File f = new File(fn) ;
if ( f.exists() ) {
@@ -124,18 +84,18 @@ public class FusekiLogging
// The log4j general initialization is done in a class static
// in LogManager so it can't be called again in any sensible manner.
// Instead, we include the same basic mechanism ...
- logLogging("Fuseki logging - look for URL log4j.properties") ;
+ logLogging("Fuseki logging - classpath log4j.properties") ;
URL url = Loader.getResource("log4j.properties") ;
if ( url != null ) {
PropertyConfigurator.configure(url) ;
- logLogging("Fuseki logging - found = %s", url) ;
+ logLogging("Fuseki logging - found via classpath %s", url) ;
System.setProperty("log4j.configuration", url.toString()) ;
return ;
}
logLogging("Fuseki logging - Use built-in") ;
// Use builtin.
- LogCtl.resetLogging(log4Jsetup) ;
+ LogCtl.resetLogging(log4Jsetup()) ;
// Stop anything attempting to do it again.
System.setProperty("log4j.configuration", "set") ;
}
@@ -146,5 +106,57 @@ public class FusekiLogging
System.out.println() ;
}
}
+
+ private static String log4Jsetup() {
+ return StrUtils.strjoinNL
+ // Preferred: classes/log4j.properties, from src/main/resources/log4j.properties
+ // Keep these in-step. Different usages cause different logging initalizations;
+ // if the jar is rebundled, it may loose the associated log4.properties file.
+ ("## Plain output to stdout",
+ "log4j.appender.jena.plainstdout=org.apache.log4j.ConsoleAppender",
+ "log4j.appender.jena.plainstdout.target=System.out",
+ "log4j.appender.jena.plainstdout.layout=org.apache.log4j.PatternLayout",
+ "log4j.appender.jena.plainstdout.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-10c{1} %-5p %m%n",
+ //"log4j.appender.jena.plainstdout.layout.ConversionPattern=%d{HH:mm:ss} %-10c{1} %-5p %m%n",
+
+ "## Plain output to stderr",
+ "log4j.appender.jena.plainstderr=org.apache.log4j.ConsoleAppender",
+ "log4j.appender.jena.plainstderr.target=System.err",
+ "log4j.appender.jena.plainstderr.layout=org.apache.log4j.PatternLayout",
+ //"log4j.appender.jena.plainstderr.layout.ConversionPattern=%d{HH:mm:ss} %-10c{1} %-5p %m%n",
+ "log4j.appender.jena.plainstderr.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %-10c{1} %-5p %m%n",
+
+ "## Everything",
+ "log4j.rootLogger=INFO, jena.plainstdout",
+ "log4j.logger.com.hp.hpl.jena=WARN",
+ "log4j.logger.org.openjena=WARN",
+ "log4j.logger.org.apache.jena=WARN",
+
+ "log4j.logger.org.apache.jena=WARN",
+
+ "# System logs.",
+ "log4j.logger." + Fuseki.serverLogName + "=INFO",
+ "log4j.logger." + Fuseki.actionLogName + "=INFO",
+ "log4j.logger." + Fuseki.adminLogName + "=INFO",
+ "log4j.logger." + Fuseki.validationLogName + "=INFO",
+ "log4j.logger." + Fuseki.configLogName + "=INFO",
+
+ "log4j.logger.org.apache.jena.tdb.loader=INFO",
+ "log4j.logger.org.eclipse.jetty=WARN" ,
+ "log4j.logger.org.apache.shiro=WARN",
+
+ "# NCSA RequestAccess log",
+ "log4j.appender.plain=org.apache.log4j.ConsoleAppender",
+ "log4j.appender.plain.target=System.out",
+ "log4j.appender.plain.layout=org.apache.log4j.PatternLayout",
+ "log4j.appender.plain.layout.ConversionPattern=%m%n",
+ "log4j.additivity."+Fuseki.requestLogName + "=false",
+ "log4j.logger."+Fuseki.requestLogName + "=INFO, plain",
+
+ "## Parser output",
+ "log4j.additivity" + SysRIOT.riotLoggerName + "=false",
+ "log4j.logger." + SysRIOT.riotLoggerName + "=INFO, plainstdout"
+ ) ;
+ }
}
[2/2] jena git commit: Log initialization errors.
Posted by an...@apache.org.
Log initialization errors.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/19f917ed
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/19f917ed
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/19f917ed
Branch: refs/heads/master
Commit: 19f917ed15954707a7742e868599beb41e081c76
Parents: 0c5450a
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Dec 18 14:34:06 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Dec 18 14:34:06 2014 +0000
----------------------------------------------------------------------
.../apache/jena/fuseki/server/FusekiServer.java | 143 ++++++++++---------
1 file changed, 74 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/19f917ed/jena-fuseki2/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
index 9e84df2..8dd62b5 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
@@ -121,79 +121,84 @@ public class FusekiServer
if ( initialized )
return ;
initialized = true ;
- Fuseki.init() ;
-
- // ---- Set and check FUSEKI_HOME and FUSEKI_BASE
-
- if ( FUSEKI_HOME == null ) {
- // Make absolute
- String x1 = FusekiLib.getenv("FUSEKI_HOME") ;
- if ( x1 != null )
- FUSEKI_HOME = Paths.get(x1) ;
- }
-
- if ( FUSEKI_BASE == null ) {
- String x2 = FusekiLib.getenv("FUSEKI_BASE") ;
- if ( x2 != null )
- FUSEKI_BASE = Paths.get(x2) ;
- else {
- if ( FUSEKI_HOME != null )
- FUSEKI_BASE = FUSEKI_HOME.resolve(runArea) ;
- else
- // Neither FUSEKI_HOME nor FUSEKI_BASE set.
- FUSEKI_BASE = Paths.get(DFT_FUSEKI_BASE) ;
+ try {
+ Fuseki.init() ;
+
+ // ---- Set and check FUSEKI_HOME and FUSEKI_BASE
+
+ if ( FUSEKI_HOME == null ) {
+ // Make absolute
+ String x1 = FusekiLib.getenv("FUSEKI_HOME") ;
+ if ( x1 != null )
+ FUSEKI_HOME = Paths.get(x1) ;
}
- }
-
- if ( FUSEKI_HOME != null )
- FUSEKI_HOME = FUSEKI_HOME.toAbsolutePath() ;
-
- FUSEKI_BASE = FUSEKI_BASE.toAbsolutePath() ;
-
- Fuseki.configLog.info("FUSEKI_HOME="+ ((FUSEKI_HOME==null) ? "unset" : FUSEKI_HOME.toString())) ;
- Fuseki.configLog.info("FUSEKI_BASE="+FUSEKI_BASE.toString());
- // If FUSEKI_HOME exists, it may be FUSEKI_BASE.
-
- if ( FUSEKI_HOME != null ) {
- if ( ! Files.isDirectory(FUSEKI_HOME) )
- throw new FusekiConfigException("FUSEKI_HOME is not a directory: "+FUSEKI_HOME) ;
- if ( ! Files.isReadable(FUSEKI_HOME) )
- throw new FusekiConfigException("FUSEKI_HOME is not readable: "+FUSEKI_HOME) ;
- }
-
- if ( Files.exists(FUSEKI_BASE) ) {
- if ( ! Files.isDirectory(FUSEKI_BASE) )
- throw new FusekiConfigException("FUSEKI_BASE is not a directory: "+FUSEKI_BASE) ;
- if ( ! Files.isWritable(FUSEKI_BASE) )
- throw new FusekiConfigException("FUSEKI_BASE is not writable: "+FUSEKI_BASE) ;
- } else {
- ensureDir(FUSEKI_BASE);
- }
+ if ( FUSEKI_BASE == null ) {
+ String x2 = FusekiLib.getenv("FUSEKI_BASE") ;
+ if ( x2 != null )
+ FUSEKI_BASE = Paths.get(x2) ;
+ else {
+ if ( FUSEKI_HOME != null )
+ FUSEKI_BASE = FUSEKI_HOME.resolve(runArea) ;
+ else
+ // Neither FUSEKI_HOME nor FUSEKI_BASE set.
+ FUSEKI_BASE = Paths.get(DFT_FUSEKI_BASE) ;
+ }
+ }
- // Ensure FUSEKI_BASE has the assumed directories.
- dirTemplates = writeableDirectory(FUSEKI_BASE, templatesNameBase) ;
- dirDatabases = writeableDirectory(FUSEKI_BASE, databasesLocationBase) ;
- dirBackups = writeableDirectory(FUSEKI_BASE, backupDirNameBase) ;
- dirConfiguration = writeableDirectory(FUSEKI_BASE, configDirNameBase) ;
- dirLogs = writeableDirectory(FUSEKI_BASE, logsNameBase) ;
- dirSystemDatabase = writeableDirectory(FUSEKI_BASE, systemDatabaseNameBase) ;
- dirFileArea = writeableDirectory(FUSEKI_BASE, systemFileAreaBase) ;
- //Possible intercept poiint
-
- // ---- Initialize with files.
-
- if ( Files.isRegularFile(FUSEKI_BASE) )
- throw new FusekiConfigException("FUSEKI_BASE exists but is a file") ;
-
- // Copy missing files into FUSEKI_BASE
- copyFileIfMissing(null, DFT_SHIRO_INI, FUSEKI_BASE) ;
- copyFileIfMissing(null, DFT_CONFIG, FUSEKI_BASE) ;
- for ( String n : Template.templateNames ) {
- copyFileIfMissing(null, n, FUSEKI_BASE) ;
+ if ( FUSEKI_HOME != null )
+ FUSEKI_HOME = FUSEKI_HOME.toAbsolutePath() ;
+
+ FUSEKI_BASE = FUSEKI_BASE.toAbsolutePath() ;
+
+ Fuseki.configLog.info("FUSEKI_HOME="+ ((FUSEKI_HOME==null) ? "unset" : FUSEKI_HOME.toString())) ;
+ Fuseki.configLog.info("FUSEKI_BASE="+FUSEKI_BASE.toString());
+
+ // If FUSEKI_HOME exists, it may be FUSEKI_BASE.
+
+ if ( FUSEKI_HOME != null ) {
+ if ( ! Files.isDirectory(FUSEKI_HOME) )
+ throw new FusekiConfigException("FUSEKI_HOME is not a directory: "+FUSEKI_HOME) ;
+ if ( ! Files.isReadable(FUSEKI_HOME) )
+ throw new FusekiConfigException("FUSEKI_HOME is not readable: "+FUSEKI_HOME) ;
+ }
+
+ if ( Files.exists(FUSEKI_BASE) ) {
+ if ( ! Files.isDirectory(FUSEKI_BASE) )
+ throw new FusekiConfigException("FUSEKI_BASE is not a directory: "+FUSEKI_BASE) ;
+ if ( ! Files.isWritable(FUSEKI_BASE) )
+ throw new FusekiConfigException("FUSEKI_BASE is not writable: "+FUSEKI_BASE) ;
+ } else {
+ ensureDir(FUSEKI_BASE);
+ }
+
+ // Ensure FUSEKI_BASE has the assumed directories.
+ dirTemplates = writeableDirectory(FUSEKI_BASE, templatesNameBase) ;
+ dirDatabases = writeableDirectory(FUSEKI_BASE, databasesLocationBase) ;
+ dirBackups = writeableDirectory(FUSEKI_BASE, backupDirNameBase) ;
+ dirConfiguration = writeableDirectory(FUSEKI_BASE, configDirNameBase) ;
+ dirLogs = writeableDirectory(FUSEKI_BASE, logsNameBase) ;
+ dirSystemDatabase = writeableDirectory(FUSEKI_BASE, systemDatabaseNameBase) ;
+ dirFileArea = writeableDirectory(FUSEKI_BASE, systemFileAreaBase) ;
+ //Possible intercept point
+
+ // ---- Initialize with files.
+
+ if ( Files.isRegularFile(FUSEKI_BASE) )
+ throw new FusekiConfigException("FUSEKI_BASE exists but is a file") ;
+
+ // Copy missing files into FUSEKI_BASE
+ copyFileIfMissing(null, DFT_SHIRO_INI, FUSEKI_BASE) ;
+ copyFileIfMissing(null, DFT_CONFIG, FUSEKI_BASE) ;
+ for ( String n : Template.templateNames ) {
+ copyFileIfMissing(null, n, FUSEKI_BASE) ;
+ }
+
+ serverInitialized = true ;
+ } catch (RuntimeException ex) {
+ Fuseki.serverLog.error("Exception in server initialization", ex) ;
+ throw ex ;
}
-
- serverInitialized = true ;
}
private static boolean emptyDir(Path dir) {