You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "John Conlon (JIRA)" <ji...@apache.org> on 2006/04/27 22:00:37 UTC
[jira] Created: (DIRSERVER-611) An OSGi Activator can allow simple
way for reconfiguration of log4j.properties without restarting the JVM.
An OSGi Activator can allow simple way for reconfiguration of log4j.properties without restarting the JVM.
----------------------------------------------------------------------------------------------------------
Key: DIRSERVER-611
URL: http://issues.apache.org/jira/browse/DIRSERVER-611
Project: Directory ApacheDS
Type: Improvement
Reporter: John Conlon
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.");
}
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
Re: [jira] Created: (DIRSERVER-611) An OSGi Activator can allow
simple way for reconfiguration of log4j.properties without restarting the
JVM.
Posted by "John E. Conlon" <jc...@verticon.com>.
On Fri, 2006-04-28 at 00:54 -0400, Enrique Rodriguez wrote:
> John Conlon (JIRA) wrote:
> ...
> > private static final String LOG_PROPERTIES_LOCATION =
> > "log4j.configuration";
>
> Was this intentional ^^^ to use 'configuration' as the extension? In
> the comment, below, you use props.
Yes it was intentional. As you mentioned in a previous email the
standard way to pass log4j configuration was with a command line like:
java -Dlog4j.configuration=file://$(pwd)/conf/log4j.properties -jar
bin/felix.jar
Earlier version of felix required a property in the config.properties
file to pass system properties through to bundles. I used one like this.
log4j.configuration=${log4j.configuration}
Recent version of felix seem to 'pass' the system property through to
the bundles with out need for the pass through property in
config.properties so I just commented out the above property and use the
command line. If I want to hard code the location I can just uncomment
the property and use it, without putting it in the startup script.
> This why your SCR logging died?
All other non-scr bundles continued to log to the console (including the
apacheDS backend) but not the one bundle I tested with scr. After I
changed that bundle back to servicebinder it then sent its logs (and
System.out.println just fine.
regards,
John
Re: [jira] Created: (DIRSERVER-611) An OSGi Activator can allow simple
way for reconfiguration of log4j.properties without restarting the JVM.
Posted by Enrique Rodriguez <en...@gmail.com>.
John Conlon (JIRA) wrote:
...
> private static final String LOG_PROPERTIES_LOCATION =
> "log4j.configuration";
Was this intentional ^^^ to use 'configuration' as the extension? In
the comment, below, you use props. This why your SCR logging died?
Enrique
> /**
> * @return url of the log4j.properties configuration file
> *
> * @throws MalformedURLException
> *
> */
[jira] Closed: (DIRSERVER-611) An OSGi Activator can allow simple
way for reconfiguration of log4j.properties without restarting the JVM.
Posted by "John Conlon (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/DIRSERVER-611?page=all ]
John Conlon closed DIRSERVER-611.
---------------------------------
Done.
> An OSGi Activator can allow simple way for reconfiguration of log4j.properties without restarting the JVM.
> ----------------------------------------------------------------------------------------------------------
>
> Key: DIRSERVER-611
> URL: http://issues.apache.org/jira/browse/DIRSERVER-611
> Project: Directory ApacheDS
> Issue Type: Improvement
> Reporter: John Conlon
> Assigned To: Enrique Rodriguez
> Fix For: 1.5.0
>
>
> 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.");
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Resolved: (DIRSERVER-611) An OSGi Activator can allow simple
way for reconfiguration of log4j.properties without restarting the JVM.
Posted by "Enrique Rodriguez (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/DIRSERVER-611?page=all ]
Enrique Rodriguez resolved DIRSERVER-611:
-----------------------------------------
Fix Version: 1.1.0
Resolution: Fixed
Assign To: Enrique Rodriguez
Activator committed on revision 406169 as part of the ApacheDS OSGi build logging bundle.
> An OSGi Activator can allow simple way for reconfiguration of log4j.properties without restarting the JVM.
> ----------------------------------------------------------------------------------------------------------
>
> Key: DIRSERVER-611
> URL: http://issues.apache.org/jira/browse/DIRSERVER-611
> Project: Directory ApacheDS
> Type: Improvement
> Reporter: John Conlon
> Assignee: Enrique Rodriguez
> Fix For: 1.1.0
>
> 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.");
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira