Hi,

Do you see your bundle started ?
If the bundle is started, do you see the service started (with the correct property) ?

Can you share your code on github for instance ?

By the way, do you need the decanter-appender-log ? I guess you just want the decanter-collector-log.

Regards
JB

On 03/27/2016 07:01 PM, D wrote:
I am trying to create a custom appender using Decanter as mentioned here. My
goal is to listen to all logs output by karaf bundles and display it in
console. I am using Karaf 3.0.4 under Apache Servicemix 6.1.0

I have added Decanter feature repository in Karaf & then installed
collector-log and appender-log as mentioned in the Decanter documentation.

My custom appender looks like below:-

package com.jabong.karaf.decanter.appender.elklog;

import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

public class ELKLogAppender implements EventHandler {
     @Override
     public void handleEvent(Event event) {
     for (String name : event.getPropertyNames()) {
         System.out.println("Custom Debraj" + name + ":" +
event.getProperty(name));
     }
     }
}

My Activator looks like below:-

package com.jabong.karaf.decanter.appender.elklog;

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;

public class Activator implements BundleActivator {
     private ServiceRegistration registration;

     @Override
     public void start(BundleContext bundleContext) {
     ELKLogAppender appender = new ELKLogAppender();
     Dictionary<String, String> properties = new Hashtable<>();
     properties.put(EventConstants.EVENT_TOPIC, "decanter/collect/*");
     registration = bundleContext.registerService(EventHandler.class,
appender, properties);
     }

     @Override
     public void stop(BundleContext bundleContext) {
     if (registration != null) {
         registration.unregister();
     }
     }
}

My pom.xml looks like below:-

<project xmlns="http://maven.apache.org/POM/4.0.0";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.jabong.karaf.decanter.appender</groupId>
     <artifactId>elklog</artifactId>
     <version>0.0.1</version>
     <packaging>bundle</packaging>
     <name>Apache Karaf :: Decanter :: Appender :: ELKLog</name>
     <dependencies>

         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <version>4.3.1</version>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.compendium</artifactId>
             <version>4.3.1</version>
         </dependency>
     </dependencies>
     <build>
         <sourceDirectory>src</sourceDirectory>
         <plugins>
             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.3</version>
                 <configuration>
                     <source>1.8</source>
                     <target>1.8</target>
                 </configuration>
             </plugin>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <version>2.4.0</version>
                 <inherited>true</inherited>
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>

<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                         <Bundle-Version>${project.version}</Bundle-Version>

<Bundle-Activator>com.jabong.karaf.decanter.appender.elklog.Activator</Bundle-Activator>
                         <Import-Package>
                             *
                         </Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
         </plugins>
     </build>
</project>

I was able to install the bundle correctly in Karaf by placing it in deploy
folder.

332 | Active    |  80 | 0.0.1                              | basecomponent
333 | Active    |  80 | 1.0.1                              | Apache Karaf ::
Decanter :: API
334 | Active    |  80 | 1.0.1                              | Apache Karaf ::
Decanter :: Collector :: Log
337 | Active    |  80 | 1.0.1                              | Apache Karaf ::
Decanter :: Appender :: Log
339 | Active    |  80 | 0.0.1                              | Apache Karaf ::
Decanter :: Appender :: ELKLog

My org.ops4j.pax.logging.cfg in Karaf looks like below:-

# Root logger
log4j.rootLogger=INFO, out, osgi:VmLogAppender
log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer

# To avoid flooding the log when using DEBUG level on an ssh connection and
doing log:tail
log4j.logger.org.apache.sshd.server.channel.ChannelSession = INFO

# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} | %-5.5p |
%-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
%X{bundle.version} | %X | %m%n

# File appender
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t
| %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %X |
%m%n
log4j.appender.out.file=${karaf.data}/log/servicemix.log
log4j.appender.out.append=true
log4j.appender.out.maxFileSize=100MB
log4j.appender.out.maxBackupIndex=10

# Sift appender
log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
log4j.appender.sift.key=bundle.name
log4j.appender.sift.default=servicemix
log4j.appender.sift.appender=org.apache.log4j.FileAppender
log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.sift.appender.layout.ConversionPattern=%d{ISO8601} | %-5.5p |
%-16.16t | %-32.32c{1} | %X | %m%n
log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
log4j.appender.sift.appender.append=true

But I am not seeing any message on the console. Even though I am seeing many
logs in data/servicemix.log





--
View this message in context: 
http://karaf.922171.n3.nabble.com/Custom-Appender-in-Karaf-Decanter-Not-working-tp4046003.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