Thanks Guillaume, I think you are right. I tried your logging properties and they worked. However, I also needed to make a small change to the code. I needed to use the ConfigurationAdmin.getConfiguration() method that takes two arguments and pass in a null value as the second argument. Apparently, the one-argument version of getConfiguration() will bind the Configuration object to the location of the calling bundle, instead of the location of the ManagedService bundle (which is the Pax-Logging bundle in this case). Passing null as the second parameter to the two-paramater version of getConfiguration() takes care of this. Hence, the final code looks like this. Note, that the "configurer bundle" contains a log4j.properties file that is loaded and used to update the configuration properties of the Pax-Logging service:
public class Activator implements BundleActivator { private static final Logger logger = Logger.getLogger(Activator.class); public static final String PAX_LOGGING_SERVICE_PID = "org.ops4j.pax.logging"; public void start(final BundleContext ctx) throws Exception { new Thread() { @Override public void run() { InputStream inStream = getClass().getResourceAsStream("/log4j.properties"); if (inStream == null) { logger.error("Failed to find log4j.properties file in bundle!"); throw new RuntimeException("Failed to find log4j.properties file in bundle!"); } Properties log4jProperites = new Properties(); try { log4jProperites.load(inStream); logger.info("Loaded log4j.properties"); } catch (IOException e) { logger.error("Failed to load log4j.properties: " + e.getMessage()); throw new RuntimeException("Failed to load log4j.properties", e); } // Use a Servicetracker to wait for ConfigurationAdmin service ServiceTracker tracker = new ServiceTracker(ctx, ConfigurationAdmin.class.getName(), null); tracker.open(); ConfigurationAdmin service = null; try { service = (ConfigurationAdmin) tracker.waitForService(0); } catch (InterruptedException e) { logger.error("Failed to get ConfigurationAdmin service: " + e.getMessage()); throw new RuntimeException("Failed to get ConfigurationAdmin service", e); } // Update the Pax-Logging configuration by setting the // log4j.properties contents via the ConfigurationAdmin service Configuration configuration = null; try { configuration = service.getConfiguration(PAX_LOGGING_SERVICE_PID, null); } catch (IOException e) { logger.error("Failed to get configuration: " + e.getMessage()); throw new RuntimeException("Failed to get configuration", e); } try { configuration.update(log4jProperites); } catch (IOException e) { logger.error("Failed to update configuration properties: " + e.getMessage()); } logger.info("Log configuration updated!"); } }.start(); } public void stop(BundleContext ctx) throws Exception { } } Thank you for helping me out! cheers, Peter On Wed, May 7, 2008 at 6:42 PM, Guillaume Nodet <[EMAIL PROTECTED]> wrote: > I think it's just a log4j problem. Maybe you need to configure an > appender at least. > Try with the following properties: > > log4j.rootLogger=WARN, stdout > log4j.appender.stdout=org.apache.log4j.ConsoleAppender > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout > log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | > %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n > > > On Wed, May 7, 2008 at 5:41 PM, Peter Gardfjäll > <[EMAIL PROTECTED]> wrote: > > Thanks for the example Guillaume! > > I have looked at your example and your approach looks similar to the one > I > > have been trying (without any success I'm afraid...). > > > > Basically, I just want to reduce the amount of logging produced when > > Pax-Logging is run in default mode (I get bombarded by log messages as > all > > bundles start up). Hence, I thought I would write a simple bundle with a > > BundleActivator that sets the log-level. > > I am running against Pax-Logging version 1.0.0 and I have tried using > both > > the ConfigurationAdmin service of equinox and felix, without seeing any > > differences in the amount of log output. I will provide the code below. I > > hope someone can give some hints as to what I am doing wrong. > > > > public class Activator implements BundleActivator { > > private static final Logger logger = > Logger.getLogger(Activator.class); > > public static final String PAX_LOGGING_SERVICE_PID = > > "org.ops4j.pax.logging"; > > > > public void start(final BundleContext ctx) throws Exception { > > logger.info("Started Logging configurator bundle ..."); > > new Thread() { > > @Override > > public void run() { > > ServiceTracker tracker = new ServiceTracker(ctx, > > ConfigurationAdmin.class.getName(), null); > > tracker.open(); > > logger.info("Waiting for service tracker to find a > > ConfigurationAdmin service ..."); > > ConfigurationAdmin service = null; > > try { > > service = (ConfigurationAdmin) > > tracker.waitForService(0); > > } catch (InterruptedException e) { > > logger.error("Failed to get ConfigurationAdmin > service: > > " + e.getMessage()); > > } > > logger.info("Got ConfigurationAdmin service."); > > > > Configuration configuration = null; > > try { > > configuration = > > service.getConfiguration(PAX_LOGGING_SERVICE_PID); > > } catch (IOException e) { > > logger.error("Failed to get configuration: " + > > e.getMessage()); > > } > > Dictionary<String, String> props = new Hashtable<String, > > String>(); > > props.put("log4j.rootLogger", "WARN"); > > try { > > configuration.update(props); > > } catch (IOException e) { > > logger.error("Failed to update configuration: " + > > e.getMessage()); > > } > > logger.info("Configuration updated"); > > } > > }.start(); > > } > > > > public void stop(BundleContext ctx) throws Exception { > > } > > > > } > > > > Once I get the "Configuration updated" output, I would expect the amount > of > > logging to be reduced. > > However, the log level seems to remain unchanged. What am I doing wrong? > > > > regards, Peter > > > > > > > > > > On Wed, May 7, 2008 at 4:07 PM, Guillaume Nodet <[EMAIL PROTECTED]> > wrote: > > > I've done that for ServiceMix Kernel a few days ago: > > > > > > http://svn.apache.org/repos/asf/servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/java/org/apache/servicemix/gshell/log/SetLogLevel.java > > > > > > > > > > > > > > > On Wed, May 7, 2008 at 3:34 PM, Peter Gardfjäll > > > <[EMAIL PROTECTED]> wrote: > > > > Hi all, > > > > > > > > according to the Pax-Logging documentation, the logger can be set up > by > > > > passing the contents of a log4j.properties via the ConfigurationAdmin > > > > service. > > > > However, I have not been able to find any code examples of how to > > perform > > > > this. > > > > Are there any samples available that shows how to accomplish this, > or > > would > > > > someone be willing to respond with a brief code example? > > > > It would be greatly appreciated. > > > > > > > > Thanks, Peter > > > > _______________________________________________ > > > > general mailing list > > > > general@lists.ops4j.org > > > > http://lists.ops4j.org/mailman/listinfo/general > > > > > > > > > > > > > > > > > > > > -- > > > Cheers, > > > Guillaume Nodet > > > ------------------------ > > > Blog: http://gnodet.blogspot.com/ > > > > > > _______________________________________________ > > > general mailing list > > > general@lists.ops4j.org > > > http://lists.ops4j.org/mailman/listinfo/general > > > > > > > > > _______________________________________________ > > general mailing list > > general@lists.ops4j.org > > http://lists.ops4j.org/mailman/listinfo/general > > > > > > > > -- > Cheers, > Guillaume Nodet > ------------------------ > Blog: http://gnodet.blogspot.com/ > > _______________________________________________ > general mailing list > general@lists.ops4j.org > http://lists.ops4j.org/mailman/listinfo/general >
_______________________________________________ general mailing list general@lists.ops4j.org http://lists.ops4j.org/mailman/listinfo/general