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

Reply via email to