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 2015/06/27 09:10:05 UTC

Re: [Dev][log4j2]How to configure log4j2 in OSGi environment

Did you solve your OSGi issues?

Gary

On Thu, May 14, 2015 at 10:37 AM, Chathura Priyankara <
priyankarahac@gmail.com> wrote:

> Hi,
>
> I think resources inside the META-INF of log4j2 core is not visible to
> log4j-api.
> That is why this error occurs.
> Any idea about this ?
>
> Thanks!
>
> On Thu, May 14, 2015 at 9:39 AM, Chathura Priyankara <
> priyankarahac@gmail.com> wrote:
>
>> Hi,
>>
>> I want to use log4j2 OSGi bundles in one OSGi application. It is based on
>> Eclipse Equinox and consists of several modules. Apache Felix is the bundle
>> plugin.
>> To use log4j2 in this OSGi environment I added log4j-api, log4j-core and
>> log4j-jcl as maven dependencies like follows.
>>
>>    <dependency>
>>         <groupId>org.apache.logging.log4j</groupId>
>>         <artifactId>log4j-api</artifactId>
>>         <version>2.2</version>
>>     </dependency>
>>     <dependency>
>>         <groupId>org.apache.logging.log4j</groupId>
>>         <artifactId>log4j-core</artifactId>
>>         <version>2.2</version>
>>     </dependency>
>>     <dependency>
>>         <groupId>org.apache.logging.log4j</groupId>
>>         <artifactId>log4j-jcl</artifactId>
>>         <version>2.2</version>
>>     </dependency>
>>
>> (The application uses apache commons as the logging API).
>> I have added log4j2 configuration in to the bundle also.
>> Then I copied above three jars in to the dropins directory which is the
>> OSGi container in my case.
>>
>> However when I'm running this application I'm getting following exception.
>>
>> ERROR StatusLogger Log4j2 could not find a logging implementation. Please
>> add log4j-core to the classpath. Using SimpleLogger to log to the console
>>
>> As far as I understood this error comes because log4j2 api cannot find
>> the log4j-provider.properties file inside the META-INF of log4j-core.
>> I'm quite new to this, could you please tell me why I'm getting this
>> error and how to correct this ?
>> Any help is highly appreciated.
>>
>> Thanks!
>> Regards,
>> Chathura
>>
>> On Thu, May 14, 2015 at 9:38 AM, Chathura Priyankara <
>> priyankarahac@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I want to use log4j2 OSGi bundles in one OSGi application. It is based
>>> on Eclipse Equinox and consists of several modules. Apache Felix is the
>>> bundle plugin.
>>> To use log4j2 in this OSGi environment I added log4j-api, log4j-core and
>>> log4j-jcl as maven dependencies like follows.
>>>
>>>    <dependency>
>>>         <groupId>org.apache.logging.log4j</groupId>
>>>         <artifactId>log4j-api</artifactId>
>>>         <version>2.2</version>
>>>     </dependency>
>>>     <dependency>
>>>         <groupId>org.apache.logging.log4j</groupId>
>>>         <artifactId>log4j-core</artifactId>
>>>         <version>2.2</version>
>>>     </dependency>
>>>     <dependency>
>>>         <groupId>org.apache.logging.log4j</groupId>
>>>         <artifactId>log4j-jcl</artifactId>
>>>         <version>2.2</version>
>>>     </dependency>
>>>
>>> (The application uses apache commons as the logging API).
>>> I have added log4j2 configuration in to the bundle also.
>>> Then I copied above three jars in to the dropins directory which is the OSGi container in my case.
>>>
>>> However when I'm running this application I'm getting following exception.
>>>
>>> ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console
>>>
>>> As far as I understood this error comes because log4j2 api cannot find the log4j-provider.properties file inside the META-INF of log4j-core.
>>> I'm quite new to this, could you please tell me why I'm getting this error and how to correct this ?
>>> Any help is highly appreciated.
>>>
>>> Thanks!
>>> Regards,
>>> Chathura.
>>>
>>>
>>> On Thu, May 14, 2015 at 9:08 AM, Gary Gregory <ga...@gmail.com>
>>> wrote:
>>>
>>>> Please provide a precise description of what you are doing and seeing,
>>>> including the full stack trace. What version of Log4j are you using?
>>>>
>>>> Thank you,
>>>> Gary
>>>>
>>>> On Wed, May 13, 2015 at 1:36 AM, Chathura Priyankara <
>>>> priyankarahac@gmail.com> wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>> It seems like there is no proper guide about how to configure log4j2
>>>>> OSGi bundles correctly. Even though there is a fix [1] for the class
>>>>> loading issue I'm still getting add log4j2 implementation to the class path
>>>>> exception in an OSGi environment.
>>>>>
>>>>> Can any one please guide me how correctly use log4j2 OSGi bundles in
>>>>> an OSGi environment ?
>>>>>
>>>>> [1] https://issues.apache.org/jira/browse/LOG4J2-373
>>>>>
>>>>> Thanks,
>>>>> Chathura.
>>>>>
>>>>> --
>>>>> Chathura Priyankara,
>>>>> Faculty of Information Technology,
>>>>> University of Moratuwa.
>>>>> Blog  : www.codeoncloud.blogspot.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
>>>>
>>>
>>>
>>>
>>> --
>>> Chathura Priyankara,
>>> Faculty of Information Technology,
>>> University of Moratuwa.
>>> Blog  : www.codeoncloud.blogspot.com
>>>
>>
>>
>>
>> --
>> Chathura Priyankara,
>> Faculty of Information Technology,
>> University of Moratuwa.
>> Blog  : www.codeoncloud.blogspot.com
>>
>
>
>
> --
> Chathura Priyankara,
> Faculty of Information Technology,
> University of Moratuwa.
> Blog  : www.codeoncloud.blogspot.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: [Dev][log4j2]How to configure log4j2 in OSGi environment

Posted by Chathura Priyankara <pr...@gmail.com>.
Hi Gray,

I could not properly solve this problem still. For now although it is ugly
what I'm doing is making a fragment which has log4j-api as fragment host.
This fragment has log4j.provider.properties file.
However I'm facing two main problems as pointed below.

1. log4j core cannot find custom appenders in other OSGi bundles even
package name is provided in log4j2.xml. (I couldn't find any proper reason
for this issue)
2. How and when to set the system property (
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager) for
JUL adapter when it is using in OSGi environment ? (Still I could not make
any success on this)

I highly appreciated if you could point me to a good solutions for these
issues. (There are no any good resource about using log4j in OSGi
environment)

Regards,
Chathura.

On Sat, Jun 27, 2015 at 12:40 PM, Gary Gregory <ga...@gmail.com>
wrote:

> Did you solve your OSGi issues?
>
> Gary
>
> On Thu, May 14, 2015 at 10:37 AM, Chathura Priyankara <
> priyankarahac@gmail.com> wrote:
>
>> Hi,
>>
>> I think resources inside the META-INF of log4j2 core is not visible to
>> log4j-api.
>> That is why this error occurs.
>> Any idea about this ?
>>
>> Thanks!
>>
>> On Thu, May 14, 2015 at 9:39 AM, Chathura Priyankara <
>> priyankarahac@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I want to use log4j2 OSGi bundles in one OSGi application. It is based
>>> on Eclipse Equinox and consists of several modules. Apache Felix is the
>>> bundle plugin.
>>> To use log4j2 in this OSGi environment I added log4j-api, log4j-core and
>>> log4j-jcl as maven dependencies like follows.
>>>
>>>    <dependency>
>>>         <groupId>org.apache.logging.log4j</groupId>
>>>         <artifactId>log4j-api</artifactId>
>>>         <version>2.2</version>
>>>     </dependency>
>>>     <dependency>
>>>         <groupId>org.apache.logging.log4j</groupId>
>>>         <artifactId>log4j-core</artifactId>
>>>         <version>2.2</version>
>>>     </dependency>
>>>     <dependency>
>>>         <groupId>org.apache.logging.log4j</groupId>
>>>         <artifactId>log4j-jcl</artifactId>
>>>         <version>2.2</version>
>>>     </dependency>
>>>
>>> (The application uses apache commons as the logging API).
>>> I have added log4j2 configuration in to the bundle also.
>>> Then I copied above three jars in to the dropins directory which is the
>>> OSGi container in my case.
>>>
>>> However when I'm running this application I'm getting following
>>> exception.
>>>
>>> ERROR StatusLogger Log4j2 could not find a logging implementation.
>>> Please add log4j-core to the classpath. Using SimpleLogger to log to the
>>> console
>>>
>>> As far as I understood this error comes because log4j2 api cannot find
>>> the log4j-provider.properties file inside the META-INF of log4j-core.
>>> I'm quite new to this, could you please tell me why I'm getting this
>>> error and how to correct this ?
>>> Any help is highly appreciated.
>>>
>>> Thanks!
>>> Regards,
>>> Chathura
>>>
>>> On Thu, May 14, 2015 at 9:38 AM, Chathura Priyankara <
>>> priyankarahac@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I want to use log4j2 OSGi bundles in one OSGi application. It is based
>>>> on Eclipse Equinox and consists of several modules. Apache Felix is the
>>>> bundle plugin.
>>>> To use log4j2 in this OSGi environment I added log4j-api, log4j-core
>>>> and log4j-jcl as maven dependencies like follows.
>>>>
>>>>    <dependency>
>>>>         <groupId>org.apache.logging.log4j</groupId>
>>>>         <artifactId>log4j-api</artifactId>
>>>>         <version>2.2</version>
>>>>     </dependency>
>>>>     <dependency>
>>>>         <groupId>org.apache.logging.log4j</groupId>
>>>>         <artifactId>log4j-core</artifactId>
>>>>         <version>2.2</version>
>>>>     </dependency>
>>>>     <dependency>
>>>>         <groupId>org.apache.logging.log4j</groupId>
>>>>         <artifactId>log4j-jcl</artifactId>
>>>>         <version>2.2</version>
>>>>     </dependency>
>>>>
>>>> (The application uses apache commons as the logging API).
>>>> I have added log4j2 configuration in to the bundle also.
>>>> Then I copied above three jars in to the dropins directory which is the OSGi container in my case.
>>>>
>>>> However when I'm running this application I'm getting following exception.
>>>>
>>>> ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console
>>>>
>>>> As far as I understood this error comes because log4j2 api cannot find the log4j-provider.properties file inside the META-INF of log4j-core.
>>>> I'm quite new to this, could you please tell me why I'm getting this error and how to correct this ?
>>>> Any help is highly appreciated.
>>>>
>>>> Thanks!
>>>> Regards,
>>>> Chathura.
>>>>
>>>>
>>>> On Thu, May 14, 2015 at 9:08 AM, Gary Gregory <ga...@gmail.com>
>>>> wrote:
>>>>
>>>>> Please provide a precise description of what you are doing and seeing,
>>>>> including the full stack trace. What version of Log4j are you using?
>>>>>
>>>>> Thank you,
>>>>> Gary
>>>>>
>>>>> On Wed, May 13, 2015 at 1:36 AM, Chathura Priyankara <
>>>>> priyankarahac@gmail.com> wrote:
>>>>>
>>>>>> Hi All,
>>>>>>
>>>>>> It seems like there is no proper guide about how to configure log4j2
>>>>>> OSGi bundles correctly. Even though there is a fix [1] for the class
>>>>>> loading issue I'm still getting add log4j2 implementation to the class path
>>>>>> exception in an OSGi environment.
>>>>>>
>>>>>> Can any one please guide me how correctly use log4j2 OSGi bundles in
>>>>>> an OSGi environment ?
>>>>>>
>>>>>> [1] https://issues.apache.org/jira/browse/LOG4J2-373
>>>>>>
>>>>>> Thanks,
>>>>>> Chathura.
>>>>>>
>>>>>> --
>>>>>> Chathura Priyankara,
>>>>>> Faculty of Information Technology,
>>>>>> University of Moratuwa.
>>>>>> Blog  : www.codeoncloud.blogspot.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
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Chathura Priyankara,
>>>> Faculty of Information Technology,
>>>> University of Moratuwa.
>>>> Blog  : www.codeoncloud.blogspot.com
>>>>
>>>
>>>
>>>
>>> --
>>> Chathura Priyankara,
>>> Faculty of Information Technology,
>>> University of Moratuwa.
>>> Blog  : www.codeoncloud.blogspot.com
>>>
>>
>>
>>
>> --
>> Chathura Priyankara,
>> Faculty of Information Technology,
>> University of Moratuwa.
>> Blog  : www.codeoncloud.blogspot.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
>



-- 
Chathura Priyankara,
Faculty of Information Technology,
University of Moratuwa.
Blog  : www.codeoncloud.blogspot.com