Re: Karaf log4j conflict

2024-03-11 Thread Grzegorz Grzybek
Hello

Pax Logging (where pax-logging-api contains and exports Logging APIs, while
pax-logging-log4j2 is the Log4j2-based implementation) has enormous amount
of effort put into integration of very different logging packages and it is
used by Apache Karaf among others.

The team developed Pax Logging for many years trying to maintain old APIs
and include new ones. Among others, there's one consequence of this -
either you use Pax Logging and accept some (workarounds possible)
limitation or you craft your own set of bundles approaching what Pax
Logging does anyway.

Your issue is simple - your "caterwaul-connect-core" bundle imports
"org.apache.logging.log4j.core" which is simply NOT exported by
pax-logging-log4j2. This (at first glance) means you NEED actual Log4j2
bundles installed.

However - are you sure your "caterwaul-connect-core" bundle really needs
this package? is it implementing custom appenders/layouts/plugins? If so,
it's better (and Pax Logging contains relevant examples) to create a
fragment bundle attached to pax-logging-log4j2 bundle.

regards
Grzegorz Grzybek

pon., 11 mar 2024 o 21:51 Will Hartung  napisaƂ(a):

> I've been trying to get our legacy application running in an OSGI runtime,
> and have been trying with Karaf.
>
> After much pushing modules around, I was getting this error about Log4j:
>
> Error executing command: Error executing command on bundles:
> Error starting bundle 138: Unable to resolve caterwaul-connect-core
> [138](R 138.1): missing requirement [caterwaul-connect-core [138](R 138.1)]
> osgi.wiring.package; (osgi.wiring.package=org.apache.logging.log4j.core)
> Unresolved requirements: [[caterwaul-connect-core [138](R 138.1)]
> osgi.wiring.package; (osgi.wiring.package=org.apache.logging.log4j.core)]
>
> So, I added in log4j-api-2.20.0.jar, and log4j-core-2.20.0.jar.
>
> These loaded, resolve, and start fine, but now when I try to start my
> bundle I get:
>
> Error executing command: Error executing command on bundles:
> Error starting bundle 138: Uses constraint violation. Unable to resolve
> resource caterwaul-connect-core [caterwaul-connect-core [138](R 138.1)]
> because it is exposed to package 'org.apache.logging.log4j' from resources
> org.ops4j.pax.logging.pax-logging-api
> [org.ops4j.pax.logging.pax-logging-api [5](R 5.0)] and
> org.apache.logging.log4j.api [org.apache.logging.log4j.api [215](R 215.0)]
> via two dependency chains.
>
> Chain 1:
>   caterwaul-connect-core [caterwaul-connect-core [138](R 138.1)]
> import: (osgi.wiring.package=org.apache.logging.log4j)
>  |
> export: osgi.wiring.package: org.apache.logging.log4j
>   org.ops4j.pax.logging.pax-logging-api
> [org.ops4j.pax.logging.pax-logging-api [5](R 5.0)]
>
> Chain 2:
>   caterwaul-connect-core [caterwaul-connect-core [138](R 138.1)]
> import: (osgi.wiring.package=org.apache.logging.log4j.core)
>  |
> export: osgi.wiring.package=org.apache.logging.log4j.core;
> uses:=org.apache.logging.log4j
>   org.apache.logging.log4j.core [org.apache.logging.log4j.core [214](R
> 214.0)]
> import:
> (&(osgi.wiring.package=org.apache.logging.log4j)(version>=2.20.0)(!(version>=3.0.0)))
>  |
> export: osgi.wiring.package: org.apache.logging.log4j
>   org.apache.logging.log4j.api [org.apache.logging.log4j.api [215](R
> 215.0)] Unresolved requirements: [[caterwaul-connect-core [138](R 138.1)]
> osgi.wiring.package; (osgi.wiring.package=org.apache.logging.log4j.core)]
>
> It was my understanding that Karaf bundled logging. In fact, that was a
> motivator to trying in. My adventures with Felix were derailed with trying
> to get SLF4J to start and wire properly (even when using the pax logging
> bundle).
>
> But, now, when I include the log4j bundles, it complains that there's a
> conflict from the two sources for log4j. If I go and uninstall the log4j
> core bundle, then I no longer get the conflict about too many log4js, but
> the complaint that it can't find it at all.
>
> How can I reconcile this impasse?
>
> Thanks!
>
> Regards,
>
> Will Hartung
>
>


Karaf log4j conflict

2024-03-11 Thread Will Hartung
I've been trying to get our legacy application running in an OSGI runtime,
and have been trying with Karaf.

After much pushing modules around, I was getting this error about Log4j:

Error executing command: Error executing command on bundles:
Error starting bundle 138: Unable to resolve caterwaul-connect-core [138](R
138.1): missing requirement [caterwaul-connect-core [138](R 138.1)]
osgi.wiring.package; (osgi.wiring.package=org.apache.logging.log4j.core)
Unresolved requirements: [[caterwaul-connect-core [138](R 138.1)]
osgi.wiring.package; (osgi.wiring.package=org.apache.logging.log4j.core)]

So, I added in log4j-api-2.20.0.jar, and log4j-core-2.20.0.jar.

These loaded, resolve, and start fine, but now when I try to start my
bundle I get:

Error executing command: Error executing command on bundles:
Error starting bundle 138: Uses constraint violation. Unable to resolve
resource caterwaul-connect-core [caterwaul-connect-core [138](R 138.1)]
because it is exposed to package 'org.apache.logging.log4j' from resources
org.ops4j.pax.logging.pax-logging-api
[org.ops4j.pax.logging.pax-logging-api [5](R 5.0)] and
org.apache.logging.log4j.api [org.apache.logging.log4j.api [215](R 215.0)]
via two dependency chains.

Chain 1:
  caterwaul-connect-core [caterwaul-connect-core [138](R 138.1)]
import: (osgi.wiring.package=org.apache.logging.log4j)
 |
export: osgi.wiring.package: org.apache.logging.log4j
  org.ops4j.pax.logging.pax-logging-api
[org.ops4j.pax.logging.pax-logging-api [5](R 5.0)]

Chain 2:
  caterwaul-connect-core [caterwaul-connect-core [138](R 138.1)]
import: (osgi.wiring.package=org.apache.logging.log4j.core)
 |
export: osgi.wiring.package=org.apache.logging.log4j.core;
uses:=org.apache.logging.log4j
  org.apache.logging.log4j.core [org.apache.logging.log4j.core [214](R
214.0)]
import:
(&(osgi.wiring.package=org.apache.logging.log4j)(version>=2.20.0)(!(version>=3.0.0)))
 |
export: osgi.wiring.package: org.apache.logging.log4j
  org.apache.logging.log4j.api [org.apache.logging.log4j.api [215](R
215.0)] Unresolved requirements: [[caterwaul-connect-core [138](R 138.1)]
osgi.wiring.package; (osgi.wiring.package=org.apache.logging.log4j.core)]

It was my understanding that Karaf bundled logging. In fact, that was a
motivator to trying in. My adventures with Felix were derailed with trying
to get SLF4J to start and wire properly (even when using the pax logging
bundle).

But, now, when I include the log4j bundles, it complains that there's a
conflict from the two sources for log4j. If I go and uninstall the log4j
core bundle, then I no longer get the conflict about too many log4js, but
the complaint that it can't find it at all.

How can I reconcile this impasse?

Thanks!

Regards,

Will Hartung