You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by matthiaw <mi...@web.de> on 2019/05/30 10:45:36 UTC

Log4j2 in osgi-bundle

I want to use log4j2 in my osgi-bundle for karaf. When i add log4j into the
pom, compile it and load it into karaf, then the exception

Unresolved requirements: [[... [56](R 56.0)] osgi.wiring.package;
(&(osgi.wiring.package=*org.apache.logging.log4j*)(version>=2.11.0)(!(version>=3.0.0)))]

is thrown. This must be, because i not added something to
maven-bundle-plugin. Bot when i add there

<Private-Package>..., org.apache.logging.log4j*</Private-Package> or
<Private-Package>..., *</Private-Package> 

i get the exception

Unresolved requirements: [[... [57](R 57.0)] osgi.wiring.package;
(osgi.wiring.package=*com.conversantmedia.util.concurrent*)]

Looking for the package gets me to adding

<dependency>
    <groupId>com.conversantmedia</groupId>
    <artifactId>disruptor</artifactId>
    <version>1.2.0</version>
</dependency>

to the pom. Now i get 

Unresolved requirements: [[... [58](R 58.0)] osgi.wiring.package;
(osgi.wiring.package=*com.fasterxml.jackson.annotation*)]

Is it necessary that i add all depended libraries for log4j manually to the
pom to get a working bundle? Or is there a better way?

I am new to osgi and karaf. How can i add log4j accurate in a osgi-bundle,
so its log is shown in karaf log:display?

Regards,
Matthias




--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Re: Log4j2 in osgi-bundle

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

OK, I think you need some "background" about OSGi.

To avoid to pollute the mailing list, please ping me in private message,
I will explain deeply.

Regards
JB

On 30/05/2019 15:20, Matthias Wegner wrote:
> SLF4J
> 
> =========
> 
> Adding to the pom
> 
> <dependency>
>             <groupId>org.slf4j</groupId>
>             <artifactId>slf4j-api</artifactId>
>             <version>1.7.26</version>
>         </dependency>
> 
> and using in java logger with     private static final Logger logger =
> LoggerFactory.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
> 
> 
> works like charm in the bundle, thanks.
> 
> 
> LOG4J
> 
> =========
> 
> Adding to the pom
> 
> <dependency>
>             <groupId>org.ops4j.pax.logging</groupId>
> <artifactId>pax-logging-log4j2</artifactId>
>             <version>1.10.1</version>
> </dependency>
> 
> <Import-Package>
>     org.apache.logging.log4j*;version="[2,3)",
> 
>    *
> 
> </Import-Package>
> 
> is also working.
> 
> But i dont understand what information i get when i run in karaf the
> command package:exports|grep -i log4j. Also, i dont understand what
> [2,3) means?
> 
> 
> But i have two working solutions with slf4j of log4j that work now.
> Perfect, thanks.
> 
> Regards,
> 
> M.
> 
> 
> Am 30.05.19 um 13:26 schrieb Jean-Baptiste Onofré:
>> Hi,
>>
>> you should not embed log4j as private: you should import the log4j
>> packages provided by pax-logging.
>>
>> However, the log4j2 packages versions is 2.8.2, not 2.11.0.
>>
>> So, I recommend to use Import-Package with [2,3).
>>
>> You can see the packages using package:exports|grep -i log4j command.
>>
>> Regards
>> JB
>>
>> On 30/05/2019 12:45, matthiaw wrote:
>>> I want to use log4j2 in my osgi-bundle for karaf. When i add log4j
>>> into the
>>> pom, compile it and load it into karaf, then the exception
>>>
>>> Unresolved requirements: [[... [56](R 56.0)] osgi.wiring.package;
>>> (&(osgi.wiring.package=*org.apache.logging.log4j*)(version>=2.11.0)(!(version>=3.0.0)))]
>>>
>>>
>>> is thrown. This must be, because i not added something to
>>> maven-bundle-plugin. Bot when i add there
>>>
>>> <Private-Package>..., org.apache.logging.log4j*</Private-Package> or
>>> <Private-Package>..., *</Private-Package>
>>>
>>> i get the exception
>>>
>>> Unresolved requirements: [[... [57](R 57.0)] osgi.wiring.package;
>>> (osgi.wiring.package=*com.conversantmedia.util.concurrent*)]
>>>
>>> Looking for the package gets me to adding
>>>
>>> <dependency>
>>>      <groupId>com.conversantmedia</groupId>
>>>      <artifactId>disruptor</artifactId>
>>>      <version>1.2.0</version>
>>> </dependency>
>>>
>>> to the pom. Now i get
>>>
>>> Unresolved requirements: [[... [58](R 58.0)] osgi.wiring.package;
>>> (osgi.wiring.package=*com.fasterxml.jackson.annotation*)]
>>>
>>> Is it necessary that i add all depended libraries for log4j manually
>>> to the
>>> pom to get a working bundle? Or is there a better way?
>>>
>>> I am new to osgi and karaf. How can i add log4j accurate in a
>>> osgi-bundle,
>>> so its log is shown in karaf log:display?
>>>
>>> Regards,
>>> Matthias
>>>
>>>
>>>
>>>
>>> -- 
>>> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
>>>
> -- 
> Matthias Wegner
> Hauptstrasse 41a
> 79199 Kirchzarten
> Tel.: 07661 9091000
> Mobil: 0716 47893182
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Log4j2 in osgi-bundle

Posted by Matthias Wegner <mi...@web.de>.
SLF4J

=========

Adding to the pom

<dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <version>1.7.26</version>
         </dependency>

and using in java logger with     private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());

works like charm in the bundle, thanks.


LOG4J

=========

Adding to the pom

<dependency>
             <groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-log4j2</artifactId>
             <version>1.10.1</version>
</dependency>

<Import-Package>
     org.apache.logging.log4j*;version="[2,3)",

    *

</Import-Package>

is also working.

But i dont understand what information i get when i run in karaf the
command package:exports|grep -i log4j. Also, i dont understand what
[2,3) means?


But i have two working solutions with slf4j of log4j that work now.
Perfect, thanks.

Regards,

M.


Am 30.05.19 um 13:26 schrieb Jean-Baptiste Onofré:
> Hi,
>
> you should not embed log4j as private: you should import the log4j
> packages provided by pax-logging.
>
> However, the log4j2 packages versions is 2.8.2, not 2.11.0.
>
> So, I recommend to use Import-Package with [2,3).
>
> You can see the packages using package:exports|grep -i log4j command.
>
> Regards
> JB
>
> On 30/05/2019 12:45, matthiaw wrote:
>> I want to use log4j2 in my osgi-bundle for karaf. When i add log4j into the
>> pom, compile it and load it into karaf, then the exception
>>
>> Unresolved requirements: [[... [56](R 56.0)] osgi.wiring.package;
>> (&(osgi.wiring.package=*org.apache.logging.log4j*)(version>=2.11.0)(!(version>=3.0.0)))]
>>
>> is thrown. This must be, because i not added something to
>> maven-bundle-plugin. Bot when i add there
>>
>> <Private-Package>..., org.apache.logging.log4j*</Private-Package> or
>> <Private-Package>..., *</Private-Package>
>>
>> i get the exception
>>
>> Unresolved requirements: [[... [57](R 57.0)] osgi.wiring.package;
>> (osgi.wiring.package=*com.conversantmedia.util.concurrent*)]
>>
>> Looking for the package gets me to adding
>>
>> <dependency>
>>      <groupId>com.conversantmedia</groupId>
>>      <artifactId>disruptor</artifactId>
>>      <version>1.2.0</version>
>> </dependency>
>>
>> to the pom. Now i get
>>
>> Unresolved requirements: [[... [58](R 58.0)] osgi.wiring.package;
>> (osgi.wiring.package=*com.fasterxml.jackson.annotation*)]
>>
>> Is it necessary that i add all depended libraries for log4j manually to the
>> pom to get a working bundle? Or is there a better way?
>>
>> I am new to osgi and karaf. How can i add log4j accurate in a osgi-bundle,
>> so its log is shown in karaf log:display?
>>
>> Regards,
>> Matthias
>>
>>
>>
>>
>> --
>> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
>>
--
Matthias Wegner
Hauptstrasse 41a
79199 Kirchzarten
Tel.: 07661 9091000
Mobil: 0716 47893182


Re: Log4j2 in osgi-bundle

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

you should not embed log4j as private: you should import the log4j
packages provided by pax-logging.

However, the log4j2 packages versions is 2.8.2, not 2.11.0.

So, I recommend to use Import-Package with [2,3).

You can see the packages using package:exports|grep -i log4j command.

Regards
JB

On 30/05/2019 12:45, matthiaw wrote:
> I want to use log4j2 in my osgi-bundle for karaf. When i add log4j into the
> pom, compile it and load it into karaf, then the exception
> 
> Unresolved requirements: [[... [56](R 56.0)] osgi.wiring.package;
> (&(osgi.wiring.package=*org.apache.logging.log4j*)(version>=2.11.0)(!(version>=3.0.0)))]
> 
> is thrown. This must be, because i not added something to
> maven-bundle-plugin. Bot when i add there
> 
> <Private-Package>..., org.apache.logging.log4j*</Private-Package> or
> <Private-Package>..., *</Private-Package> 
> 
> i get the exception
> 
> Unresolved requirements: [[... [57](R 57.0)] osgi.wiring.package;
> (osgi.wiring.package=*com.conversantmedia.util.concurrent*)]
> 
> Looking for the package gets me to adding
> 
> <dependency>
>     <groupId>com.conversantmedia</groupId>
>     <artifactId>disruptor</artifactId>
>     <version>1.2.0</version>
> </dependency>
> 
> to the pom. Now i get 
> 
> Unresolved requirements: [[... [58](R 58.0)] osgi.wiring.package;
> (osgi.wiring.package=*com.fasterxml.jackson.annotation*)]
> 
> Is it necessary that i add all depended libraries for log4j manually to the
> pom to get a working bundle? Or is there a better way?
> 
> I am new to osgi and karaf. How can i add log4j accurate in a osgi-bundle,
> so its log is shown in karaf log:display?
> 
> Regards,
> Matthias
> 
> 
> 
> 
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Log4j2 in osgi-bundle

Posted by "francois.papon" <fr...@openobject.fr>.
Hi,The easy way is to use slf4j.regards,FrancoisEnvoyé depuis mon smartphone Samsung Galaxy.
-------- Message d'origine --------De : matthiaw <mi...@web.de> Date : 30/05/2019  14:45  (GMT+04:00) À : user@karaf.apache.org Objet : Log4j2 in osgi-bundle I want to use log4j2 in my osgi-bundle for karaf. When i add log4j into thepom, compile it and load it into karaf, then the exceptionUnresolved requirements: [[... [56](R 56.0)] osgi.wiring.package;(&(osgi.wiring.package=*org.apache.logging.log4j*)(version>=2.11.0)(!(version>=3.0.0)))]is thrown. This must be, because i not added something tomaven-bundle-plugin. Bot when i add there<Private-Package>..., org.apache.logging.log4j*</Private-Package> or<Private-Package>..., *</Private-Package> i get the exceptionUnresolved requirements: [[... [57](R 57.0)] osgi.wiring.package;(osgi.wiring.package=*com.conversantmedia.util.concurrent*)]Looking for the package gets me to adding<dependency>    <groupId>com.conversantmedia</groupId>    <artifactId>disruptor</artifactId>    <version>1.2.0</version></dependency>to the pom. Now i get Unresolved requirements: [[... [58](R 58.0)] osgi.wiring.package;(osgi.wiring.package=*com.fasterxml.jackson.annotation*)]Is it necessary that i add all depended libraries for log4j manually to thepom to get a working bundle? Or is there a better way?I am new to osgi and karaf. How can i add log4j accurate in a osgi-bundle,so its log is shown in karaf log:display?Regards,Matthias--Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html