You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2014/04/27 22:27:54 UTC

Re: svn commit: r1590443 - in /logging/log4j/log4j2/trunk/log4j-core: pom.xml src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java

I for one am glad to see all of this OSGi stuff layered on top of our
current modules instead of separate ones.

So thank you for that Matt!

Now let's see what pops up in Java 9 WRT Jigsaw... ;)

Gary


On Sun, Apr 27, 2014 at 2:24 PM, <ma...@apache.org> wrote:

> Author: mattsicker
> Date: Sun Apr 27 18:24:47 2014
> New Revision: 1590443
>
> URL: http://svn.apache.org/r1590443
> Log:
> Add basic OSGi activator class.
>
>   - Registers Log4jContextFactory as the LogManager.factory.
>   - Tracks future bundle start-ups to find Log4j plugins (still need
>   to add code to check existing bundles) via the plugin cache file.
>   - Pre-loads plugin classes using proper ClassLoader for future use
>   by configurations.
>
> Added:
>
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>   (with props)
> Modified:
>     logging/log4j/log4j2/trunk/log4j-core/pom.xml
>
> Modified: logging/log4j/log4j2/trunk/log4j-core/pom.xml
> URL:
> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/pom.xml?rev=1590443&r1=1590442&r2=1590443&view=diff
>
> ==============================================================================
> --- logging/log4j/log4j2/trunk/log4j-core/pom.xml (original)
> +++ logging/log4j/log4j2/trunk/log4j-core/pom.xml Sun Apr 27 18:24:47 2014
> @@ -260,6 +260,7 @@
>            <instructions>
>
>  <Bundle-SymbolicName>org.apache.logging.log4j.core</Bundle-SymbolicName>
>
>  <Export-Package>org.apache.logging.log4j.core.*</Export-Package>
> +
>  <Bundle-Activator>org.apache.logging.log4j.core.config.plugins.osgi.Activator</Bundle-Activator>
>            </instructions>
>          </configuration>
>        </plugin>
>
> Added:
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
> URL:
> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java?rev=1590443&view=auto
>
> ==============================================================================
> ---
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
> (added)
> +++
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
> Sun Apr 27 18:24:47 2014
> @@ -0,0 +1,75 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package org.apache.logging.log4j.core.config.plugins.osgi;
> +
> +import org.apache.logging.log4j.LogManager;
> +import org.apache.logging.log4j.Logger;
> +import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
> +import org.apache.logging.log4j.core.helpers.lang.BundleResourceLoader;
> +import org.apache.logging.log4j.core.impl.Log4jContextFactory;
> +import org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
> +import org.apache.logging.log4j.spi.LoggerContextFactory;
> +import org.apache.logging.log4j.status.StatusLogger;
> +import org.osgi.framework.BundleContext;
> +import org.osgi.framework.BundleEvent;
> +import org.osgi.framework.BundleListener;
> +
> +/**
> + * OSGi BundleActivator.
> + */
> +public class Activator implements org.osgi.framework.BundleActivator {
> +
> +    private static final Logger LOGGER = StatusLogger.getLogger();
> +
> +    @Override
> +    public void start(final BundleContext context) throws Exception {
> +        registerLoggerContextFactory();
> +        context.addBundleListener(new Listener());
> +    }
> +
> +    private void registerLoggerContextFactory() {
> +        final LoggerContextFactory current = LogManager.getFactory();
> +        if (!(current instanceof Log4jContextFactory)) {
> +            LogManager.setFactory(new Log4jContextFactory());
> +        }
> +    }
> +
> +    @Override
> +    public void stop(final BundleContext context) throws Exception {
> +        unregisterLoggerContextFactory();
> +    }
> +
> +    private void unregisterLoggerContextFactory() {
> +        LogManager.setFactory(new SimpleLoggerContextFactory());
> +    }
> +
> +    private static class Listener implements BundleListener {
> +
> +        @Override
> +        public void bundleChanged(final BundleEvent event) {
> +            switch (event.getType()) {
> +                case BundleEvent.STARTED:
> +                    PluginManager.loadPlugins(new
> BundleResourceLoader(event.getBundle()));
> +                    break;
> +
> +                default:
> +                    break;
> +            }
> +        }
> +    }
> +}
>
> Propchange:
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>
> ------------------------------------------------------------------------------
>     svn:eol-style = native
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: svn commit: r1590443 - in /logging/log4j/log4j2/trunk/log4j-core: pom.xml src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java

Posted by Matt Sicker <bo...@gmail.com>.
Indeed! I don't even know if it's possible to get more complex than OSGi
without violating Java standards. You can dynamically add or remove JARs at
runtime, and other JARs that depend on them can react accordingly to avoid
having to restart where possible. Jigsaw, on the other hand, is supposed to
be only used at compile-time, so just like generics, it's going to be
disappointing in practice. ;)


On 27 April 2014 15:36, Gary Gregory <ga...@gmail.com> wrote:

> More complex than OSGi would be painful ;)
>
> Gary
>
>
> On Sun, Apr 27, 2014 at 4:33 PM, Matt Sicker <bo...@gmail.com> wrote:
>
>> Yeah, OSGi is supposed to just be overlaid like this anyhow. I don't even
>> know if the other method of extra bundles even worked properly. From what I
>> know about Jigsaw so far, it's not as powerful as OSGi yet, so it might end
>> up being rather simple to integrate with in comparison.
>>
>>
>> On 27 April 2014 15:27, Gary Gregory <ga...@gmail.com> wrote:
>>
>>> I for one am glad to see all of this OSGi stuff layered on top of our
>>> current modules instead of separate ones.
>>>
>>> So thank you for that Matt!
>>>
>>> Now let's see what pops up in Java 9 WRT Jigsaw... ;)
>>>
>>> Gary
>>>
>>>
>>> On Sun, Apr 27, 2014 at 2:24 PM, <ma...@apache.org> wrote:
>>>
>>>> Author: mattsicker
>>>> Date: Sun Apr 27 18:24:47 2014
>>>> New Revision: 1590443
>>>>
>>>> URL: http://svn.apache.org/r1590443
>>>> Log:
>>>> Add basic OSGi activator class.
>>>>
>>>>   - Registers Log4jContextFactory as the LogManager.factory.
>>>>   - Tracks future bundle start-ups to find Log4j plugins (still need
>>>>   to add code to check existing bundles) via the plugin cache file.
>>>>   - Pre-loads plugin classes using proper ClassLoader for future use
>>>>   by configurations.
>>>>
>>>> Added:
>>>>
>>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>>>   (with props)
>>>> Modified:
>>>>     logging/log4j/log4j2/trunk/log4j-core/pom.xml
>>>>
>>>> Modified: logging/log4j/log4j2/trunk/log4j-core/pom.xml
>>>> URL:
>>>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/pom.xml?rev=1590443&r1=1590442&r2=1590443&view=diff
>>>>
>>>> ==============================================================================
>>>> --- logging/log4j/log4j2/trunk/log4j-core/pom.xml (original)
>>>> +++ logging/log4j/log4j2/trunk/log4j-core/pom.xml Sun Apr 27 18:24:47
>>>> 2014
>>>> @@ -260,6 +260,7 @@
>>>>            <instructions>
>>>>
>>>>  <Bundle-SymbolicName>org.apache.logging.log4j.core</Bundle-SymbolicName>
>>>>
>>>>  <Export-Package>org.apache.logging.log4j.core.*</Export-Package>
>>>> +
>>>>  <Bundle-Activator>org.apache.logging.log4j.core.config.plugins.osgi.Activator</Bundle-Activator>
>>>>            </instructions>
>>>>          </configuration>
>>>>        </plugin>
>>>>
>>>> Added:
>>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>>> URL:
>>>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java?rev=1590443&view=auto
>>>>
>>>> ==============================================================================
>>>> ---
>>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>>> (added)
>>>> +++
>>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>>> Sun Apr 27 18:24:47 2014
>>>> @@ -0,0 +1,75 @@
>>>> +/*
>>>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>>>> + * contributor license agreements. See the NOTICE file distributed with
>>>> + * this work for additional information regarding copyright ownership.
>>>> + * The ASF licenses this file to You under the Apache License, Version
>>>> 2.0
>>>> + * (the "License"); you may not use this file except in compliance with
>>>> + * the License. You may obtain a copy of the License at
>>>> + *
>>>> + *      http://www.apache.org/licenses/LICENSE-2.0
>>>> + *
>>>> + * Unless required by applicable law or agreed to in writing, software
>>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>>>> implied.
>>>> + * See the License for the specific language governing permissions and
>>>> + * limitations under the License.
>>>> + */
>>>> +
>>>> +package org.apache.logging.log4j.core.config.plugins.osgi;
>>>> +
>>>> +import org.apache.logging.log4j.LogManager;
>>>> +import org.apache.logging.log4j.Logger;
>>>> +import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
>>>> +import org.apache.logging.log4j.core.helpers.lang.BundleResourceLoader;
>>>> +import org.apache.logging.log4j.core.impl.Log4jContextFactory;
>>>> +import org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
>>>> +import org.apache.logging.log4j.spi.LoggerContextFactory;
>>>> +import org.apache.logging.log4j.status.StatusLogger;
>>>> +import org.osgi.framework.BundleContext;
>>>> +import org.osgi.framework.BundleEvent;
>>>> +import org.osgi.framework.BundleListener;
>>>> +
>>>> +/**
>>>> + * OSGi BundleActivator.
>>>> + */
>>>> +public class Activator implements org.osgi.framework.BundleActivator {
>>>> +
>>>> +    private static final Logger LOGGER = StatusLogger.getLogger();
>>>> +
>>>> +    @Override
>>>> +    public void start(final BundleContext context) throws Exception {
>>>> +        registerLoggerContextFactory();
>>>> +        context.addBundleListener(new Listener());
>>>> +    }
>>>> +
>>>> +    private void registerLoggerContextFactory() {
>>>> +        final LoggerContextFactory current = LogManager.getFactory();
>>>> +        if (!(current instanceof Log4jContextFactory)) {
>>>> +            LogManager.setFactory(new Log4jContextFactory());
>>>> +        }
>>>> +    }
>>>> +
>>>> +    @Override
>>>> +    public void stop(final BundleContext context) throws Exception {
>>>> +        unregisterLoggerContextFactory();
>>>> +    }
>>>> +
>>>> +    private void unregisterLoggerContextFactory() {
>>>> +        LogManager.setFactory(new SimpleLoggerContextFactory());
>>>> +    }
>>>> +
>>>> +    private static class Listener implements BundleListener {
>>>> +
>>>> +        @Override
>>>> +        public void bundleChanged(final BundleEvent event) {
>>>> +            switch (event.getType()) {
>>>> +                case BundleEvent.STARTED:
>>>> +                    PluginManager.loadPlugins(new
>>>> BundleResourceLoader(event.getBundle()));
>>>> +                    break;
>>>> +
>>>> +                default:
>>>> +                    break;
>>>> +            }
>>>> +        }
>>>> +    }
>>>> +}
>>>>
>>>> Propchange:
>>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>>>
>>>> ------------------------------------------------------------------------------
>>>>     svn:eol-style = native
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>

Re: svn commit: r1590443 - in /logging/log4j/log4j2/trunk/log4j-core: pom.xml src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java

Posted by Gary Gregory <ga...@gmail.com>.
More complex than OSGi would be painful ;)

Gary


On Sun, Apr 27, 2014 at 4:33 PM, Matt Sicker <bo...@gmail.com> wrote:

> Yeah, OSGi is supposed to just be overlaid like this anyhow. I don't even
> know if the other method of extra bundles even worked properly. From what I
> know about Jigsaw so far, it's not as powerful as OSGi yet, so it might end
> up being rather simple to integrate with in comparison.
>
>
> On 27 April 2014 15:27, Gary Gregory <ga...@gmail.com> wrote:
>
>> I for one am glad to see all of this OSGi stuff layered on top of our
>> current modules instead of separate ones.
>>
>> So thank you for that Matt!
>>
>> Now let's see what pops up in Java 9 WRT Jigsaw... ;)
>>
>> Gary
>>
>>
>> On Sun, Apr 27, 2014 at 2:24 PM, <ma...@apache.org> wrote:
>>
>>> Author: mattsicker
>>> Date: Sun Apr 27 18:24:47 2014
>>> New Revision: 1590443
>>>
>>> URL: http://svn.apache.org/r1590443
>>> Log:
>>> Add basic OSGi activator class.
>>>
>>>   - Registers Log4jContextFactory as the LogManager.factory.
>>>   - Tracks future bundle start-ups to find Log4j plugins (still need
>>>   to add code to check existing bundles) via the plugin cache file.
>>>   - Pre-loads plugin classes using proper ClassLoader for future use
>>>   by configurations.
>>>
>>> Added:
>>>
>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>>   (with props)
>>> Modified:
>>>     logging/log4j/log4j2/trunk/log4j-core/pom.xml
>>>
>>> Modified: logging/log4j/log4j2/trunk/log4j-core/pom.xml
>>> URL:
>>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/pom.xml?rev=1590443&r1=1590442&r2=1590443&view=diff
>>>
>>> ==============================================================================
>>> --- logging/log4j/log4j2/trunk/log4j-core/pom.xml (original)
>>> +++ logging/log4j/log4j2/trunk/log4j-core/pom.xml Sun Apr 27 18:24:47
>>> 2014
>>> @@ -260,6 +260,7 @@
>>>            <instructions>
>>>
>>>  <Bundle-SymbolicName>org.apache.logging.log4j.core</Bundle-SymbolicName>
>>>
>>>  <Export-Package>org.apache.logging.log4j.core.*</Export-Package>
>>> +
>>>  <Bundle-Activator>org.apache.logging.log4j.core.config.plugins.osgi.Activator</Bundle-Activator>
>>>            </instructions>
>>>          </configuration>
>>>        </plugin>
>>>
>>> Added:
>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>> URL:
>>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java?rev=1590443&view=auto
>>>
>>> ==============================================================================
>>> ---
>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>> (added)
>>> +++
>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>> Sun Apr 27 18:24:47 2014
>>> @@ -0,0 +1,75 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>>> + * contributor license agreements. See the NOTICE file distributed with
>>> + * this work for additional information regarding copyright ownership.
>>> + * The ASF licenses this file to You under the Apache License, Version
>>> 2.0
>>> + * (the "License"); you may not use this file except in compliance with
>>> + * the License. You may obtain a copy of the License at
>>> + *
>>> + *      http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing, software
>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>>> implied.
>>> + * See the License for the specific language governing permissions and
>>> + * limitations under the License.
>>> + */
>>> +
>>> +package org.apache.logging.log4j.core.config.plugins.osgi;
>>> +
>>> +import org.apache.logging.log4j.LogManager;
>>> +import org.apache.logging.log4j.Logger;
>>> +import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
>>> +import org.apache.logging.log4j.core.helpers.lang.BundleResourceLoader;
>>> +import org.apache.logging.log4j.core.impl.Log4jContextFactory;
>>> +import org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
>>> +import org.apache.logging.log4j.spi.LoggerContextFactory;
>>> +import org.apache.logging.log4j.status.StatusLogger;
>>> +import org.osgi.framework.BundleContext;
>>> +import org.osgi.framework.BundleEvent;
>>> +import org.osgi.framework.BundleListener;
>>> +
>>> +/**
>>> + * OSGi BundleActivator.
>>> + */
>>> +public class Activator implements org.osgi.framework.BundleActivator {
>>> +
>>> +    private static final Logger LOGGER = StatusLogger.getLogger();
>>> +
>>> +    @Override
>>> +    public void start(final BundleContext context) throws Exception {
>>> +        registerLoggerContextFactory();
>>> +        context.addBundleListener(new Listener());
>>> +    }
>>> +
>>> +    private void registerLoggerContextFactory() {
>>> +        final LoggerContextFactory current = LogManager.getFactory();
>>> +        if (!(current instanceof Log4jContextFactory)) {
>>> +            LogManager.setFactory(new Log4jContextFactory());
>>> +        }
>>> +    }
>>> +
>>> +    @Override
>>> +    public void stop(final BundleContext context) throws Exception {
>>> +        unregisterLoggerContextFactory();
>>> +    }
>>> +
>>> +    private void unregisterLoggerContextFactory() {
>>> +        LogManager.setFactory(new SimpleLoggerContextFactory());
>>> +    }
>>> +
>>> +    private static class Listener implements BundleListener {
>>> +
>>> +        @Override
>>> +        public void bundleChanged(final BundleEvent event) {
>>> +            switch (event.getType()) {
>>> +                case BundleEvent.STARTED:
>>> +                    PluginManager.loadPlugins(new
>>> BundleResourceLoader(event.getBundle()));
>>> +                    break;
>>> +
>>> +                default:
>>> +                    break;
>>> +            }
>>> +        }
>>> +    }
>>> +}
>>>
>>> Propchange:
>>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>>
>>> ------------------------------------------------------------------------------
>>>     svn:eol-style = native
>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: svn commit: r1590443 - in /logging/log4j/log4j2/trunk/log4j-core: pom.xml src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java

Posted by Matt Sicker <bo...@gmail.com>.
Yeah, OSGi is supposed to just be overlaid like this anyhow. I don't even
know if the other method of extra bundles even worked properly. From what I
know about Jigsaw so far, it's not as powerful as OSGi yet, so it might end
up being rather simple to integrate with in comparison.


On 27 April 2014 15:27, Gary Gregory <ga...@gmail.com> wrote:

> I for one am glad to see all of this OSGi stuff layered on top of our
> current modules instead of separate ones.
>
> So thank you for that Matt!
>
> Now let's see what pops up in Java 9 WRT Jigsaw... ;)
>
> Gary
>
>
> On Sun, Apr 27, 2014 at 2:24 PM, <ma...@apache.org> wrote:
>
>> Author: mattsicker
>> Date: Sun Apr 27 18:24:47 2014
>> New Revision: 1590443
>>
>> URL: http://svn.apache.org/r1590443
>> Log:
>> Add basic OSGi activator class.
>>
>>   - Registers Log4jContextFactory as the LogManager.factory.
>>   - Tracks future bundle start-ups to find Log4j plugins (still need
>>   to add code to check existing bundles) via the plugin cache file.
>>   - Pre-loads plugin classes using proper ClassLoader for future use
>>   by configurations.
>>
>> Added:
>>
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>   (with props)
>> Modified:
>>     logging/log4j/log4j2/trunk/log4j-core/pom.xml
>>
>> Modified: logging/log4j/log4j2/trunk/log4j-core/pom.xml
>> URL:
>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/pom.xml?rev=1590443&r1=1590442&r2=1590443&view=diff
>>
>> ==============================================================================
>> --- logging/log4j/log4j2/trunk/log4j-core/pom.xml (original)
>> +++ logging/log4j/log4j2/trunk/log4j-core/pom.xml Sun Apr 27 18:24:47 2014
>> @@ -260,6 +260,7 @@
>>            <instructions>
>>
>>  <Bundle-SymbolicName>org.apache.logging.log4j.core</Bundle-SymbolicName>
>>
>>  <Export-Package>org.apache.logging.log4j.core.*</Export-Package>
>> +
>>  <Bundle-Activator>org.apache.logging.log4j.core.config.plugins.osgi.Activator</Bundle-Activator>
>>            </instructions>
>>          </configuration>
>>        </plugin>
>>
>> Added:
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>> URL:
>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java?rev=1590443&view=auto
>>
>> ==============================================================================
>> ---
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>> (added)
>> +++
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>> Sun Apr 27 18:24:47 2014
>> @@ -0,0 +1,75 @@
>> +/*
>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>> + * contributor license agreements. See the NOTICE file distributed with
>> + * this work for additional information regarding copyright ownership.
>> + * The ASF licenses this file to You under the Apache License, Version
>> 2.0
>> + * (the "License"); you may not use this file except in compliance with
>> + * the License. You may obtain a copy of the License at
>> + *
>> + *      http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing, software
>> + * distributed under the License is distributed on an "AS IS" BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>> implied.
>> + * See the License for the specific language governing permissions and
>> + * limitations under the License.
>> + */
>> +
>> +package org.apache.logging.log4j.core.config.plugins.osgi;
>> +
>> +import org.apache.logging.log4j.LogManager;
>> +import org.apache.logging.log4j.Logger;
>> +import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
>> +import org.apache.logging.log4j.core.helpers.lang.BundleResourceLoader;
>> +import org.apache.logging.log4j.core.impl.Log4jContextFactory;
>> +import org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
>> +import org.apache.logging.log4j.spi.LoggerContextFactory;
>> +import org.apache.logging.log4j.status.StatusLogger;
>> +import org.osgi.framework.BundleContext;
>> +import org.osgi.framework.BundleEvent;
>> +import org.osgi.framework.BundleListener;
>> +
>> +/**
>> + * OSGi BundleActivator.
>> + */
>> +public class Activator implements org.osgi.framework.BundleActivator {
>> +
>> +    private static final Logger LOGGER = StatusLogger.getLogger();
>> +
>> +    @Override
>> +    public void start(final BundleContext context) throws Exception {
>> +        registerLoggerContextFactory();
>> +        context.addBundleListener(new Listener());
>> +    }
>> +
>> +    private void registerLoggerContextFactory() {
>> +        final LoggerContextFactory current = LogManager.getFactory();
>> +        if (!(current instanceof Log4jContextFactory)) {
>> +            LogManager.setFactory(new Log4jContextFactory());
>> +        }
>> +    }
>> +
>> +    @Override
>> +    public void stop(final BundleContext context) throws Exception {
>> +        unregisterLoggerContextFactory();
>> +    }
>> +
>> +    private void unregisterLoggerContextFactory() {
>> +        LogManager.setFactory(new SimpleLoggerContextFactory());
>> +    }
>> +
>> +    private static class Listener implements BundleListener {
>> +
>> +        @Override
>> +        public void bundleChanged(final BundleEvent event) {
>> +            switch (event.getType()) {
>> +                case BundleEvent.STARTED:
>> +                    PluginManager.loadPlugins(new
>> BundleResourceLoader(event.getBundle()));
>> +                    break;
>> +
>> +                default:
>> +                    break;
>> +            }
>> +        }
>> +    }
>> +}
>>
>> Propchange:
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
>>
>> ------------------------------------------------------------------------------
>>     svn:eol-style = native
>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>