You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by lionceau <fl...@gmail.Com> on 2014/06/09 19:04:15 UTC
logging and karaf, how to do it ?
this link show how to make a logger and why it's useful to use the logger of
OSGi :
https://code.google.com/p/osgi-logging/wiki/UnderstandingTheOSGiLogging
<https://code.google.com/p/osgi-logging/wiki/UnderstandingTheOSGiLogging>
How to run this on Apache Karaf ?
this is my featres.xml :
<feature name='log2-bundle' version='1.0'>
<bundle>file:///C:/Users/Florian/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log2/com.vogella.osgi.firstbundle.internal.bundleLogV6_1.0.0.201406091621.jar</bundle>
<bundle>file:///C:/Users/Florian/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log2/testBundleLogV6-consoleLog_1.0.0.201406091852.jar</bundle>
<bundle>file:///C:/Users/Florian/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log2/log.jar</bundle>
</feature>
I have this error :
karaf@root()> feature:install log2-bundle
Error executing command: Jar is not a bundle, no Bundle-SymbolicName
file:///C:/
Users/xxx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log
2/log.jar
karaf@root()>
--
View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438.html
Sent from the Karaf - User mailing list archive at Nabble.com.
Re: logging and karaf, how to do it ?
Posted by lionceau <fl...@gmail.Com>.
Hi ,
Thank you for your fast answer.
What is the diference between feature:install and bundle:install ??
What do you mean with " Just drop your bundle in the deploy folder, it's
enough, you don't need
the feature. " ??? because if i put the jar in the folder /deploy I have
this error :
karaf@root()> bundle:install testLoggerVF2.jar
Bundle IDs:
Error executing command: Error installing bundles:
Unable to install bundle testLoggerVF2.jar
karaf@root()>
If I do this :
karaf@root()> feature:install log6-bundle
Error executing command: Could not start bundle file:///C:/Users/xxx/Downloa
ds/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log6/testLoggerV3.jar
in
feature(s) log6-bundle-1.0: Activator start error in bundle
com.vogella.osgi.fi
rstbundle.internal.bundleLogV6 [124].
I have this error in the log :
2014-06-10 19:47:24,870 | ERROR | Local user karaf | ShellUtil
| 37 - org.apache.karaf.shell.console - 3.0.1 | Exception caught while
executing command
java.lang.Exception: Could not start bundle
file:///C:/Users/xxx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log6/testLoggerV3.jar
in feature(s) log6-bundle-1.0: Activator start error in bundle
com.vogella.osgi.firstbundle.internal.bundleLogV6 [123].
at
org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:478)
at
org.apache.karaf.features.internal.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:433)
at
org.apache.karaf.features.internal.FeaturesServiceImpl.installFeature(FeaturesServiceImpl.java:373)
at
org.apache.karaf.features.internal.FeaturesServiceImpl.installFeature(FeaturesServiceImpl.java:362)
at Proxye8b3d988_0f57_4bc5_b7b4_326ae3387392.installFeature(Unknown Source)
at
org.apache.karaf.features.command.InstallFeatureCommand.doExecute(InstallFeatureCommand.java:67)
at
org.apache.karaf.features.command.FeaturesCommandSupport.doExecute(FeaturesCommandSupport.java:38)
at
org.apache.karaf.shell.console.AbstractAction.execute(AbstractAction.java:33)
at
org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)
at
org.apache.karaf.shell.commands.basic.AbstractCommand.execute(AbstractCommand.java:33)
at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)[:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source)[:1.7.0_55]
at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)
at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)
at
org.apache.karaf.shell.console.commands.$BlueprintCommand1564765056.execute(Unknown
Source)[37:org.apache.karaf.shell.console:3.0.1]
at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)[:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source)[:1.7.0_55]
at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)
at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)
at
org.apache.karaf.shell.console.commands.$BlueprintCommand1564765056.execute(Unknown
Source)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
at
org.apache.karaf.shell.console.impl.jline.ConsoleImpl$DelegateSession.execute(ConsoleImpl.java:521)
at
org.apache.karaf.shell.console.impl.jline.ConsoleImpl.run(ConsoleImpl.java:212)
at java.lang.Thread.run(Unknown Source)[:1.7.0_55]
at
org.apache.karaf.shell.console.impl.jline.ConsoleFactoryService$3.doRun(ConsoleFactoryService.java:126)[37:org.apache.karaf.shell.console:3.0.1]
at
org.apache.karaf.shell.console.impl.jline.ConsoleFactoryService$3$1.run(ConsoleFactoryService.java:117)
at java.security.AccessController.doPrivileged(Native Method)[:1.7.0_55]
at
org.apache.karaf.jaas.modules.JaasHelper.doAs(JaasHelper.java:47)[38:org.apache.karaf.jaas.modules:3.0.1]
at
org.apache.karaf.shell.console.impl.jline.ConsoleFactoryService$3.run(ConsoleFactoryService.java:115)[37:org.apache.karaf.shell.console:3.0.1]
Caused by: org.osgi.framework.BundleException: Activator start error in
bundle com.vogella.osgi.firstbundle.internal.bundleLogV6 [123].
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2196)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
at
org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:475)
... 36 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at
com.vogella.osgi.firstbundle.internal.BundleLogV6.Activator.<clinit>(Activator.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)[:1.7.0_55]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)[:1.7.0_55]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)[:1.7.0_55]
at java.lang.reflect.Constructor.newInstance(Unknown Source)[:1.7.0_55]
at java.lang.Class.newInstance(Unknown Source)[:1.7.0_55]
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4336)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2141)
... 40 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory not
found by com.vogella.osgi.firstbundle.internal.bundleLogV6 [123]
at
org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at
org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(Unknown Source)[:1.7.0_55]
... 48 more
--
View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438p4033457.html
Sent from the Karaf - User mailing list archive at Nabble.com.
Re: logging and karaf, how to do it ?
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,
it's not correct: you should avoid to mix deploy and feature.
Just drop your bundle in the deploy folder, it's enough, you don't need
the feature.
You should see your log message in the data/log/karaf.log.
Regards
JB
On 06/10/2014 12:07 AM, lionceau wrote:
> hello,
>
>
>
> This is my features.xml :
>
>
> <feature name='log6-bundle' version='1.0'>
>
> <bundle>file:///C:/Users/xxx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log6/testLoggerVF.jar</bundle>
> </feature>
>
> this is acivator.java
> package com.vogella.osgi.firstbundle.internal.BundleLogV6;
>
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
>
>
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> import com.vogella.osgi.firstbundle.internal.BundleLogV6.MyThread;
>
> public class Activator implements BundleActivator {
> private MyThread myThread;
>
> private final static Logger LOGGER =
> LoggerFactory.getLogger(Activator.class);
>
>
> public void start(BundleContext context) throws Exception {
> System.out.println("logV6 Starting com.vogella.osgi.firstbundle");
> LOGGER.info("log info : Starting com.vogella.osgi.firstbundle");
>
> myThread = new MyThread();
> myThread.start();
> }
>
>
> public void stop(BundleContext context) throws Exception {
> System.out.println("Stopping com.vogella.osgi.firstbundle");
> LOGGER.info("log info : Stopping com.vogella.osgi.firstbundle");
>
> myThread.stopThread();
> myThread.join();
> }
>
> }
>
>
>
> and this is MyThread.java
>
> package com.vogella.osgi.firstbundle.internal.BundleLogV6;
>
>
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class MyThread extends Thread {
> private volatile boolean active = true;
>
> private final static Logger LOGGER =
> LoggerFactory.getLogger(MyThread.class);
>
> public void run() {
> while (active) {
> System.out.println("ahoy OSGi console");
> LOGGER.info("Hello man");
> LOGGER.info("tetbundlelog v6");
> LOGGER.info("My stuff");
> try {
> Thread.sleep(5000);
> } catch (Exception e) {
> System.out.println("Thread interrupted " + e.getMessage());
> }
> }
> }
>
> public void stopThread() {
> active = false;
> }
> }
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438p4033446.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com
Re: logging and karaf, how to do it ?
Posted by lionceau <fl...@gmail.Com>.
hello,
This is my features.xml :
<feature name='log6-bundle' version='1.0'>
<bundle>file:///C:/Users/xxx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log6/testLoggerVF.jar</bundle>
</feature>
this is acivator.java
package com.vogella.osgi.firstbundle.internal.BundleLogV6;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.vogella.osgi.firstbundle.internal.BundleLogV6.MyThread;
public class Activator implements BundleActivator {
private MyThread myThread;
private final static Logger LOGGER =
LoggerFactory.getLogger(Activator.class);
public void start(BundleContext context) throws Exception {
System.out.println("logV6 Starting com.vogella.osgi.firstbundle");
LOGGER.info("log info : Starting com.vogella.osgi.firstbundle");
myThread = new MyThread();
myThread.start();
}
public void stop(BundleContext context) throws Exception {
System.out.println("Stopping com.vogella.osgi.firstbundle");
LOGGER.info("log info : Stopping com.vogella.osgi.firstbundle");
myThread.stopThread();
myThread.join();
}
}
and this is MyThread.java
package com.vogella.osgi.firstbundle.internal.BundleLogV6;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyThread extends Thread {
private volatile boolean active = true;
private final static Logger LOGGER =
LoggerFactory.getLogger(MyThread.class);
public void run() {
while (active) {
System.out.println("ahoy OSGi console");
LOGGER.info("Hello man");
LOGGER.info("tetbundlelog v6");
LOGGER.info("My stuff");
try {
Thread.sleep(5000);
} catch (Exception e) {
System.out.println("Thread interrupted " + e.getMessage());
}
}
}
public void stopThread() {
active = false;
}
}
--
View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438p4033446.html
Sent from the Karaf - User mailing list archive at Nabble.com.
Re: logging and karaf, how to do it ?
Posted by Achim Nierbeck <bc...@googlemail.com>.
One thing I noticed in your description. You seem to mix features and
deploy folders.
Make sure you don't reference bundles placed in the deploy folder.
Or better don't put your bundles which you are using in your feature file
in the deploy folder
of Karaf.
regards, Achim
2014-06-09 22:28 GMT+02:00 lionceau <fl...@gmail.com>:
> Hi,
>
> Thank you JB for your answer , it's working on eclipse but in Karaf I see
> this error :
>
> karaf@root()> feature:install log6-bundle
> Error executing command: Could not start bundle
> file:///C:/Users/xxx/Downloa
>
> ds/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log6/testLoggerVF.jar
> in
> feature(s) log6-bundle-1.0: Activator start error in bundle
> com.vogella.osgi.fi
> rstbundle.internal.bundleLogV6 [107].
> karaf@root()>
>
>
> this is my Manifest :
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: Internal
> Bundle-SymbolicName: com.vogella.osgi.firstbundle.internal.bundleLogV6
> Bundle-Version: 1.0.0.qualifier
> Bundle-Activator:
> com.vogella.osgi.firstbundle.internal.BundleLogV6.Activator
> Bundle-Vendor: VOGELLA
> Bundle-RequiredExecutionEnvironment: JavaSE-1.7
> Import-Package: org.osgi.framework;version="1.3.0",
> org.osgi.util.tracker;version="1.5.1",
> org.slf4j;resolution:=optional;version="1.7.2"
> Bundle-ActivationPolicy: lazy
>
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438p4033444.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>
--
Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>
Software Architect / Project Manager / Scrum Master
Re: logging and karaf, how to do it ?
Posted by lionceau <fl...@gmail.Com>.
Hi,
Thank you JB for your answer , it's working on eclipse but in Karaf I see
this error :
karaf@root()> feature:install log6-bundle
Error executing command: Could not start bundle file:///C:/Users/xxx/Downloa
ds/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log6/testLoggerVF.jar
in
feature(s) log6-bundle-1.0: Activator start error in bundle
com.vogella.osgi.fi
rstbundle.internal.bundleLogV6 [107].
karaf@root()>
this is my Manifest :
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Internal
Bundle-SymbolicName: com.vogella.osgi.firstbundle.internal.bundleLogV6
Bundle-Version: 1.0.0.qualifier
Bundle-Activator:
com.vogella.osgi.firstbundle.internal.BundleLogV6.Activator
Bundle-Vendor: VOGELLA
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.osgi.framework;version="1.3.0",
org.osgi.util.tracker;version="1.5.1",
org.slf4j;resolution:=optional;version="1.7.2"
Bundle-ActivationPolicy: lazy
--
View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438p4033444.html
Sent from the Karaf - User mailing list archive at Nabble.com.
Re: logging and karaf, how to do it ?
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,
in the META-INF/MANIFEST.MF of your bundle, you should have:
- org.slf4j*;resolution:=optional in the Import-Package
In your code, if you use:
LOGGER.info("My stuff");
you should be able to see "My stuff" in data/log/karaf.log.
Can you check that ?
Regards
JB
On 06/09/2014 07:41 PM, lionceau wrote:
> Hi ,
>
> When i try to do this using eclipse , my eclipse don't know : import
> org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
> then i import slf4j-api-1.7.7.jar from
> http://mvnrepository.com/artifact/org.slf4j/slf4j-api
> <http://mvnrepository.com/artifact/org.slf4j/slf4j-api>
>
> And after that nothing run, why ? What's going on ?
>
> Thank you for your fast answer JB
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438p4033440.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com
Re: logging and karaf, how to do it ?
Posted by lionceau <fl...@gmail.Com>.
Hi ,
When i try to do this using eclipse , my eclipse don't know : import
org.slf4j.Logger;
import org.slf4j.LoggerFactory;
then i import slf4j-api-1.7.7.jar from
http://mvnrepository.com/artifact/org.slf4j/slf4j-api
<http://mvnrepository.com/artifact/org.slf4j/slf4j-api>
And after that nothing run, why ? What's going on ?
Thank you for your fast answer JB
--
View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438p4033440.html
Sent from the Karaf - User mailing list archive at Nabble.com.
Re: logging and karaf, how to do it ?
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,
Karaf use Pax Logging for the logging framework. You don't need to
install anything special, Karaf already provides "natively" different
logging framework support (slf4j, log4j, avalon, etc).
All in configured in a central file (etc/org.ops4j.pax.logging.cfg)
using the log4j syntax.
In your bundle, you just import the logging package that you need and
directly use the logger. For instance:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
private final static Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
...
LOGGER.info("Hello man");
...
Karaf also provides multiple commands to manipulate log (log:display,
log:set, log:debug, log:tail, ...).
You can find the logger user guide there:
http://karaf.apache.org/manual/latest/users-guide/log.html
I blogged about how to extend Pax Logging with custom appender, etc
(more from a developer perspective):
http://blog.nanthrax.net/2012/12/create-custom-log4j-appender-for-karaf-and-pax-logging/
Regards
JB
On 06/09/2014 07:04 PM, lionceau wrote:
> this link show how to make a logger and why it's useful to use the logger of
> OSGi :
> https://code.google.com/p/osgi-logging/wiki/UnderstandingTheOSGiLogging
> <https://code.google.com/p/osgi-logging/wiki/UnderstandingTheOSGiLogging>
>
> How to run this on Apache Karaf ?
>
> this is my featres.xml :
> <feature name='log2-bundle' version='1.0'>
>
> <bundle>file:///C:/Users/Florian/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log2/com.vogella.osgi.firstbundle.internal.bundleLogV6_1.0.0.201406091621.jar</bundle>
>
> <bundle>file:///C:/Users/Florian/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log2/testBundleLogV6-consoleLog_1.0.0.201406091852.jar</bundle>
>
> <bundle>file:///C:/Users/Florian/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log2/log.jar</bundle>
> </feature>
>
>
>
>
> I have this error :
> karaf@root()> feature:install log2-bundle
> Error executing command: Jar is not a bundle, no Bundle-SymbolicName
> file:///C:/
> Users/xxx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/bundles/log
> 2/log.jar
> karaf@root()>
>
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/logging-and-karaf-how-to-do-it-tp4033438.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com