
|
If you were logged in you would be able to see more operations.
|
|
|
| Resolution Date: |
14/May/06 06:55 AM
|
|
Runtime changes to the log4j.properties file require reconfiguration of the logging infrastructure.
Adding an the attached Activator to an OSGi bundle that exports LOG4J and SLF4J packages a bundle can offer LOG4J and SLF4J packages to other bundles and offer a solution for reconfiguration of the logging infrastructure without restarting the JVM.
--------------------------------------------------
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Activator implements BundleActivator
{
private static final String LOG_PROPERTIES_LOCATION =
"log4j.configuration";
private Logger log = null;
public void start(BundleContext bundleContext) throws Exception
{
try
{
resetLog4j(bundleContext);
}
catch (Exception e)
{
//e.printStackTrace();
}
log = LoggerFactory.getLogger(Activator.class);
log.debug("Reset log configuration.");
}
public void stop(BundleContext arg0) throws Exception {}
/**
* @return url of the log4j.properties configuration file
*
* @throws MalformedURLException
*
*/
private URL getLoggingProperty(BundleContext bundleContext)
throws MalformedURLException
{
final String logPropertiesLocation = bundleContext
.getProperty(LOG_PROPERTIES_LOCATION);
return new URL(logPropertiesLocation);
}
/**
* Reset the log4j configuration.
* @param bundleContext
* @throws MalformedURLException
* @throws FileNotFoundException
*/
private void resetLog4j(BundleContext bundleContext)
throws MalformedURLException,
FileNotFoundException
{
LogManager.resetConfiguration();
URL log4jprops = getLoggingProperty(bundleContext);
if (log4jprops != null)
{
PropertyConfigurator.configure(log4jprops);
}
else
{
throw new FileNotFoundException(bundleContext
.getProperty(LOG_PROPERTIES_LOCATION)
+ " could not be found. "
+ "Please specify add the file and restart the "
+ bundleContext.getBundle().getLocation() + " bundle.");
}
}
}
|
|
Description
|
Runtime changes to the log4j.properties file require reconfiguration of the logging infrastructure.
Adding an the attached Activator to an OSGi bundle that exports LOG4J and SLF4J packages a bundle can offer LOG4J and SLF4J packages to other bundles and offer a solution for reconfiguration of the logging infrastructure without restarting the JVM.
--------------------------------------------------
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Activator implements BundleActivator
{
private static final String LOG_PROPERTIES_LOCATION =
"log4j.configuration";
private Logger log = null;
public void start(BundleContext bundleContext) throws Exception
{
try
{
resetLog4j(bundleContext);
}
catch (Exception e)
{
//e.printStackTrace();
}
log = LoggerFactory.getLogger(Activator.class);
log.debug("Reset log configuration.");
}
public void stop(BundleContext arg0) throws Exception {}
/**
* @return url of the log4j.properties configuration file
*
* @throws MalformedURLException
*
*/
private URL getLoggingProperty(BundleContext bundleContext)
throws MalformedURLException
{
final String logPropertiesLocation = bundleContext
.getProperty(LOG_PROPERTIES_LOCATION);
return new URL(logPropertiesLocation);
}
/**
* Reset the log4j configuration.
* @param bundleContext
* @throws MalformedURLException
* @throws FileNotFoundException
*/
private void resetLog4j(BundleContext bundleContext)
throws MalformedURLException,
FileNotFoundException
{
LogManager.resetConfiguration();
URL log4jprops = getLoggingProperty(bundleContext);
if (log4jprops != null)
{
PropertyConfigurator.configure(log4jprops);
}
else
{
throw new FileNotFoundException(bundleContext
.getProperty(LOG_PROPERTIES_LOCATION)
+ " could not be found. "
+ "Please specify add the file and restart the "
+ bundleContext.getBundle().getLocation() + " bundle.");
}
}
} |
Show » |
| No work has yet been logged on this issue.
|
|