Log4j2 in osgi-bundle

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Log4j2 in osgi-bundle

Matthias
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
Reply | Threaded
Open this post in threaded view
|

Re: Log4j2 in osgi-bundle

fpapon
Hi,

The easy way is to use slf4j.

regards,

Francois



Envoyé depuis mon smartphone Samsung Galaxy.

-------- Message d'origine --------
De : matthiaw <[hidden email]>
Date : 30/05/2019 14:45 (GMT+04:00)
Objet : 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
François Papon
fpapon@apache.org
Yupiik - https://www.yupiik.com
Reply | Threaded
Open this post in threaded view
|

Re: Log4j2 in osgi-bundle

jbonofre
In reply to this post by Matthias
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é
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Log4j2 in osgi-bundle

Matthias
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

Reply | Threaded
Open this post in threaded view
|

Re: Log4j2 in osgi-bundle

jbonofre
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é
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com