You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/12/20 11:19:46 UTC
svn commit: r605865 - in
/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app:
BootstrapInstaller.java Logger.java Sling.java main/Main.java
main/SimpleLogger.java
Author: fmeschbe
Date: Thu Dec 20 02:19:45 2007
New Revision: 605865
URL: http://svn.apache.org/viewvc?rev=605865&view=rev
Log:
SLING-143 Replace internal Logger interface with Felix Framework Logger
Removed:
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Logger.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/SimpleLogger.java
Modified:
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java
incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java
Modified: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java?rev=605865&r1=605864&r2=605865&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java Thu Dec 20 02:19:45 2007
@@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.felix.framework.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -110,7 +111,7 @@
/**
* Install the Bundles from JAR files found in the given <code>parent</code>
* path.
- *
+ *
* @param context The <code>BundleContext</code> used to install the new
* Bundles.
* @param currentBundles The currently installed Bundles indexed by their
@@ -124,12 +125,12 @@
private void installBundles(BundleContext context,
Map<String, Bundle> currentBundles, String parent,
List<Bundle> installed) {
-
+
Iterator<String> res = resourceProvider.getChildren(parent);
while (res.hasNext()) {
-
+
String path = res.next();
-
+
if (path.endsWith(".jar")) {
// check for an already installed Bundle with the given location
@@ -149,11 +150,12 @@
Bundle newBundle;
try {
newBundle = context.installBundle(location, ins);
- logger.log("Bundle " + newBundle.getSymbolicName()
- + " installed from " + location);
+ logger.log(Logger.LOG_INFO, "Bundle "
+ + newBundle.getSymbolicName() + " installed from "
+ + location);
} catch (BundleException be) {
- logger.log("Bundle installation from " + location
- + " failed", be);
+ logger.log(Logger.LOG_ERROR, "Bundle installation from "
+ + location + " failed", be);
continue;
}
@@ -186,8 +188,8 @@
try {
bundle.start();
} catch (BundleException be) {
- logger.log("Bundle " + bundle.getSymbolicName()
- + " could not be started", be);
+ logger.log(Logger.LOG_ERROR, "Bundle "
+ + bundle.getSymbolicName() + " could not be started", be);
}
}
Modified: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java?rev=605865&r1=605864&r2=605865&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/Sling.java Thu Dec 20 02:19:45 2007
@@ -40,6 +40,7 @@
import java.util.Map.Entry;
import org.apache.felix.framework.Felix;
+import org.apache.felix.framework.Logger;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -215,7 +216,7 @@
this.logger = logger;
this.resourceProvider = resourceProvider;
- this.logger.log("Starting Sling");
+ this.logger.log(Logger.LOG_INFO, "Starting Sling");
// read the default parameters
Map<String, String> props = this.loadConfigProperties(propOverwrite);
@@ -238,14 +239,15 @@
activators.add(new BootstrapInstaller(logger, resourceProvider));
// create the framework and start it
- Felix tmpFelix = new Felix(props, activators);
+ Felix tmpFelix = new Felix(logger, props, activators);
tmpFelix.start();
// only assign field if start succeeds
this.felix = tmpFelix;
// log sucess message
- this.logger.log("Sling Instance " + props.get(SLING_ID) + " started");
+ this.logger.log(Logger.LOG_INFO, "Sling Instance "
+ + props.get(SLING_ID) + " started");
}
/**
@@ -257,9 +259,9 @@
if (felix != null) {
String label = "Sling Instance "
+ felix.getBundleContext().getProperty(SLING_ID);
- logger.log("Shutting down " + label);
+ logger.log(Logger.LOG_INFO, "Shutting down " + label);
felix.stopAndWait();
- logger.log(label + " stopped");
+ logger.log(Logger.LOG_INFO, label + " stopped");
felix = null;
}
}
@@ -307,7 +309,7 @@
try {
this.doStopBundle();
} catch (Exception e) {
- this.logger.log("Unexpected exception caught", e);
+ this.logger.log(Logger.LOG_ERROR, "Unexpected exception caught", e);
}
// drop bundle context reference
@@ -358,8 +360,8 @@
slingHome = props.get(SLING_HOME);
if (slingHome == null || slingHome.length() == 0) {
slingHome = "sling";
- this.logger.log("sling.home is not defined. Using '"
- + slingHome + "'");
+ this.logger.log(Logger.LOG_INFO,
+ "sling.home is not defined. Using '" + slingHome + "'");
}
}
@@ -369,7 +371,7 @@
slingHome = slingHomeFile.getAbsolutePath();
// overlay with ${sling.home}/sling.properties
- this.logger.log("Starting sling in " + slingHome);
+ this.logger.log(Logger.LOG_INFO, "Starting sling in " + slingHome);
File propFile = new File(slingHome, CONFIG_PROPERTIES);
this.load(props, propFile);
@@ -442,8 +444,8 @@
origProps.put(name, "${sling.home}" + path);
} catch (IOException ioe) {
- this.logger.log("Cannot copy file " + value + " to "
- + target, ioe);
+ this.logger.log(Logger.LOG_ERROR, "Cannot copy file "
+ + value + " to " + target, ioe);
} finally {
if (dest != null) {
try {
@@ -473,7 +475,7 @@
tmp.putAll(origProps);
tmp.store(os, "Overlay properties for configuration");
} catch (Exception ex) {
- this.logger.log(
+ this.logger.log(Logger.LOG_ERROR,
"Error loading overlay properties from " + propFile, ex);
} finally {
if (os != null) {
@@ -596,10 +598,12 @@
}
}
- this.logger.log("Using Execution Environment setting: " + ee);
+ this.logger.log(Logger.LOG_INFO,
+ "Using Execution Environment setting: " + ee);
props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee);
} else {
- this.logger.log("Not using Execution Environment setting");
+ this.logger.log(Logger.LOG_INFO,
+ "Not using Execution Environment setting");
}
}
@@ -628,8 +632,9 @@
slingId = UUID.fromString(rawString).toString();
}
} catch (Throwable t) {
- logger.log("Failed reading UUID from id file " + idFile
- + ", creating new id", t);
+ logger.log(Logger.LOG_ERROR,
+ "Failed reading UUID from id file " + idFile
+ + ", creating new id", t);
} finally {
if (fin != null) {
try {
@@ -652,7 +657,8 @@
fout.write(slingId.getBytes("ISO-8859-1"));
fout.flush();
} catch (Throwable t) {
- logger.log("Failed writing UUID to id file " + idFile, t);
+ logger.log(Logger.LOG_ERROR, "Failed writing UUID to id file "
+ + idFile, t);
} finally {
if (fout != null) {
try {
@@ -803,8 +809,8 @@
this.load(props, is);
}
} catch (IOException ioe) {
- this.logger.log("Error loading config properties from "
- + file, ioe);
+ this.logger.log(Logger.LOG_ERROR,
+ "Error loading config properties from " + file, ioe);
}
}
}
@@ -825,8 +831,8 @@
try {
this.load(props, is);
} catch (IOException ioe) {
- this.logger.log("Error loading config properties from "
- + resource, ioe);
+ this.logger.log(Logger.LOG_ERROR,
+ "Error loading config properties from " + resource, ioe);
}
}
}
@@ -844,8 +850,9 @@
try {
this.load(props, new FileInputStream(file));
} catch (IOException ioe) {
- this.logger.log("Error loading config properties from "
- + file.getAbsolutePath(), ioe);
+ this.logger.log(Logger.LOG_ERROR,
+ "Error loading config properties from "
+ + file.getAbsolutePath(), ioe);
}
}
}
Modified: incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java?rev=605865&r1=605864&r2=605865&view=diff
==============================================================================
--- incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java (original)
+++ incubator/sling/trunk/launcher/app/src/main/java/org/apache/sling/launcher/app/main/Main.java Thu Dec 20 02:19:45 2007
@@ -16,10 +16,12 @@
*/
package org.apache.sling.launcher.app.main;
+import static org.apache.felix.framework.util.FelixConstants.LOG_LEVEL_PROP;
+
import java.util.HashMap;
import java.util.Map;
-import org.apache.sling.launcher.app.Logger;
+import org.apache.felix.framework.Logger;
import org.apache.sling.launcher.app.ResourceProvider;
import org.apache.sling.launcher.app.Sling;
import org.apache.sling.osgi.log.LogbackManager;
@@ -71,6 +73,9 @@
/** The Sling configuration property name setting the initial log file */
private static final String PROP_LOG_FILE = LogbackManager.LOG_FILE;
+ /** Default log level setting if no set on command line (value is "INFO"). */
+ private static final int DEFAULT_LOG_LEVEL = Logger.LOG_INFO;
+
/**
* The configuration property setting the port on which the HTTP service
* listens
@@ -101,8 +106,18 @@
// line arguments unconditionally. These will not be persisted in any
// properties file, though
+ // set up and configure Felix Logger
+ int logLevel;
+ if (!commandLine.containsKey(PROP_LOG_LEVEL)) {
+ logLevel = DEFAULT_LOG_LEVEL;
+ } else {
+ logLevel = toLogLevelInt(commandLine.get(PROP_LOG_LEVEL), DEFAULT_LOG_LEVEL);
+ commandLine.put(LOG_LEVEL_PROP, String.valueOf(logLevel));
+ }
+ Logger logger = new Logger();
+ logger.setLogLevel(logLevel);
+
try {
- Logger logger = new SimpleLogger();
ResourceProvider resProvider = new ClassLoaderResourceProvider(
Main.class.getClassLoader());
Sling sling = new Sling(logger, resProvider, props) {
@@ -153,7 +168,8 @@
}
// option argument is following the current option
- String value = argc < args.length ? args[argc++] : null;
+ argc++;
+ String value = argc < args.length ? args[argc] : null;
switch (arg.charAt(1)) {
case 'l':
@@ -271,5 +287,16 @@
usage("Bad log level: " + level, 1);
return null;
+ }
+
+ /** Return the log level code for the string */
+ private static int toLogLevelInt(String level, int defaultLevel) {
+ for (int i = 0; i < logLevels.length; i++) {
+ if (logLevels[i].equalsIgnoreCase(level)) {
+ return i;
+ }
+ }
+
+ return defaultLevel;
}
}