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

Reply via email to